2929 applicationRegisterParam bool
3030 applicationTemplateHashParam string
3131 factoryAddressParam string
32+ prtFactoryAddressParam string
33+ deploymentTypePRT bool
3234)
3335
3436var applicationCmd = & cobra.Command {
@@ -49,7 +51,8 @@ Supported Environment Variables:
4951 CARTESI_BLOCKCHAIN_HTTP_ENDPOINT Blockchain HTTP endpoint
5052 CARTESI_CONTRACTS_INPUT_BOX_ADDRESS Input Box contract address
5153 CARTESI_CONTRACTS_APPLICATION_FACTORY_ADDRESS Application Factory address
52- CARTESI_CONTRACTS_SELF_HOSTED_APPLICATION_FACTORY_ADDRESS Self Hosted Application Factory address` ,
54+ CARTESI_CONTRACTS_SELF_HOSTED_APPLICATION_FACTORY_ADDRESS Self Hosted Application Factory address
55+ CARTESI_CONTRACTS_PRT_FACTORY_ADDRESS PRT Factory address` ,
5356}
5457
5558const applicationExamples = `
@@ -59,6 +62,9 @@ const applicationExamples = `
5962# deploy an application contract using an existing consensus, then register the application
6063 - cli deploy application echo-dapp applications/echo-dapp/ --consensus=0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
6164
65+ # deploy an application contract with a PRT consensus, then register the application
66+ - cli deploy application echo-dapp applications/echo-dapp/ --prt
67+
6268# deploy but don't register into the database
6369 - cli deploy application echo-dapp applications/echo-dapp/ --register=false
6470
@@ -73,6 +79,8 @@ func init() {
7379 "Consensus address. A new authority consensus will be created if this field is left empty." )
7480 applicationCmd .Flags ().StringVarP (& factoryAddressParam , "factory" , "f" , "" ,
7581 "Application factory address. Default value is retrieved from configuration." )
82+ applicationCmd .Flags ().StringVarP (& prtFactoryAddressParam , "prt-factory" , "" , "" ,
83+ "PRT Application factory address. Default value is retrieved from configuration." )
7684 applicationCmd .Flags ().StringVarP (& applicationOwnerAddressParam , "application-owner" , "o" , "" ,
7785 "Application owner address. If not defined, it will be derived from the auth method." )
7886 applicationCmd .Flags ().StringVarP (& applicationDataAvailabilityParam , "data-availability" , "d" , "" ,
@@ -85,6 +93,8 @@ func init() {
8593 "Start processing the application, requires 'register=true'." )
8694 applicationCmd .Flags ().StringVarP (& authorityOwnerAddressParam , "authority-owner" , "O" , "" ,
8795 "Authority Owner address. If not defined, it will be derived from the auth method." )
96+ applicationCmd .Flags ().BoolVarP (& deploymentTypePRT , "prt" , "" , false ,
97+ "Deploy a PRT application." )
8898
8999 origHelpFunc := applicationCmd .HelpFunc ()
90100 applicationCmd .SetHelpFunc (func (command * cobra.Command , strings []string ) {
@@ -141,7 +151,9 @@ func runDeployApplication(cmd *cobra.Command, args []string) {
141151 }
142152
143153 var deployment ethutil.IApplicationDeployment
144- if deploySelfhosted := ! cmd .Flags ().Changed ("consensus" ); deploySelfhosted {
154+ if deploymentTypePRT {
155+ deployment , err = buildPrtApplicationDeployment (cmd , args , client , txOpts )
156+ } else if deploySelfhosted := ! cmd .Flags ().Changed ("consensus" ); deploySelfhosted {
145157 deployment , err = buildSelfhostedApplicationDeployment (cmd , args , client , txOpts )
146158 } else {
147159 deployment , err = buildApplicationOnlyDeployment (cmd , args , client , txOpts )
@@ -210,6 +222,15 @@ func runDeployApplication(cmd *cobra.Command, args []string) {
210222 application .EpochLength = res .Deployment .EpochLength
211223 application .DataAvailability = res .Deployment .DataAvailability
212224 application .IInputBoxBlock = res .Deployment .IInputBoxBlock
225+
226+ case * ethutil.PRTApplicationDeploymentResult :
227+ application .IApplicationAddress = res .ApplicationResult .ApplicationAddress
228+ application .IConsensusAddress = res .ApplicationResult .Deployment .Consensus
229+ application .IInputBoxAddress = res .ApplicationResult .Deployment .InputBoxAddress
230+ application .TemplateHash = res .ApplicationResult .Deployment .TemplateHash
231+ application .EpochLength = res .ApplicationResult .Deployment .EpochLength
232+ application .DataAvailability = res .ApplicationResult .Deployment .DataAvailability
233+ application .IInputBoxBlock = res .ApplicationResult .Deployment .IInputBoxBlock
213234 default :
214235 panic ("unimplemented deployment type\n " )
215236 }
@@ -339,7 +360,7 @@ func buildSelfhostedApplicationDeployment(
339360 return request , nil
340361}
341362
342- func buildApplicationOnlyDeployment (
363+ func buildApplicationOnlyDeploymentWithoutConsensus (
343364 cmd * cobra.Command ,
344365 args []string ,
345366 client * ethclient.Client ,
@@ -360,11 +381,6 @@ func buildApplicationOnlyDeployment(
360381 return nil , fmt .Errorf ("error on parameter factory: %w" , err )
361382 }
362383
363- request .Consensus , err = parseHexAddress (applicationConsensusAddressParam )
364- if err != nil {
365- return nil , fmt .Errorf ("error on parameter consensus: %w" , err )
366- }
367-
368384 if ! cmd .Flags ().Changed ("template-hash" ) {
369385 if len (args ) >= 2 { // args[1] is mandatory if `template-hash` was absent
370386 request .TemplateHash , err = readHash (args [1 ])
@@ -402,17 +418,64 @@ func buildApplicationOnlyDeployment(
402418 return nil , fmt .Errorf ("error on parameter data-availability: %w" , err )
403419 }
404420
421+ request .Salt , err = ethutil .ParseSalt (saltParam )
422+ if err != nil {
423+ return nil , fmt .Errorf ("error on parameter salt: %w" , err )
424+ }
425+
426+ request .Verbose = verboseParam
427+ return request , nil
428+ }
429+
430+ func buildApplicationOnlyDeployment (
431+ cmd * cobra.Command ,
432+ args []string ,
433+ client * ethclient.Client ,
434+ txOpts * bind.TransactOpts ,
435+ ) (
436+ * ethutil.ApplicationDeployment ,
437+ error ,
438+ ) {
439+ request , err := buildApplicationOnlyDeploymentWithoutConsensus (cmd , args , client , txOpts )
440+
441+ request .Consensus , err = parseHexAddress (applicationConsensusAddressParam )
442+ if err != nil {
443+ return nil , fmt .Errorf ("error on parameter consensus: %w" , err )
444+ }
445+
405446 request .Consensus , request .EpochLength , err = customConsensus (client , applicationConsensusAddressParam )
406447 if err != nil {
407448 return nil , fmt .Errorf ("error on parameter consensus: %w" , err )
408449 }
409450
410- request .Salt , err = ethutil .ParseSalt (saltParam )
451+ return request , nil
452+ }
453+
454+ func buildPrtApplicationDeployment (
455+ cmd * cobra.Command ,
456+ args []string ,
457+ client * ethclient.Client ,
458+ txOpts * bind.TransactOpts ,
459+ ) (
460+ * ethutil.PRTApplicationDeployment ,
461+ error ,
462+ ) {
463+ var err error
464+ request := & ethutil.PRTApplicationDeployment {}
465+ if ! cmd .Flags ().Changed ("prt-factory" ) {
466+ request .FactoryAddress , err = config .GetContractsPrtFactoryAddress ()
467+ } else {
468+ request .FactoryAddress , err = parseHexAddress (factoryAddressParam )
469+ }
411470 if err != nil {
412- return nil , fmt .Errorf ("error on parameter salt: %w" , err )
471+ return nil , fmt .Errorf ("error on parameter factory: %w" , err )
472+ }
473+
474+ request .Application , err = buildApplicationOnlyDeploymentWithoutConsensus (cmd , args , client , txOpts )
475+ if err != nil {
476+ return nil , fmt .Errorf ("error on application: %w" , err )
413477 }
414478
415- request .Verbose = verboseParam
416479 return request , nil
417480}
418481
0 commit comments