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

feat: Enable retrieval of constants from runtime metadata #207

Merged
merged 1 commit into from Dec 17, 2020

Conversation

emostov
Copy link
Contributor

@emostov emostov commented Dec 17, 2020

Closes #205

Example of new public api usage and outputs

    let client = ClientBuilder::<KusamaRuntime>::new().build().await?;
    let block_hash_count_meta = client.metadata()
        .module("System")?
        .constant("BlockHashCount")?;

    println!("name: {:#?}\n value: {:#?}\n ty: {:#?}\n documentation: {:#?}\n",
        block_hash_count_meta.name(),
        block_hash_count_meta.value::<u32>()?,
        block_hash_count_meta.ty(),
        block_hash_count_meta.documentation()
    );

  // name: "BlockHashCount"
  // value: 2400
  // ty: "T::BlockNumber"
  // documentation: [
  //    " The maximum number of blocks to allow in mortal eras.",
  // ]

Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

nice, LGTM

/// Get a constant's metadata by name
pub fn constant(
&self,
key: &'static str,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
key: &'static str,
key: &str,

No need to restrict it to 'static

Copy link
Member

@ascjones ascjones Dec 17, 2020

Choose a reason for hiding this comment

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

I see now some of the other similar methods are also 'static, but I don't think they need to be if we make the respective Error variants have a String instead.

Copy link
Member

@ascjones ascjones left a comment

Choose a reason for hiding this comment

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

LGTM

We can figure out whether to allow non 'static keys in another PR.

@ascjones ascjones merged commit 0a926ef into master Dec 17, 2020
@ascjones ascjones deleted the zeke-const-meta-re branch December 17, 2020 10:23
@ascjones ascjones mentioned this pull request Feb 5, 2021
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.

Add constants to metadata
3 participants