Skip to content

feat: Enable retrieval of constants from runtime metadata#207

Merged
ascjones merged 1 commit intomasterfrom
zeke-const-meta-re
Dec 17, 2020
Merged

feat: Enable retrieval of constants from runtime metadata#207
ascjones merged 1 commit intomasterfrom
zeke-const-meta-re

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
Contributor

@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
Contributor

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
Contributor

@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
Contributor

@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