Skip to content
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

Decode hex values returned from /runtime/metadata #893

Closed
CurlyBracketEffect opened this issue Apr 7, 2022 · 1 comment · Fixed by #907
Closed

Decode hex values returned from /runtime/metadata #893

CurlyBracketEffect opened this issue Apr 7, 2022 · 1 comment · Fixed by #907

Comments

@CurlyBracketEffect
Copy link
Contributor

It would be useful if the value returned by the /runtime/metadata endpoint was decoded to decimal.

Currently, this is what is returned when querying Polkadot:

"constants": [
{
"name": "ExistentialDeposit",
"type": "6",
"value": "0x00e40b54020000000000000000000000",
"docs": [
" The minimum amount required to keep an account open."
]
},

The alternative to this would be to have the user convert it themselves, but being that this is SCALE encoded, they would need another library and the know-how to do so. Since the goal for Sidecar is to be an abstraction layer between PJS API and the user, I think this would be a good quality of life upgrade.

@TarikGul
Copy link
Member

Okay so currently this is because the values expected from constants such as ExistentialDeposit are typed as a u128. Which in Javascript cant be greater than 53 bits. In this case it's returned as a hex value with the prototype chain being the following: -> Bytes -> Raw -> Uint8Array -> TypedArray -> Object.

Technically we can just use hexToBn(value, { isLe: true }).toString() when sanitizing. But the trouble I am having currently is how can we generically apply this to the sanitation process without making any assumptions on what the value of the bytes are (Is it a u128, or maybe a very large hex value containing a bunch of information 🤷 ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants