[][src]Crate substrate_client

Substrate Client and associated logic.

The Client is one of the most important components of Substrate. It mainly comprises two parts:

Initialization

Creating a Client is done by calling the new method and passing to it a Backend and an Executor.

The former is typically provided by the substrate-client-db crate.

The latter typically requires passing one of:

Additionally, the fourth generic parameter of the Client is a marker type representing the ways in which the runtime can interface with the outside. Any code that builds a Client is responsible for putting the right marker.

Example

use std::sync::Arc;
use substrate_client::{Client, in_mem::Backend, LocalCallExecutor};
use primitives::Blake2Hasher;
use sr_primitives::{StorageOverlay, ChildrenStorageOverlay};
use executor::{NativeExecutor, WasmExecutionMethod};

// In this example, we're using the `Block` and `RuntimeApi` types from the
// `substrate-test-runtime-client` crate. These types are automatically generated when
// compiling a runtime. In a typical use-case, these types would have been to be generated
// from your runtime.
use test_client::{LocalExecutor, runtime::Block, runtime::RuntimeApi};

let backend = Arc::new(Backend::<Block, Blake2Hasher>::new());
let client = Client::<_, _, _, RuntimeApi>::new(
	backend.clone(),
	LocalCallExecutor::new(
		backend.clone(),
		NativeExecutor::<LocalExecutor>::new(WasmExecutionMethod::Interpreted, None),
		None,
	),
	// This parameter provides the storage for the chain genesis.
	<(StorageOverlay, ChildrenStorageOverlay)>::default(),
	Default::default(),
	Default::default(),
);

Re-exports

pub use crate::blockchain::Info as ChainInfo;
pub use crate::leaves::LeafSet;
pub use crate::blockchain::well_known_cache_keys;

Modules

backend

Substrate Client data backend

block_builder

Utility struct to build a block.

blockchain

Substrate blockchain trait

children

Functionality for reading and storing children hashes from db.

cht

Canonical hash trie definitions and helper functions.

error

Substrate client possible errors.

genesis

Tool for creating the genesis block.

in_mem

In memory client backend

leaves

Helper for managing the set of available leaves in the chain for DB implementations.

light

Light client components.

runtime_api

All the functionality required for declaring and implementing runtime apis.

utils

Utility methods for the client.

Macros

decl_runtime_apis

Declares given traits as runtime apis.

impl_runtime_apis

Tags given trait implementations as runtime apis.

Structs

BlockImportNotification

Summary of an imported block

Client

Substrate Client

ClientInfo

Client info

ExecutionStrategies

Execution strategies settings.

FinalityNotification

Summary of a finalized block.

LocalCallExecutor

Call executor that executes methods locally, querying all required data from local backend.

LongestChain

Implement Longest Chain Select implementation where 'longest' is defined as the highest number of blocks

StorageChangeSet

Storage change set

Enums

ExecutionStrategy

Strategy for executing a call into the runtime.

Traits

BlockBody

Fetch block body by ID.

BlockOf

Figure out the block type for a given type (for now, just a Client).

BlockchainEvents

A source of blockchain events.

CallExecutor

Method call executor.

ProvideUncles

Provide a list of potential uncle headers for a given block.

Functions

apply_aux

Helper function to apply auxiliary data insertion into an operation.

new_in_mem

Create an instance of in-memory client.

new_with_backend

Create a client with the explicitly provided backend. This is useful for testing backend implementations.

Type Definitions

FinalityNotifications

A stream of block finality notifications.

ForkBlocks

Expected hashes of blocks at given heights.

ImportNotifications

Type that implements futures::Stream of block import events.

StorageEventStream

Type that implements futures::Stream of storage change events.