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

Add ability to iterate over N map storage keys #537

Merged
merged 11 commits into from
May 27, 2022
Merged

Add ability to iterate over N map storage keys #537

merged 11 commits into from
May 27, 2022

Conversation

lexnv
Copy link
Collaborator

@lexnv lexnv commented May 12, 2022

This PR changes the APi of rpc/storage_keys_paged() to receive a full
StorageKey. This behavior is similar to the exposed APIs by polkadot.js [0].
Using StorageKey instead of the prefixed version offers extensibility in terms
of API usage.

One such example is iterating over a double map storage key via providing
just the first key.

While at it, add an example to illustrate different methods of performing storage
queries that customers could extend for their own use-cases.

[0] https://polkadot.js.org/docs/substrate/rpc/#getkeyspagedkey-storagekey-count-u32-startkey-storagekey-at-blockhash-vecstoragekey

Feature requested by #526 .

Example Output

Example 1. Obtained keys:
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a270200000005dd59ff1333ed58157a7deed14d96af01000100511f
  Value: 4
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000100d8a96165380224fcebf540672e38c01000100411f
  Value: 7
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a27020000004e764be91a94f8c0b1516f7775b719ea01000100a10f
  Value: 2
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a270200000077250378cce57ae600f6c271b88c7649010001000920
  Value: 6
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a27020000007c40b0b99e93a82fa5901740fd6c0eba01000100711f
  Value: 3
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000b3004529114de762981310e9a525ec1901000100690a
  Value: 5
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000de763eb59c21d5cf088fab93114f368b01000100591f
  Value: 8

Example 2. Obtained keys:
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000de763eb59c21d5cf088fab93114f368b01000100591f
  Value: 8
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000b3004529114de762981310e9a525ec1901000100690a
  Value: 5
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a27020000007c40b0b99e93a82fa5901740fd6c0eba01000100711f
  Value: 3
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a270200000077250378cce57ae600f6c271b88c7649010001000920
  Value: 6
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a27020000004e764be91a94f8c0b1516f7775b719ea01000100a10f
  Value: 2
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000100d8a96165380224fcebf540672e38c01000100411f
  Value: 7
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a270200000005dd59ff1333ed58157a7deed14d96af01000100511f
  Value: 4

Example 3. Obtained keys:
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000de763eb59c21d5cf088fab93114f368b01000100591f
  Value: 8
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000b3004529114de762981310e9a525ec1901000100690a
  Value: 5
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a27020000007c40b0b99e93a82fa5901740fd6c0eba01000100711f
  Value: 3
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a270200000077250378cce57ae600f6c271b88c7649010001000920
  Value: 6
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a27020000004e764be91a94f8c0b1516f7775b719ea01000100a10f
  Value: 2
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000100d8a96165380224fcebf540672e38c01000100411f
  Value: 7
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a270200000005dd59ff1333ed58157a7deed14d96af01000100511f
  Value: 4

Example 4
Query key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000
Obtained keys:
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a270200000005dd59ff1333ed58157a7deed14d96af01000100511f
  Value: 4
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000100d8a96165380224fcebf540672e38c01000100411f
  Value: 7
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a27020000004e764be91a94f8c0b1516f7775b719ea01000100a10f
  Value: 2
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a270200000077250378cce57ae600f6c271b88c7649010001000920
  Value: 6
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a27020000007c40b0b99e93a82fa5901740fd6c0eba01000100711f
  Value: 3
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000b3004529114de762981310e9a525ec1901000100690a
  Value: 5
Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000de763eb59c21d5cf088fab93114f368b01000100591f
  Value: 8

lexnv added 11 commits May 11, 2022 17:01
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Copy link
Collaborator

@jsdw jsdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, liking the additional examples too :)

@jsdw jsdw requested a review from a team May 16, 2022 12:28
@lexnv lexnv self-assigned this May 25, 2022
@jsdw jsdw removed the request for review from a team May 27, 2022 10:44
Copy link
Member

@TarikGul TarikGul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jsdw jsdw merged commit 531e40d into master May 27, 2022
@jsdw jsdw deleted the storage_query branch May 27, 2022 14:09
@jsdw jsdw mentioned this pull request Jun 21, 2022
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 this pull request may close these issues.

3 participants