[][src]Crate sc_client

Substrate Client and associated logic.

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

  • A database containing the blocks and chain state, generally referred to as the Backend.
  • A runtime environment, generally referred to as the Executor.

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 sc-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 sc_client::{Client, in_mem::Backend, LocalCallExecutor};
use sp_runtime::Storage;
use sc_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 substrate_test_runtime_client::{LocalExecutor, runtime::Block, runtime::RuntimeApi};

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

Re-exports

pub use sc_client_api::blockchain;
pub use crate::leaves::LeafSet;

Modules

cht

Canonical hash trie definitions and helper functions.

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.

utils

Utility methods for the client.

well_known_cache_keys

A list of all well known keys in the blockchain cache.

Structs

BlockImportNotification

Summary of an imported block

ChainInfo

Blockchain info

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

StateMachine

The substrate state machine.

StorageChangeSet

Storage change set

StorageProof

A proof that some set of key-value pairs are included in the storage trie. The proof contains the storage values so that the partial storage backend can be reconstructed by a verifier that does not already have access to the key-value pairs.

Enums

ExecutionStrategy

Strategy for executing a call into the runtime.

Traits

BlockBackend

Interface for fetching block data.

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.

LockImportRun

Interface for performing operations on the backend.

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

BadBlocks

Known bad block hashes.

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.