leonardocustodio / polkadart

Polkadart provides developers the ability to query a node and interact with the Polkadot based chains using Dart.
https://polkadart.dev
Apache License 2.0
39 stars 16 forks source link

Expose (double) map prefix for generated storage types or expose a `keys()` method for (double) maps #374

Closed clangenb closed 11 months ago

clangenb commented 1 year ago

It would be awesome to have that to easily generate storage keys for the state_getKeysPaged method. I imagine something like:

  Uint8List mapKeyPrefix() {
    final Uint8List hash = Uint8List(32 + hasher.size(key));
    Hasher.twoxx128.hashTo(
        data: Uint8List.fromList(utf8.encode(prefix)),
        output: hash.buffer.asUint8List(hash.offsetInBytes, 16));
    Hasher.twoxx128.hashTo(
        data: Uint8List.fromList(utf8.encode(storage)),
        output: hash.buffer.asUint8List(hash.offsetInBytes + 16, 16));
    return hash;
  }

Additionally, the generated storage types must be make public, to easily access that. I imagine something like:

final prefix = polkadot.query.system.account.mapKeyPrefix();
final keys = polkadot.rpc.state.getKeysPaged(prefix, count: 50);

Or this could even be internalized as generated code:

final keys = polkadot.query.system.account.keys(count: 50);