-
Notifications
You must be signed in to change notification settings - Fork 336
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
Add a utility function to get query responses to Decimal. #965
Comments
Yeah, the proto encoding of Cosmos SDK decimals (github.com/cosmos/cosmos-sdk/types.Dec) is annoying. Your code looks correct. I was looking for an example how we do it in CosmJS but it seems like all the queries that return decimals are only implemented for Launchpad, not Stargate. I'd very much appreciate a port of |
@webmaster128 I'd like to take up the task. Thanks |
What's really strange is the binary encoding in // QueryInflationResponse is the response type for the Query/Inflation RPC
// method.
message QueryInflationResponse {
// inflation is the current minting inflation value.
bytes inflation = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
} vs the string encoding in // CommissionRates defines the initial commission rates to be used for creating
// a validator.
message CommissionRates {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;
// rate is the commission rate charged to delegators, as a fraction.
string rate = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
// max_rate defines the maximum commission rate which validator can ever charge, as a fraction.
string max_rate = 2 [
(gogoproto.moretags) = "yaml:\"max_rate\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// max_change_rate defines the maximum daily increase of the validator commission, as a fraction.
string max_change_rate = 3 [
(gogoproto.moretags) = "yaml:\"max_change_rate\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
} |
Could you have a look at #969 (new |
#969 now conntains a full MintExtension for queries. Here I took the approch to wrap the whole protobuf API in custom types and do the decimal parsing internally. So it should be easy to use. It is somewhat inconsistent to many other query extensions that expose the original proto type. Happy for some 👀 on the PR. |
Will check it out with @blackpanther1881 |
Please also note cosmos/cosmos-sdk#10863 if you care about the future of Decimals in Cosmos SDK. |
@webmaster128 both decodeCosmosSdkDecFromProto and MintExtension from #969 working fine. decodeCosmosSdkDecFromProto response.toString() giving required result. |
Here
response.infaltion
returns a uint8array.Is there another way to do this?
The text was updated successfully, but these errors were encountered: