-
Notifications
You must be signed in to change notification settings - Fork 346
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
feat: allow to specify an AccountParser inside StargateClient #1102
feat: allow to specify an AccountParser inside StargateClient #1102
Conversation
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.
Good start.
Should we make accountFromAny
public (maybe under different name) such that the parser can be implemented as custom type or default to accountFromAny implementation.
Do you have an example of how you would implement this? |
Let's get in the user's perspective, imagine someone wants to create a client that supports import { Profile } from "@desmos/generated/types/accounts";
function myParser(input: Any): Account {
const { typeUrl, value } = input;
if (typeUrl === "/desmos.profiles.v1beta1.Profile") {
// version 1
const baseAccount = Profile.decode(value)?..baseAccount;
assert(baseAccount);
return accountFromBaseAccount(baseAccount); // accountFromBaseAccount is not public
// version 2
return {
address: address,
pubkey: pubkey,
accountNumber: uint64FromProto(accountNumber).toNumber(), // uint64FromProto is not public
sequence: uint64FromProto(sequence).toNumber(),
}
} else {
throw new Error("Found unsupported account type"); // is this desired? Do you want a fallback to standard Cosmos SDK accounts?
}
} So basically it's unclear to me if it is currently possible to write a good implementation of the new interface. |
I've actually implemented like the following: export function profileFromAny(input: Any): Account {
const { typeUrl, value } = input;
switch (typeUrl) {
case "/desmos.profiles.v1beta1.Profile": {
const baseAccount = Profile.decode(value)?.account;
assert(baseAccount);
return accountFromAny(baseAccount);
}
default:
return accountFromAny(input);
}
} This kind of implementation relies on the following things:
So, each custom |
Looks good. I missed that In this case I consider this feature-complete. Can you add a CHANGELOG entry? Then 🐎🐎🐎 |
Added, let me know if it can be improved |
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.
Looks good. Just the exports left
Released as part of 0.28.1 |
This PR introduces a new
StargateClientOptions
interface that allows setting custom options forStargateClient
.The most important option is the
accountParser
option, which must be anAccountParser
instance and allows to provide theStargateClient
a custom way of decoding Cosmos accounts. This is particularly useful to solve problems when reading account from chains that support custom account types (eg. the Desmos chain). This can solve problems like the one REStake is having: eco-stake/restake#334