feat: make account parser implementation extendable #1530
Open
0xpatrickdev wants to merge 4 commits intocosmos:mainfrom
Open
feat: make account parser implementation extendable #15300xpatrickdev wants to merge 4 commits intocosmos:mainfrom
0xpatrickdev wants to merge 4 commits intocosmos:mainfrom
Conversation
- adds AccountParserManager class where consumers can register different accountParsers - adds createDefaultAccountParser() which instantiates AccountParserManager with common cosmos-sdk account types - preserves existing accountFromAny interface for backwards compatability
- refactor createDefaultAccountParser (instance) to createAccountParserRegistry (map of accountParsers) for easier testing
…er class, and AccountParserRegistry type
0xpatrickdev
commented
Dec 22, 2023
Comment on lines
+134
to
+136
| * const myAccountParserManager = new AccountParserManager(createAccountParserRegistry()); | ||
| * myAccountParserManager.register('/custom.type.v1.CustomAccount', customAccountParser); | ||
| * const account = customParserManager.parseAccount(someInput); |
Contributor
Author
There was a problem hiding this comment.
Suggested change
| * const myAccountParserManager = new AccountParserManager(createAccountParserRegistry()); | |
| * myAccountParserManager.register('/custom.type.v1.CustomAccount', customAccountParser); | |
| * const account = customParserManager.parseAccount(someInput); | |
| * const { register, parseAccount } = new AccountParserManager(createAccountParserRegistry()); | |
| * register('/custom.type.v1.CustomAccount', customAccountParser); | |
| * const options: StargateClientOptions = { accountParser: parseAccount }; |
This probably aligns closer to expected usage
0xpatrickdev
commented
Dec 23, 2023
| */ | ||
| export type AccountParser = (any: Any) => Account; | ||
|
|
||
| export type AccountParserRegistry = Map<Any["typeUrl"], AccountParser>; |
Contributor
Author
There was a problem hiding this comment.
Realizing we may also want to export accountFromBaseAccount (L26-L35), as this will likely be needed by those supplying a custom account parser. Alternatively, this could be baked into every parseAccount call as every AccountParser function likely needs this as the last step.
Will wait for feedback on this and the overall design before making any updates.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
AccountParserManagerclass that enables registeringAccountParserscreateAccountParserRegistry, a map of well-knowntypeUrls andAccountParser'saccountFromAnyfunctionality