Skip to content

Commit

Permalink
format and check docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tadeohepperle committed Aug 10, 2023
1 parent 2f83d36 commit 57be757
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions subxt/src/book/usage/custom_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,49 @@
//!
//! Substrate-based chains can expose custom values in their metadata.
//! Each of these values:
//!
//!
//! - can be accessed by a unique __name__.
//! - refers to a concrete __type__ stored in the metadata.
//! - contains a scale encoded __value__ of that type.
//!
//!
//! ## Getting a custom value
//!
//! Custom values can be accessed via a [`CustomValuesClient`](subxt::custom_values::CustomValuesClient).
//!
//! Custom values can be accessed via a [`CustomValuesClient`](crate::custom_values::CustomValuesClient).
//! The client exposes an `at` function by which a custom value can be fetched, given an address to this custom value.
//! An address can be as simple as the aforementioned __name__ as a [str]. This will return a dynamic value, that you can manually decode into the type you want.
//! An address can be as simple as the aforementioned __name__ as a [str]. This will return a dynamic value, that you can manually decode into the type you want.
//! Suppose, the custom types contain a value of type `Foo` under the name `"foo"` you can access it like in this example:
//!
//!
//! ```rust
//! use subxt::{OnlineClient, PolkadotConfig, ext::{codec::Decode, scale_decode::DecodeAsType}};
//!
//!
//! #[derive(Decode, DecodeAsType, Debug)]
//! struct Foo {
//! struct Foo {
//! n: u8,
//! b: bool,
//! }
//!
//!
//! let api = OnlineClient::<PolkadotConfig>::new().await?;
//! let custom_value_client = api.custom_values();
//! let foo_dynamic = custom_value_client.at("foo")?;
//! let foo: Foo = foo_dynamic.as_type()?;
//!
//!
//! ```
//!
//!
//! Alternatively we also provide a statically generated api for custom values:
//!
//!
//! ```rust,no_run
//! #[subxt::subxt(runtime_metadata_path = "some_metadata.scale")]
//! pub mod interface {}
//!
//! let static_address = interface::custom().foo();
//!
//!
//! let api = OnlineClient::<PolkadotConfig>::new().await?;
//! let custom_value_client = api.custom_values();
//!
//!
//! // Now the `at()` function already decodes the value into the Foo type:
//! let foo = custom_value_client.at(&static_address)?;
//! let foo = custom_value_client.at(&static_address)?;
//! ```
//!
//!
//! Note: Names of custom values are converted to __snake_case__ to produce a valid function name during code generation.
//! If there are multiple values where the names would be equal when converted to __snake_case__, functions might not be statically generated for some of them, because of naming conflicts.
//! Make sure names in the custom values of your metadata differ significantly.
2 changes: 1 addition & 1 deletion subxt/src/book/usage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

pub mod blocks;
pub mod constants;
pub mod custom_values;
pub mod events;
pub mod light_client;
pub mod runtime_apis;
pub mod storage;
pub mod transactions;
pub mod custom_values;

0 comments on commit 57be757

Please sign in to comment.