@@ -4,6 +4,7 @@ package ethutil
44
55import (
66 "context"
7+ "encoding/hex"
78 "fmt"
89 "math/big"
910
@@ -15,25 +16,41 @@ import (
1516 "github.com/ethereum/go-ethereum/ethclient"
1617)
1718
18- type PRTDeployment struct {
19- App * ApplicationDeployment
19+ type PRTApplicationDeployment struct {
2020 FactoryAddress common.Address
21+ TemplateHash common.Hash
22+ Salt SaltBytes
23+
24+ Application * ApplicationDeployment
2125}
2226
23- type PRTDeploymentResult struct {
27+ type PRTApplicationDeploymentResult struct {
28+ Deployment * PRTApplicationDeployment
29+ ApplicationResult * ApplicationDeploymentResult
2430}
2531
26- func (me * PRTDeployment ) String () string {
32+ func (me * PRTApplicationDeployment ) String () string {
2733 result := ""
28- result += me .App .String ()
29- if me .App .Verbose {
34+ result += fmt .Sprintf ("PRT application deployment:\n " )
35+ result += fmt .Sprintf ("\t application owner: %v\n " , me .Application .OwnerAddress )
36+ if me .Application .Verbose {
3037 result += fmt .Sprintf ("\t PRT factory address: %v\n " , me .FactoryAddress )
31- result += fmt .Sprintf ("\t PRT consensus address: %v\n " , me .App .Consensus )
38+ result += fmt .Sprintf ("\t APP factory address: %v\n " , me .Application .FactoryAddress )
39+ result += fmt .Sprintf ("\t template hash: %v\n " , me .Application .TemplateHash )
40+ result += fmt .Sprintf ("\t data availability: 0x%v\n " , hex .EncodeToString (me .Application .DataAvailability ))
41+ result += fmt .Sprintf ("\t salt: %v\n " , me .Application .Salt )
3242 }
3343 return result
3444}
3545
36- func (me * PRTDeployment ) deployPRT (
46+ func (me * PRTApplicationDeploymentResult ) String () string {
47+ result := ""
48+ result += fmt .Sprintf ("\t application address: %v\n " , me .ApplicationResult .ApplicationAddress )
49+ result += fmt .Sprintf ("\t consensus address: %v\n " , me .ApplicationResult .Deployment .Consensus )
50+ return result
51+ }
52+
53+ func (me * PRTApplicationDeployment ) deployPRT (
3754 ctx context.Context ,
3855 client * ethclient.Client ,
3956 txOpts * bind.TransactOpts ,
@@ -45,7 +62,7 @@ func (me *PRTDeployment) deployPRT(
4562 if err != nil {
4663 return zero , fmt .Errorf ("failed to instantiate contract: %v" , err )
4764 }
48- tx , err := factory .NewDaveConsensus (txOpts , applicationAddress , me .App . TemplateHash , me . App .Salt )
65+ tx , err := factory .NewDaveConsensus (txOpts , applicationAddress , me .TemplateHash , me .Salt )
4966 if err != nil {
5067 return zero , fmt .Errorf ("transaction failed: %v" , err )
5168 }
@@ -72,19 +89,29 @@ func (me *PRTDeployment) deployPRT(
7289}
7390
7491// Do the consensus/application dance based on: https://github.com/cartesi/dave/blob/v1.0.0/cartesi-rollups/contracts/cannonfile.prod-instance.toml
75- func (me * PRTDeployment ) Deploy (
92+ func (me * PRTApplicationDeployment ) Deploy (
7693 ctx context.Context ,
7794 client * ethclient.Client ,
7895 txOpts * bind.TransactOpts ,
7996) (common.Address , IApplicationDeploymentResult , error ) {
8097 zero := common.Address {}
98+ result := & PRTApplicationDeploymentResult {}
99+ result .Deployment = me
81100
82- applicationAddress , result , err := me .App .Deploy (ctx , client , txOpts )
101+ var err error
102+ applicationAddress , appResult , err := me .Application .Deploy (ctx , client , txOpts )
83103 if err != nil {
84104 return zero , nil , err
85105 }
86106
87- me .App .Consensus , err = me .deployPRT (ctx , client , txOpts , applicationAddress )
107+ switch appRes := appResult .(type ) {
108+ case * ApplicationDeploymentResult :
109+ result .ApplicationResult = appRes
110+ default :
111+ panic ("Application deployment returned an impossible type." )
112+ }
113+
114+ consensus , err := me .deployPRT (ctx , client , txOpts , applicationAddress )
88115 if err != nil {
89116 return zero , nil , fmt .Errorf ("failed to deploy PRT contract: %w" , err )
90117 }
@@ -96,7 +123,7 @@ func (me *PRTDeployment) Deploy(
96123
97124 _ , err = sendTransaction (ctx , client , txOpts , big .NewInt (0 ), GasLimit ,
98125 func (txOpts * bind.TransactOpts ) (* types.Transaction , error ) {
99- return application .MigrateToOutputsMerkleRootValidator (txOpts , me . App . Consensus )
126+ return application .MigrateToOutputsMerkleRootValidator (txOpts , consensus )
100127 },
101128 )
102129 if err != nil {
@@ -112,9 +139,10 @@ func (me *PRTDeployment) Deploy(
112139 return zero , nil , fmt .Errorf ("failed to create a self hosted application: execution reverted" )
113140 }
114141
142+ result .ApplicationResult .Deployment .Consensus = consensus
115143 return applicationAddress , result , nil
116144}
117145
118- func (me * PRTDeployment ) GetFactoryAddress () common.Address {
146+ func (me * PRTApplicationDeployment ) GetFactoryAddress () common.Address {
119147 return me .FactoryAddress
120148}
0 commit comments