moonbeam
moonbeam copied to clipboard
add scale helper script
What does it do?
Adds a scale helper script to perform storage operations
1. Encode Key
$ ./scale.ts key --pallet System --storage Account --key 0x6Df05cBd5113261Dd0f63fb8ce89FC0e236B844e
0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da925e08b7dc98ca546e54165137e41c2416df05cbd5113261dd0f63fb8ce89fc0e236b844e
2. Decode from raw storage
Normal
$ ./scale.ts --ws wss://wss.api.moonbase.moonbeam.network decode --type FrameSystemAccountInfo --value '0x16000000000000000100000000000000cb61eec469fb375bd90000000000000000c0b03fbdf6c7040b000000000000000000000000000000000000000000000000000000000000000000000000000000'
{
nonce: '22',
consumers: '0',
providers: '1',
sufficients: '0',
data: {
free: '4,009,516,462,607,837,323,723',
reserved: '203,258,700,000,000,000,000',
miscFrozen: '0',
feeFrozen: '0'
}
}
Explain
$ ./scale.ts --ws wss://wss.api.moonbase.moonbeam.network decode --type FrameSystemAccountInfo --value '0x16000000000000000100000000000000cb61eec469fb375bd90000000000000000c0b03fbdf6c7040b000000000000000000000000000000000000000000000000000000000000000000000000000000' --explain
{
nonce: { value: '22', scale: '16000000' },
consumers: { value: '0', scale: '00000000' },
providers: { value: '1', scale: '01000000' },
sufficients: { value: '0', scale: '00000000' },
data: {
free: {
value: '4,009,516,462,607,837,323,723',
scale: 'cb61eec469fb375bd900000000000000'
},
reserved: {
value: '203,258,700,000,000,000,000',
scale: '00c0b03fbdf6c7040b00000000000000'
},
miscFrozen: { value: '0', scale: '00000000000000000000000000000000' },
feeFrozen: { value: '0', scale: '00000000000000000000000000000000' }
}
}
3. Encode to raw storage
Normal
$ $ ./scale.ts --ws wss://wss.api.moonbase.moonbeam.network encode --type FrameSystemAccountInfo --value '{
"nonce": "22",
"consumers": "0",
"providers": "1",
"sufficients": "0",
"data": {
"free": "4009516462607837323723",
"reserved": "203258700000000000000",
"miscFrozen": "0",
"feeFrozen": "0"
}
}'
0x16000000000000000100000000000000cb61eec469fb375bd90000000000000000c0b03fbdf6c7040b000000000000000000000000000000000000000000000000000000000000000000000000000000
Explain
$ $ ./scale.ts --ws wss://wss.api.moonbase.moonbeam.network encode --explain --type FrameSystemAccountInfo --value '{ "nonce": "22",
"consumers": "0",
"providers": "1",
"sufficients": "0",
"data": {
"free": "4009516462607837323723",
"reserved": "203258700000000000000",
"miscFrozen": "0",
"feeFrozen": "0"
}
}'
{
nonce: { value: '22', scale: '16000000' },
consumers: { value: '0', scale: '00000000' },
providers: { value: '1', scale: '01000000' },
sufficients: { value: '0', scale: '00000000' },
data: {
free: {
value: '4,009,516,462,607,837,323,723',
scale: 'cb61eec469fb375bd900000000000000'
},
reserved: {
value: '203,258,700,000,000,000,000',
scale: '00c0b03fbdf6c7040b00000000000000'
},
miscFrozen: { value: '0', scale: '00000000000000000000000000000000' },
feeFrozen: { value: '0', scale: '00000000000000000000000000000000' }
}
}
What important points reviewers should know?
Is there something left for follow-up PRs?
What alternative implementations were considered?
Are there relevant PRs or issues in other repositories (Substrate, Polkadot, Frontier, Cumulus)?
What value does it bring to the blockchain users?
Also, this should probably be moved to the moonbeam-tools repo
Isn't polkadotjs cli already providing this kind of support ?
I'm unaware of any such functionality. I think most storage operations were done manually within the team.
Also, would be great if it could list all the types or search through them because it is not always easy to know the exact type name
I can look into it.
Though the type name can be easily retrieved from the polkadot-ui when the query call is returned, or from the typescript-api as well during scripting.
Also, this should probably be moved to the moonbeam-tools repo
Can do that as well. But seems no one from the team reviews the PRs there.
The moonbeam-tools is less restrictive so you don't need a review to merge it but you can ask for
However we should make the external tools on that repo and not on moonbeam
Closing in favor of https://github.com/PureStake/moonbeam-tools/pull/13