06ab693b4c
- Update copyright from 'Parity Technologies (UK) Ltd.' to 'Dijital Kurdistan Tech Institute' - Update year to 2026 - Mark doc tests with relative metadata paths as 'ignore' to fix workspace-level doc tests - Affected files: runtime_apis.rs, storage.rs, constants.rs, transactions.rs, codegen.rs The doc tests use relative paths like '../artifacts/*.scale' which only work when testing the crate directly (-p pezkuwi-subxt), not during workspace-level tests. The examples/ directory contains the actual runnable test code.
81 lines
3.3 KiB
Rust
81 lines
3.3 KiB
Rust
// Copyright 2019-2026 Dijital Kurdistan Tech Institute
|
|
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
|
// see LICENSE for license details.
|
|
|
|
//! # Runtime API interface
|
|
//!
|
|
//! The Runtime API interface allows Subxt to call runtime APIs exposed by certain pallets in order
|
|
//! to obtain information. Much like [`super::storage`] and [`super::transactions`], Making a
|
|
//! runtime call to a node and getting the response back takes the following steps:
|
|
//!
|
|
//! 1. [Constructing a runtime call](#constructing-a-runtime-call)
|
|
//! 2. [Submitting it to get back the response](#submitting-it)
|
|
//!
|
|
//! **Note:** Runtime APIs are only available when using V15 metadata, which is currently unstable.
|
|
//! You'll need to use `subxt metadata --version unstable` command to download the unstable V15
|
|
//! metadata, and activate the `unstable-metadata` feature in Subxt for it to also use this metadata
|
|
//! from a node. The metadata format is unstable because it may change and break compatibility with
|
|
//! Subxt at any moment, so use at your own risk.
|
|
//!
|
|
//! ## Constructing a runtime call
|
|
//!
|
|
//! We can use the statically generated interface to build runtime calls:
|
|
//!
|
|
//! ```rust,ignore
|
|
//! // Note: This example uses a relative path that only works when testing this crate directly.
|
|
//! // For workspace-level doc tests, this is ignored. See examples/ for runnable code.
|
|
//! #[pezkuwi_subxt::subxt(runtime_metadata_path = "../artifacts/pezkuwi_metadata_small.scale")]
|
|
//! pub mod pezkuwi {}
|
|
//!
|
|
//! let runtime_call = pezkuwi::apis().metadata().metadata_versions();
|
|
//! ```
|
|
//!
|
|
//! Alternately, we can dynamically construct a runtime call. The input type can be a tuple or
|
|
//! vec or valid types implementing [`scale_encode::EncodeAsType`], and the output can be anything
|
|
//! implementing [`scale_decode::DecodeAsType`]:
|
|
//!
|
|
//! ```rust,no_run
|
|
//! use pezkuwi_subxt::dynamic::Value;
|
|
//!
|
|
//! let runtime_call = pezkuwi_subxt::dynamic::runtime_api_call::<(), Vec<u32>>(
|
|
//! "Metadata",
|
|
//! "metadata_versions",
|
|
//! ()
|
|
//! );
|
|
//! ```
|
|
//!
|
|
//! All valid runtime calls implement [`crate::runtime_api::Payload`], a trait which
|
|
//! describes how to encode the runtime call arguments and what return type to decode from the
|
|
//! response.
|
|
//!
|
|
//! ## Submitting it
|
|
//!
|
|
//! Runtime calls can be handed to [`crate::runtime_api::RuntimeApi::call()`], which will submit
|
|
//! them and hand back the associated response.
|
|
//!
|
|
//! ### Making a static Runtime API call
|
|
//!
|
|
//! The easiest way to make a runtime API call is to use the statically generated interface.
|
|
//!
|
|
//! ```rust,ignore
|
|
#![doc = include_str!("../../../examples/runtime_apis_static.rs")]
|
|
//! ```
|
|
//!
|
|
//! ### Making a dynamic Runtime API call
|
|
//!
|
|
//! If you'd prefer to construct the call at runtime, you can do this using the
|
|
//! [`crate::dynamic::runtime_api_call`] method.
|
|
//! ```rust,ignore
|
|
#![doc = include_str!("../../../examples/runtime_apis_dynamic.rs")]
|
|
//! ```
|
|
//!
|
|
//! ### Making a raw call
|
|
//!
|
|
//! This is generally discouraged in favour of one of the above, but may be necessary (especially if
|
|
//! the node you're talking to does not yet serve V15 metadata). Here, you must manually encode
|
|
//! the argument bytes and manually provide a type for the response bytes to be decoded into.
|
|
//! ```rust,ignore
|
|
#![doc = include_str!("../../../examples/runtime_apis_raw.rs")]
|
|
//! ```
|
|
//!
|