-
Notifications
You must be signed in to change notification settings - Fork 0
[CLD-1916]: fix(aptos): port LoadMCMSAddresses #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package aptos | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/Masterminds/semver/v3" | ||
| "github.com/aptos-labs/aptos-go-sdk" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-deployments-framework/datastore" | ||
| cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" | ||
| ) | ||
|
|
||
| const ( | ||
| // todo: move to CLDF? | ||
| AptosMCMSType cldf.ContractType = "AptosManyChainMultisig" | ||
| ) | ||
|
|
||
| // LoadMCMSAddresses tries to load the mcms addresses for all given chain selectors from the environment. | ||
| // mcmsContractVersion is the semver that must match each candidate address ref's Version field. | ||
| // If no mcms address can be found for any given chain selector, an error will be returned. | ||
|
graham-chainlink marked this conversation as resolved.
|
||
| func LoadMCMSAddresses(env cldf.Environment, chainSelectors []uint64, mcmsContractVersion semver.Version) (map[uint64]aptos.AccountAddress, error) { | ||
| result := make(map[uint64]aptos.AccountAddress) | ||
| for _, selector := range chainSelectors { | ||
| var mcmsAddress aptos.AccountAddress | ||
| found := false | ||
| refs := env.DataStore.Addresses().Filter(datastore.AddressRefByChainSelector(selector)) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed this from addressbook to datastore |
||
| for _, ref := range refs { | ||
| if ref.Type != datastore.ContractType(AptosMCMSType) || ref.Version == nil || !ref.Version.Equal(&mcmsContractVersion) { | ||
| continue | ||
| } | ||
| if err := mcmsAddress.ParseStringRelaxed(ref.Address); err != nil { | ||
| return nil, fmt.Errorf( | ||
| "failed to parse MCMS address for Aptos chain selector %d (type=%s, version=%s, address=%s): %w", | ||
| selector, ref.Type, ref.Version.String(), ref.Address, err, | ||
| ) | ||
| } | ||
| found = true | ||
|
|
||
| break | ||
| } | ||
|
graham-chainlink marked this conversation as resolved.
|
||
| if !found { | ||
| return nil, fmt.Errorf("no MCMS address found for Aptos chain selector: %d", selector) | ||
| } | ||
| result[selector] = mcmsAddress | ||
| } | ||
|
|
||
| return result, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May move this to CLDF with others , so i dont have to move 1 at a time