@@ -2,6 +2,7 @@ package ops
22
33import (
44 "fmt"
5+
56 "github.com/Masterminds/semver/v3"
67 ds "github.com/smartcontractkit/chainlink-deployments-framework/datastore"
78
@@ -69,9 +70,10 @@ func (cs DeployCCIPContracts) Apply(env cldf.Environment, config DeployCCIPContr
6970 ccipSeqInput := sequence.DeployCCIPSeqInput {
7071 // MCMSAddress: mcmsSeqReport.Output.MCMSAddress,
7172 // LinkTokenAddress: linkTokenAddress,
72- CCIPConfig : config .Params ,
73- ContractsVersion : config .ContractsVersion ,
74- ChainSelector : selector ,
73+ CCIPConfig : config .Params ,
74+ ContractsVersionSha : config .ContractsVersion ,
75+ ContractsSemver : semver .MustParse ("1.6.0" ), // TODO Move to the change input. Will do in a later PR given that this will be a breaking change for CLD
76+ ChainSelector : selector ,
7577 }
7678 ccipSeqReport , err := operations .ExecuteSequence (env .OperationsBundle , sequence .DeployCCIPSequence , deps , ccipSeqInput )
7779 if err != nil {
@@ -86,38 +88,29 @@ func (cs DeployCCIPContracts) Apply(env cldf.Environment, config DeployCCIPContr
8688
8789 // Use data store to track new deployed addresses
8890 dataStore := ds .NewMemoryDataStore ()
89- // Keep address book for backward compatibility. TODO remove it once we adopted this version in CLD
90- ab := cldf .NewMemoryAddressBook ()
91- contractsVersion := * semver .MustParse ("1.6.0" )
9291 if ccipSeqReport .Output .RouterAddress != nil {
9392 // FYI Add method will never fail given that the dataStore is empty
9493 _ = dataStore .Addresses ().Add (ccipSeqReport .Output .RouterAddress .CLDFAddressRef )
95- _ = ab .Save (selector , state .Router .String (), cldf .NewTypeAndVersion (cldf .ContractType (state .Router .String ()), contractsVersion ))
9694 s .Router = ccipSeqReport .Output .RouterAddress .TONAddress
9795 }
9896 if ccipSeqReport .Output .FeeQuoterAddress != nil {
9997 _ = dataStore .Addresses ().Add (ccipSeqReport .Output .FeeQuoterAddress .CLDFAddressRef )
100- _ = ab .Save (selector , state .FeeQuoter .String (), cldf .NewTypeAndVersion (cldf .ContractType (state .FeeQuoter .String ()), contractsVersion ))
10198 s .FeeQuoter = ccipSeqReport .Output .FeeQuoterAddress .TONAddress
10299 }
103100 if ccipSeqReport .Output .OnRampAddress != nil {
104101 _ = dataStore .Addresses ().Add (ccipSeqReport .Output .OnRampAddress .CLDFAddressRef )
105- _ = ab .Save (selector , state .OnRamp .String (), cldf .NewTypeAndVersion (cldf .ContractType (state .OnRamp .String ()), contractsVersion ))
106102 s .OnRamp = ccipSeqReport .Output .OnRampAddress .TONAddress
107103 }
108104 if ccipSeqReport .Output .OffRampAddress != nil {
109105 _ = dataStore .Addresses ().Add (ccipSeqReport .Output .OffRampAddress .CLDFAddressRef )
110- _ = ab .Save (selector , state .OffRamp .String (), cldf .NewTypeAndVersion (cldf .ContractType (state .OffRamp .String ()), contractsVersion ))
111106 s .OffRamp = ccipSeqReport .Output .OffRampAddress .TONAddress
112107 }
113108 if ccipSeqReport .Output .ReceiverAddress != nil {
114109 _ = dataStore .Addresses ().Add (ccipSeqReport .Output .ReceiverAddress .CLDFAddressRef )
115- _ = ab .Save (selector , state .TonReceiver .String (), cldf .NewTypeAndVersion (cldf .ContractType (state .TonReceiver .String ()), contractsVersion ))
116110 s .ReceiverAddress = ccipSeqReport .Output .ReceiverAddress .TONAddress
117111 }
118112 if ccipSeqReport .Output .TimelockAddress != nil {
119113 _ = dataStore .Addresses ().Add (ccipSeqReport .Output .TimelockAddress .CLDFAddressRef )
120- _ = ab .Save (selector , state .Timelock .String (), cldf .NewTypeAndVersion (cldf .ContractType (state .Timelock .String ()), contractsVersion ))
121114 s .Timelock = ccipSeqReport .Output .TimelockAddress .TONAddress
122115 }
123116
@@ -148,6 +141,9 @@ func (cs DeployCCIPContracts) Apply(env cldf.Environment, config DeployCCIPContr
148141 return cldf.ChangesetOutput {}, err
149142 }
150143
144+ // Keep address book for backward compatibility. TODO remove it once we adopted this version in CLD
145+ ab , _ := dataStoreToAddressBook (dataStore )
146+
151147 // TODO: generate MCMS proposal or execute
152148 return cldf.ChangesetOutput {
153149 MCMSTimelockProposals : proposals ,
@@ -156,3 +152,20 @@ func (cs DeployCCIPContracts) Apply(env cldf.Environment, config DeployCCIPContr
156152 AddressBook : ab ,
157153 }, nil
158154}
155+
156+ // Temp function to transform a DataStore to the legacy AddressBook. Couldn't find any utility function to do this.
157+ // Once we adopt this new change set in CLD we can remove returning AddressBook at all :)
158+ func dataStoreToAddressBook (ds * ds.MemoryDataStore ) (* cldf.AddressBookMap , error ) {
159+ ab := cldf .NewMemoryAddressBook ()
160+ addresses , err := ds .Addresses ().Fetch ()
161+ if err != nil {
162+ return nil , fmt .Errorf ("failed to list addresses from datastore: %w" , err )
163+ }
164+ for _ , addrRef := range addresses {
165+ err := ab .Save (addrRef .ChainSelector , addrRef .Address , cldf .NewTypeAndVersion (cldf .ContractType (addrRef .Type ), * addrRef .Version ))
166+ if err != nil {
167+ return nil , fmt .Errorf ("failed to save address %s to address book: %w" , addrRef .Type , err )
168+ }
169+ }
170+ return ab , nil
171+ }
0 commit comments