-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate storage key prefix methods (#381)
- Loading branch information
Showing
10 changed files
with
171 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'package:convert/convert.dart'; | ||
import 'package:polkadart/scale_codec.dart'; | ||
import 'package:polkadart_example/generated/polkadot/types/sp_core/crypto/account_id32.dart'; | ||
import 'package:polkadart/polkadart.dart' show Provider; | ||
|
||
import 'package:polkadart_example/generated/polkadot/polkadot.dart'; | ||
|
||
Future<void> main(List<String> arguments) async { | ||
final provider = Provider.fromUri(Uri.parse('wss://rpc.polkadot.io')); | ||
final polkadot = Polkadot(provider); | ||
|
||
final accountMapPrefix = polkadot.query.system.accountMapPrefix(); | ||
final keys = await polkadot.rpc.state.getKeysPaged(key: accountMapPrefix, count: 10); | ||
|
||
print("First 10 account storage keys: ${keys.map((key) => '0x${hex.encode(key)}')}"); | ||
|
||
// Decoding of the keys has to be done manually for now, see how substrate storage keys are defined: | ||
// https://www.shawntabrizi.com/blog/substrate/transparent-keys-in-substrate/ | ||
final accountIds = keys.map((key) => const AccountId32Codec().decode(ByteInput(key.sublist(32)))); | ||
print("First 10 account pubKeys: ${accountIds.map((account) => '0x${hex.encode(account)}')}"); | ||
|
||
// Get `AccountInfo`s of those keys | ||
final accountInfos = await Future.wait(accountIds.map((account) => polkadot.query.system.account(account))); | ||
|
||
for (final accountInfo in accountInfos) { | ||
print('AccountInfo: ${accountInfo.toJson()}'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Directory for the generated files. |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# melos_managed_dependency_overrides: polkadart,polkadart_cli,polkadart_keyring,polkadart_scale_codec,ss58,substrate_bip39,substrate_metadata | ||
dependency_overrides: | ||
polkadart: | ||
path: ../packages/polkadart | ||
polkadart_cli: | ||
path: ../packages/polkadart_cli | ||
polkadart_keyring: | ||
path: ../packages/polkadart_keyring | ||
polkadart_scale_codec: | ||
path: ../packages/polkadart_scale_codec | ||
ss58: | ||
path: ../packages/ss58 | ||
substrate_bip39: | ||
path: ../packages/substrate_bip39 | ||
substrate_metadata: | ||
path: ../packages/substrate_metadata |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ command: | |
|
||
packages: | ||
- packages/** | ||
- examples | ||
|
||
scripts: | ||
test: | ||
|
This file contains 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
This file contains 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