Crate sp_api[][src]

Substrate runtime api

The Substrate runtime api is the crucial interface between the node and the runtime. Every call that goes into the runtime is done with a runtime api. The runtime apis are not fixed. Every Substrate user can define its own apis with decl_runtime_apis and implement them in the runtime with impl_runtime_apis.

Every Substrate runtime needs to implement the Core runtime api. This api provides the basic functionality that every runtime needs to export.

Besides the macros and the Core runtime api, this crates provides the Metadata runtime api, the ApiExt trait, the CallApiAt trait and the ConstructRuntimeApi trait.

On a meta level this implies, the client calls the generated API from the client perspective.

Logging

Substrate supports logging from the runtime in native and in wasm. For that purpose it provides the RuntimeLogger. This runtime logger is automatically enabled for each call into the runtime through the runtime api. As logging introduces extra code that isn’t actually required for the logic of your runtime and also increases the final wasm blob size, it is recommended to disable the logging for on-chain wasm blobs. This can be done by enabling the disable-logging feature of this crate. Be aware that this feature instructs log and tracing to disable logging at compile time by setting the max_level_off feature for these crates. So, you should not enable this feature for a native build as otherwise the node will not output any log messages.

Macros

decl_runtime_apis

Declares given traits as runtime apis.

impl_runtime_apis

Tags given trait implementations as runtime apis.

mock_impl_runtime_apis

Mocks given trait implementations as runtime apis.

Structs

ApiRef

Auxiliary wrapper that holds an api instance and binds it to the given lifetime.

CallApiAtParams

Parameters for CallApiAt::call_api_at.

OldRuntimeVersion

Enums

ApiError

An error describing which API call failed.

InitializeBlock

Before calling any runtime api function, the runtime need to be initialized at the requested block. However, some functions like execute_block or initialize_block itself don’t require to have the runtime initialized at the requested block.

Constants

MAX_EXTRINSIC_DEPTH

Maximum nesting level for extrinsics.

Traits

ApiExt

Extends the runtime api implementation with some common functionality.

CallApiAt

Something that can call into the an api at a given block.

ConstructRuntimeApi

Something that can be constructed to a runtime api.

Core

The Core runtime api that every Substrate runtime needs to implement.

Metadata

The Metadata api trait that returns metadata for the runtime.

ProvideRuntimeApi

Something that provides a runtime api.

RuntimeApiInfo

Something that provides information about a runtime api.

Functions

init_runtime_logger

Init the RuntimeLogger.

Type Definitions

ProofRecorder

A type that records all accessed trie nodes and generates a proof out of it.

StateBackendFor

Extract the state backend type for a type that implements ProvideRuntimeApi.

StorageChanges
StorageTransactionCache

A type that is used as cache for the storage transactions.

TransactionFor

Extract the state backend transaction type for a type that implements ProvideRuntimeApi.