Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Conversation

@bddap
Copy link
Contributor

@bddap bddap commented Nov 8, 2019

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.

bddap added 6 commits November 8, 2019 13:24
…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.
@bddap bddap requested a review from tomusdrw as a code owner November 8, 2019 23:27
@parity-cla-bot
Copy link

It looks like @bddap signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

Copy link
Contributor

@tomusdrw tomusdrw left a 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]>"]
Copy link
Contributor

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?

@gnunicorn
Copy link
Contributor

@tomusdrw let's merge and resolve the dependency in the upcoming re-org?!?

@tomusdrw
Copy link
Contributor

Superseded by #4079

@tomusdrw tomusdrw closed this Nov 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants