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

CLI Tool Explore Command: Runtime APIs, Events, Colorized outputs, scale-typegen integration #1290

Merged
merged 66 commits into from
Jan 19, 2024

Conversation

tadeohepperle
Copy link
Contributor

Warning: Do not merge (we need to wait for a full scale-typgen release before we can integrate this PR)

This PR restructures the subxt explore CLI command. You can now explore pallet events: subxt explore pallet balances events:
image
And you can explore runtime apis: subxt explore api metadata by adding the --execute (-e) flag to a runtime api method, e.g. subxt explore api core version -e you can view the return-value of the runtime-api call:
image

Upon starting the explore command (subxt explore) you get shown a list of all available pallets and runtime apis. When You only type subxt explore pallet you only see available pallets. For outputs I use ANSI coloring which is already part of the color_eyre crate, so no new dependencies needed to be added. I added a dependency though for indoc, which makes the code a lot cleaner.

Testing

Manually tested, and tests have been adjusted.

tadeohepperle and others added 22 commits November 20, 2023 10:12
* config: Add `SkipCheckIfFeeless` signed extension

Signed-off-by: Alexandru Vasile <[email protected]>

* config: Add extra extension to the default params

Signed-off-by: Alexandru Vasile <[email protected]>

* examples: Adjust signed extension example

Signed-off-by: Alexandru Vasile <[email protected]>

* config: Extend SkipCheckIfFeeless with inner signed extension

Signed-off-by: Alexandru Vasile <[email protected]>

* config: Configure SkipCheck with inner signed extension params

Signed-off-by: Alexandru Vasile <[email protected]>

* config: Implement Deafult for SkipCheckIfFeelessParams with Option

Signed-off-by: Alexandru Vasile <[email protected]>

* examples: Fix example with proper extension

Signed-off-by: Alexandru Vasile <[email protected]>

* config: Extend <T as Config>::AssetId with EncodeAsType and Clone

Signed-off-by: Alexandru Vasile <[email protected]>

* config: Add SkipCheck with AssetTx

Signed-off-by: Alexandru Vasile <[email protected]>

* config: Encode as type from metadata the inner signed extensions

Signed-off-by: Alexandru Vasile <[email protected]>

* Adjust examples

Signed-off-by: Alexandru Vasile <[email protected]>

* blocks: Use `SkipCheckIfFeeless` for decoding the tip of extensions

Signed-off-by: Alexandru Vasile <[email protected]>

* config: Decode `SkipCheckIfFeeless` with `Self`

Signed-off-by: Alexandru Vasile <[email protected]>

* tests: Adjust testing

Signed-off-by: Alexandru Vasile <[email protected]>

* config: Descriptive errors for building `SkipCheckIfFeeless`

Signed-off-by: Alexandru Vasile <[email protected]>

* config: Add docs for extra error types

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt: Add extra derives to signed extensions

Signed-off-by: Alexandru Vasile <[email protected]>

* config: Use `Default::default` to simplify type init

Signed-off-by: Alexandru Vasile <[email protected]>

---------

Signed-off-by: Alexandru Vasile <[email protected]>
* lightclient: Make `smoldot::chainID` part of the RPC requests

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Make `BackgroundTask` generic over `PlatformRef` and chain

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Construct from raw smoldot and target different chains

Signed-off-by: Alexandru Vasile <[email protected]>

* testing: Update cargo lock for wasm tests

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Reuse `new_from_client` method and removed unused imports

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Reexport smoldot client and RPC objects used in pub
interface

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Adjust `new_from_client` interface

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Extend background to poll over multiple RPC objects

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt: Build light client from raw and target different chains

Signed-off-by: Alexandru Vasile <[email protected]>

* artifacts: Add demo chain specs

Signed-off-by: Alexandru Vasile <[email protected]>

* artifacts: Move artifacts to dedicated folder

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Use SelectAll to drive all streams

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Fetch initial data from the target chain

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Reexport other smoldot objects

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt: Target chain with potentially different config

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt/rpc: Log chainID for debugging

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt/examples: Add smoldot client with parachain example

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Propagate chain ID together with rpc responses object

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Multiplex responses by request ID and chain ID

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt: Add raw light client builder

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt: Add cargo feature flag for parachains example

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Derive default for internal structure

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Guard reexports by std feature flag

Signed-off-by: Alexandru Vasile <[email protected]>

* Update subxt/src/client/light_client/mod.rs

Co-authored-by: James Wilson <[email protected]>

* lightclient: Update the builder pattern and chain targetting

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Fix documentation

Signed-off-by: Alexandru Vasile <[email protected]>

* Provide more insightful docs wrt native/wasm panics

Signed-off-by: Alexandru Vasile <[email protected]>

* examples: Adjust comment location

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Refactor UniqueChainId into the background task

Signed-off-by: Alexandru Vasile <[email protected]>

* Update lightclient/src/background.rs

Co-authored-by: Niklas Adolfsson <[email protected]>

* Update subxt/src/client/light_client/builder.rs

Co-authored-by: James Wilson <[email protected]>

* lightclient: Update docs wrt panics

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt: Update docs wrt to smoldot instance -> client

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Use IntoIter instead of Iterator

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt: Adjsut docs wrt [`Self::new_from_client`]

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt: Remove RawRpc from LightClient in favor of chainID

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Reexport everything under smoldot module

Signed-off-by: Alexandru Vasile <[email protected]>

* artifacts: Use stateRootHash instead of genesis.raw

Signed-off-by: Alexandru Vasile <[email protected]>

---------

Signed-off-by: Alexandru Vasile <[email protected]>
Co-authored-by: James Wilson <[email protected]>
Co-authored-by: Niklas Adolfsson <[email protected]>
Bumps [futures](https://github.com/rust-lang/futures-rs) from 0.3.28 to 0.3.29.
- [Release notes](https://github.com/rust-lang/futures-rs/releases)
- [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md)
- [Commits](rust-lang/futures-rs@0.3.28...0.3.29)

---
updated-dependencies:
- dependency-name: futures
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [zeroize](https://github.com/RustCrypto/utils) from 1.6.0 to 1.7.0.
- [Commits](https://github.com/RustCrypto/utils/commits)

---
updated-dependencies:
- dependency-name: zeroize
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.3.17 to 0.3.18.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](tokio-rs/tracing@tracing-subscriber-0.3.17...tracing-subscriber-0.3.18)

---
updated-dependencies:
- dependency-name: tracing-subscriber
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.3.17 to 0.3.18.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](tokio-rs/tracing@tracing-subscriber-0.3.17...tracing-subscriber-0.3.18)

---
updated-dependencies:
- dependency-name: tracing-subscriber
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [getrandom](https://github.com/rust-random/getrandom) from 0.2.10 to 0.2.11.
- [Changelog](https://github.com/rust-random/getrandom/blob/master/CHANGELOG.md)
- [Commits](rust-random/getrandom@v0.2.10...v0.2.11)

---
updated-dependencies:
- dependency-name: getrandom
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* impl RpcClientT for Arc<WsClient>

* fix grumbles: impl for Box<T> and Arc<T>

* grumbles: move RpcClientT impls
@tadeohepperle tadeohepperle requested a review from a team as a code owner November 24, 2023 08:21
@tadeohepperle tadeohepperle changed the title CLI Tool Explore Command: Support Runtime APIs, Events, Colorized outputs, Scale-typegen integration CLI Tool Explore Command: Runtime APIs, Events, Colorized outputs, scale-typegen integration Nov 24, 2023
tadeohepperle and others added 6 commits November 29, 2023 10:52
* improve `substrate-compat`

* From => Into

---------

Co-authored-by: James Wilson <[email protected]>
Bumps [proc-macro2](https://github.com/dtolnay/proc-macro2) from 1.0.69 to 1.0.70.
- [Release notes](https://github.com/dtolnay/proc-macro2/releases)
- [Commits](dtolnay/proc-macro2@1.0.69...1.0.70)

---
updated-dependencies:
- dependency-name: proc-macro2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.192 to 1.0.193.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](serde-rs/serde@v1.0.192...v1.0.193)

---
updated-dependencies:
- dependency-name: serde
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* lightclient: Close wasm socket while dropping from connecting state

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Construct one time only closures

Signed-off-by: Alexandru Vasile <[email protected]>

* testing: Enable console logs for lightclient WASM testing

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Separate wakes and check connectivity on poll_read

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Close the socket depending on internal state

Signed-off-by: Alexandru Vasile <[email protected]>

* Revert "lightclient: Separate wakes and check connectivity on poll_read"

This reverts commit 8660940.

* lightclient: Return pending if socket is opening from poll_read

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Close the socket on `poll_close`

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Reset closures on Drop to avoid recursive invokation

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Close the socket if not already closing

Signed-off-by: Alexandru Vasile <[email protected]>

---------

Signed-off-by: Alexandru Vasile <[email protected]>
jsdw and others added 13 commits January 18, 2024 17:07
* rpcmethods

* followstr

* mod and else
…1352)

* github CI action cronjob

* add commit message

* fix the CI yml files

* binary crate for CI script with substrate-runner

* update the CI script

* correct the artifacts script

* remove bash script
…old (#1372)

* testing(fix): Ensure lightclient chainSpec is at least one block old

Signed-off-by: Alexandru Vasile <[email protected]>

* Revert "testing(fix): Ensure lightclient chainSpec is at least one block old"

This reverts commit 0eafcb2.

* lightclient(fix): Ensure lightclient chainSpec is at least one block old

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Link smoldot issue

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt: Use tokio under lightclient feature flag

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Do not sleep on errors to fetch the chainSpec

Signed-off-by: Alexandru Vasile <[email protected]>

* artifacts: Remove test file

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Subscribe to two finalized blocks

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt: Revert cargo toml

Signed-off-by: Alexandru Vasile <[email protected]>

---------

Signed-off-by: Alexandru Vasile <[email protected]>
* ci: Reduce the light client timpeut to 15 seconds

Signed-off-by: Alexandru Vasile <[email protected]>

* ci: Use ubuntu-latest for light-client tests

Signed-off-by: Alexandru Vasile <[email protected]>

---------

Signed-off-by: Alexandru Vasile <[email protected]>
* asset hub example and book adjustment

* formatting

* recursive derives

* polkadot monitor example and book adjustments

* formatting

* adjust docs and examples, add dynamic example

* james suggestions

* fmt

* chore(subxt/src): typo fix (#1370)

* rpcmethods

* followstr

* mod and else

* Weekly Cronjob fetching artifacts and generating polkadot.rs file. (#1352)

* github CI action cronjob

* add commit message

* fix the CI yml files

* binary crate for CI script with substrate-runner

* update the CI script

* correct the artifacts script

* remove bash script

---------

Co-authored-by: James Wilson <[email protected]>
Co-authored-by: Pan chao <[email protected]>
@tadeohepperle
Copy link
Contributor Author

I finally figured out how to submit the parameters needed for a dynamic runtime api call in the CLI:

  • take the input as a &str
  • parse it into a scale value
  • encode it to bytes using the params type id
  • decode it from the bytes using the params type id

IIRC @niklasad1 was doing something similar a few months back somewhere.

Now we can execute runtime apis like this:

image

cli/Cargo.toml Outdated
@@ -40,5 +40,12 @@ scale-value = { workspace = true }
syn = { workspace = true }
jsonrpsee = { workspace = true, features = ["async-client", "client-ws-transport-native-tls", "http-client"] }
tokio = { workspace = true, features = ["rt-multi-thread"] }
scale-typegen-description = { workspace = true }
heck = { workspace = true }
indoc = "2"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could probably move the indoc adn strip-ansi to the workspace Cargo.toml to make sure we can easily update it everywhere. Just in case we'll add it to multipl crates in the future. Leaving this up to you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, but I would prefer to do it later when we really need it another crate of the workspace.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's do it now for consistency, because I think every other dependency is now listed in the workspace thing first (except for non-workspace crates where we can't). Makes it mostly easy to see the entire set of crates we use in one place at least!


let usage = || {
let events = events_to_string(event_variants, pallet_name);
formatdoc! {"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This does make it easier to see how things will be formatted; good find!

trailing_args: Vec<String>,
}

pub async fn explore_storage(
Copy link
Collaborator

Choose a reason for hiding this comment

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

With runtime APIs, we have an -e flag to actually try to execute a runtime API call. I feel like we should do the same for executing a storage request, so that by default we don't try to make a request but we can if we want. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I added an -e flag for storage entries as well and made the API very similar to the runtime apis.

Comment on lines 96 to 97
#[allow(non_snake_case)]
let INPUT_VALUE: String = "<INPUT_VALUE>".blue().to_string();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Personally I'd just name it something like blue_input_placeholder or something (likewise elsewhere) and avoid needing to add the allow

{fields_example}"}
};

let execute_usage = || {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could just be a block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, good catch, I made it a closure to use it twice below, but used it only once. I am now replacing the usage() below by the second execute_usage() as intended.

/// # Encoded call data:
/// # 0x24040607020cffffff00
/// ```
/// ## Constants
/// ### Constants
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd ensure a newline above and below each heading (this and below are missing one or both), and in general add newlines before and after the code blocks in this whole section (and anywhere else) just to make it more readable as plain text :)

@jsdw
Copy link
Collaborator

jsdw commented Jan 19, 2024

Minor comments but I think they should be addressed, and then for me this is good to go! The colouring thing on my laptop is strange but we can sort that out later if it keeps coming up.

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.

Awesome stuff, nicely done :)

@tadeohepperle tadeohepperle merged commit 05ced83 into master Jan 19, 2024
11 checks passed
@tadeohepperle tadeohepperle deleted the tadeohepperle/cli-support-runtime-apis branch January 19, 2024 16:57
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.

None yet

6 participants