2929 applicationRegisterParam bool
3030 applicationTemplateHashParam string
3131 factoryAddressParam string
32+ prtFactoryAddressParam string
33+ deploymentTypePRT bool
3234)
3335
3436var applicationCmd = & cobra.Command {
@@ -59,6 +61,9 @@ const applicationExamples = `
5961# deploy an application contract using an existing consensus, then register the application
6062 - cli deploy application echo-dapp applications/echo-dapp/ --consensus=0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
6163
64+ # deploy an application contract with a PRT consensus, then register the application
65+ - cli deploy application echo-dapp applications/echo-dapp/ --prt
66+
6267# deploy but don't register into the database
6368 - cli deploy application echo-dapp applications/echo-dapp/ --register=false
6469
@@ -73,6 +78,8 @@ func init() {
7378 "Consensus address. A new authority consensus will be created if this field is left empty." )
7479 applicationCmd .Flags ().StringVarP (& factoryAddressParam , "factory" , "f" , "" ,
7580 "Application factory address. Default value is retrieved from configuration." )
81+ applicationCmd .Flags ().StringVarP (& prtFactoryAddressParam , "prt-factory" , "" , "" ,
82+ "PRT Application factory address. Default value is retrieved from configuration." )
7683 applicationCmd .Flags ().StringVarP (& applicationOwnerAddressParam , "application-owner" , "o" , "" ,
7784 "Application owner address. If not defined, it will be derived from the auth method." )
7885 applicationCmd .Flags ().StringVarP (& applicationDataAvailabilityParam , "data-availability" , "d" , "" ,
@@ -85,6 +92,8 @@ func init() {
8592 "Start processing the application, requires 'register=true'." )
8693 applicationCmd .Flags ().StringVarP (& authorityOwnerAddressParam , "authority-owner" , "O" , "" ,
8794 "Authority Owner address. If not defined, it will be derived from the auth method." )
95+ applicationCmd .Flags ().BoolVarP (& deploymentTypePRT , "prt" , "" , false ,
96+ "Deploy a PRT application." )
8897
8998 origHelpFunc := applicationCmd .HelpFunc ()
9099 applicationCmd .SetHelpFunc (func (command * cobra.Command , strings []string ) {
@@ -141,7 +150,9 @@ func runDeployApplication(cmd *cobra.Command, args []string) {
141150 }
142151
143152 var deployment ethutil.IApplicationDeployment
144- if deploySelfhosted := ! cmd .Flags ().Changed ("consensus" ); deploySelfhosted {
153+ if deploymentTypePRT {
154+ deployment , err = buildPrtApplicationDeployment (cmd , args , client , txOpts )
155+ } else if deploySelfhosted := ! cmd .Flags ().Changed ("consensus" ); deploySelfhosted {
145156 deployment , err = buildSelfhostedApplicationDeployment (cmd , args , client , txOpts )
146157 } else {
147158 deployment , err = buildApplicationOnlyDeployment (cmd , args , client , txOpts )
@@ -210,6 +221,15 @@ func runDeployApplication(cmd *cobra.Command, args []string) {
210221 application .EpochLength = res .Deployment .EpochLength
211222 application .DataAvailability = res .Deployment .DataAvailability
212223 application .IInputBoxBlock = res .Deployment .IInputBoxBlock
224+
225+ case * ethutil.PRTApplicationDeploymentResult :
226+ application .IApplicationAddress = res .ApplicationResult .ApplicationAddress
227+ application .IConsensusAddress = res .ApplicationResult .Deployment .Consensus
228+ application .IInputBoxAddress = res .ApplicationResult .Deployment .InputBoxAddress
229+ application .TemplateHash = res .ApplicationResult .Deployment .TemplateHash
230+ application .EpochLength = res .ApplicationResult .Deployment .EpochLength
231+ application .DataAvailability = res .ApplicationResult .Deployment .DataAvailability
232+ application .IInputBoxBlock = res .ApplicationResult .Deployment .IInputBoxBlock
213233 default :
214234 panic ("unimplemented deployment type\n " )
215235 }
@@ -339,7 +359,7 @@ func buildSelfhostedApplicationDeployment(
339359 return request , nil
340360}
341361
342- func buildApplicationOnlyDeployment (
362+ func buildApplicationOnlyDeploymentWithoutConsensus (
343363 cmd * cobra.Command ,
344364 args []string ,
345365 client * ethclient.Client ,
@@ -360,11 +380,6 @@ func buildApplicationOnlyDeployment(
360380 return nil , fmt .Errorf ("error on parameter factory: %w" , err )
361381 }
362382
363- request .Consensus , err = parseHexAddress (applicationConsensusAddressParam )
364- if err != nil {
365- return nil , fmt .Errorf ("error on parameter consensus: %w" , err )
366- }
367-
368383 if ! cmd .Flags ().Changed ("template-hash" ) {
369384 if len (args ) >= 2 { // args[1] is mandatory if `template-hash` was absent
370385 request .TemplateHash , err = readHash (args [1 ])
@@ -402,17 +417,64 @@ func buildApplicationOnlyDeployment(
402417 return nil , fmt .Errorf ("error on parameter data-availability: %w" , err )
403418 }
404419
420+ request .Salt , err = ethutil .ParseSalt (saltParam )
421+ if err != nil {
422+ return nil , fmt .Errorf ("error on parameter salt: %w" , err )
423+ }
424+
425+ request .Verbose = verboseParam
426+ return request , nil
427+ }
428+
429+ func buildApplicationOnlyDeployment (
430+ cmd * cobra.Command ,
431+ args []string ,
432+ client * ethclient.Client ,
433+ txOpts * bind.TransactOpts ,
434+ ) (
435+ * ethutil.ApplicationDeployment ,
436+ error ,
437+ ) {
438+ request , err := buildApplicationOnlyDeploymentWithoutConsensus (cmd , args , client , txOpts )
439+
440+ request .Consensus , err = parseHexAddress (applicationConsensusAddressParam )
441+ if err != nil {
442+ return nil , fmt .Errorf ("error on parameter consensus: %w" , err )
443+ }
444+
405445 request .Consensus , request .EpochLength , err = customConsensus (client , applicationConsensusAddressParam )
406446 if err != nil {
407447 return nil , fmt .Errorf ("error on parameter consensus: %w" , err )
408448 }
409449
410- request .Salt , err = ethutil .ParseSalt (saltParam )
450+ return request , nil
451+ }
452+
453+ func buildPrtApplicationDeployment (
454+ cmd * cobra.Command ,
455+ args []string ,
456+ client * ethclient.Client ,
457+ txOpts * bind.TransactOpts ,
458+ ) (
459+ * ethutil.PRTApplicationDeployment ,
460+ error ,
461+ ) {
462+ var err error
463+ request := & ethutil.PRTApplicationDeployment {}
464+ if ! cmd .Flags ().Changed ("prt-factory" ) {
465+ request .FactoryAddress , err = config .GetContractsPrtFactoryAddress ()
466+ } else {
467+ request .FactoryAddress , err = parseHexAddress (factoryAddressParam )
468+ }
411469 if err != nil {
412- return nil , fmt .Errorf ("error on parameter salt: %w" , err )
470+ return nil , fmt .Errorf ("error on parameter factory: %w" , err )
471+ }
472+
473+ request .Application , err = buildApplicationOnlyDeploymentWithoutConsensus (cmd , args , client , txOpts )
474+ if err != nil {
475+ return nil , fmt .Errorf ("error on application: %w" , err )
413476 }
414477
415- request .Verbose = verboseParam
416478 return request , nil
417479}
418480
0 commit comments