-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Typed chain state queries over rpc. #4059
Conversation
…clared by 'decl_storage!'.
…titive. This commit makes the implementation simpler by intruducing a struct which represents query for a typed value in storage. The new struct is called StorageQuery. A StorageQuery wraps a raw StorageKey but is not directy constructable. To construct a StorageQuery, the user must supply an implementation of a srml_support::storage::generator trait such as StorageValue or StorageMap. A type implementing one of the generator traits can be aquired by: A) marking a storage item as pub within a call to decl_storage (recommended) or B) implementing one of the generator types manually. While option B may sometimes me necessary, it's not recommended because separate manual implementaions may lose sync with the original definition.
declaration. This field was added to support a test in an earlier commit. The test no longer relies on test-runtime so the change can be reverted.
|
It looks like @bddap signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
tomusdrw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
The core RPC does not depend on (or assume the existence of) srml, and I suppose we want to keep it this way.
I think the RPC should be rather moved to srml and be treated as opt-in core-RPC extension (see how we initialize srml-system-rpc for instance).
| [package] | ||
| name = "substrate-rpc-custom" | ||
| version = "0.1.0" | ||
| authors = ["Andrew Dirksen <[email protected]>"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should include ParityTech I suppose?
|
@tomusdrw let's merge and resolve the dependency in the upcoming re-org?!? |
|
Superseded by #4079 |
This pr adds the ability to query values from chain state in a type-safe way, over rpc.
The decl_storage macro already generates implementations of the srml_support::storage::generator traits (StorageValue, StorageMap, StorageLinkedMap, and StorageDoubleMap). Those traits are currently used to provide type-safe storage access to runtime modules. This pr uses those same traits to provide type-safe storage access over json rpc. The approach keeps users from manually calculating storage keys, a potentially error prone process.
This pr adds minimal functionality, just the ability to get a typed value using a typed key. If the changes are well received, I'd like to look into additional functionality, like subscribing to typed keys, subscribing to events, creating and submitting typed extrinsics, etc.
The new workspace member is called substrate-rpc-custom as it allows queries on storage defined custom runtime modules, as opposed to substrate-rpc-api, which is mostly runtime agnostic. The new workspace member depends on both srml-support and on substrate-rpc-api. It was placed in "core/rpc/custom", alongside other rpc utilities, for discoverability.