pub struct Client { /* private fields */ }
Expand description
Blockchain database client backed by a persistent database. Owns and manages a blockchain and a block queue.
Call import_block()
to import a block asynchronously; flush_queue()
flushes the queue.
Implementations
sourceimpl Client
impl Client
sourcepub fn new(
config: ClientConfig,
spec: &Spec,
db: Arc<dyn BlockChainDB>,
miner: Arc<Miner>,
message_channel: IoChannel<ClientIoMessage>
) -> Result<Arc<Client>, Error>
pub fn new(
config: ClientConfig,
spec: &Spec,
db: Arc<dyn BlockChainDB>,
miner: Arc<Miner>,
message_channel: IoChannel<ClientIoMessage>
) -> Result<Arc<Client>, Error>
Create a new client with given parameters. The database is assumed to have been initialized with the correct columns.
sourcepub fn keep_alive(&self)
pub fn keep_alive(&self)
Wakes up client if it’s a sleep.
sourcepub fn add_notify(&self, target: Arc<dyn ChainNotify>)
pub fn add_notify(&self, target: Arc<dyn ChainNotify>)
Adds an actor to be notified on certain events
sourcepub fn on_user_defaults_change<F>(&self, f: F) where
F: 'static + FnMut(Option<Mode>) + Send,
pub fn on_user_defaults_change<F>(&self, f: F) where
F: 'static + FnMut(Option<Mode>) + Send,
Register an action to be done if a mode/spec_name change happens.
sourcepub fn flush_queue(&self)
pub fn flush_queue(&self)
Flush the block import queue.
sourcepub fn latest_env_info(&self) -> EnvInfo
pub fn latest_env_info(&self) -> EnvInfo
The env info as of the best block.
sourcepub fn env_info(&self, id: BlockId) -> Option<EnvInfo>
pub fn env_info(&self, id: BlockId) -> Option<EnvInfo>
The env info as of a given block.
returns None
if the block unknown.
sourcepub fn import_verified_blocks(&self) -> usize
pub fn import_verified_blocks(&self) -> usize
This is triggered by a message coming from a block queue when the block is ready for insertion
sourcepub fn set_io_channel(&self, io_channel: IoChannel<ClientIoMessage>)
pub fn set_io_channel(&self, io_channel: IoChannel<ClientIoMessage>)
Replace io channel. Useful for testing.
sourcepub fn latest_state_and_header(&self) -> (State<StateDB>, Header)
pub fn latest_state_and_header(&self) -> (State<StateDB>, Header)
Get a copy of the best block’s state.
sourcepub fn state_at(&self, id: BlockId) -> Option<State<StateDB>>
pub fn state_at(&self, id: BlockId) -> Option<State<StateDB>>
Attempt to get a copy of a specific block’s final state.
This will not fail if given BlockId::Latest. Otherwise, this can fail (but may not) if the DB prunes state or the block is unknown.
sourcepub fn state_at_beginning(&self, id: BlockId) -> Option<State<StateDB>>
pub fn state_at_beginning(&self, id: BlockId) -> Option<State<StateDB>>
Attempt to get a copy of a specific block’s beginning state.
This will not fail if given BlockId::Latest. Otherwise, this can fail (but may not) if the DB prunes state.
sourcepub fn blockchain_cache_info(&self) -> BlockChainCacheSize
pub fn blockchain_cache_info(&self) -> BlockChainCacheSize
Get info on the cache.
sourcepub fn report(&self) -> ClientReport
pub fn report(&self) -> ClientReport
Get the report.
sourcepub fn take_snapshot<W: SnapshotWriter + Send>(
&self,
writer: W,
at: BlockId,
p: &Progress
) -> Result<(), EthcoreError>
pub fn take_snapshot<W: SnapshotWriter + Send>(
&self,
writer: W,
at: BlockId,
p: &Progress
) -> Result<(), EthcoreError>
Take a snapshot at the given block. If the ID given is “latest”, this will default to 1000 blocks behind.
sourcepub fn pruning_history(&self) -> u64
pub fn pruning_history(&self) -> u64
Ask the client what the history parameter is.
Trait Implementations
sourceimpl BlockChainClient for Client
impl BlockChainClient for Client
sourcefn replay(
&self,
id: TransactionId,
analytics: CallAnalytics
) -> Result<Executed, CallError>
fn replay(
&self,
id: TransactionId,
analytics: CallAnalytics
) -> Result<Executed, CallError>
Replays a given transaction for inspection.
sourcefn replay_block_transactions(
&self,
block: BlockId,
analytics: CallAnalytics
) -> Result<Box<dyn Iterator<Item = (H256, Executed)>>, CallError>
fn replay_block_transactions(
&self,
block: BlockId,
analytics: CallAnalytics
) -> Result<Box<dyn Iterator<Item = (H256, Executed)>>, CallError>
Replays all the transactions in a given block for inspection.
sourcefn disable(&self)
fn disable(&self)
Disable the client from importing blocks. This cannot be undone in this session and indicates that a subsystem has reason to believe this executable incapable of syncing the chain. Read more
sourcefn is_canon(&self, hash: &H256) -> bool
fn is_canon(&self, hash: &H256) -> bool
Returns true if the given block is known and in the canon chain.
sourcefn set_spec_name(&self, new_spec_name: String) -> Result<(), ()>
fn set_spec_name(&self, new_spec_name: String) -> Result<(), ()>
Set the chain via a spec name.
sourcefn block_number(&self, id: BlockId) -> Option<BlockNumber>
fn block_number(&self, id: BlockId) -> Option<BlockNumber>
Look up the block number for the given block ID.
sourcefn block_body(&self, id: BlockId) -> Option<Body>
fn block_body(&self, id: BlockId) -> Option<Body>
Get raw block body data by block id. Block body is an RLP list of two items: uncles and transactions. Read more
sourcefn block_status(&self, id: BlockId) -> BlockStatus
fn block_status(&self, id: BlockId) -> BlockStatus
Get block status by block header hash.
sourcefn is_processing_fork(&self) -> bool
fn is_processing_fork(&self) -> bool
Returns true, if underlying import queue is processing possible fork at the moment
sourcefn block_total_difficulty(&self, id: BlockId) -> Option<U256>
fn block_total_difficulty(&self, id: BlockId) -> Option<U256>
Get block total difficulty.
sourcefn storage_root(&self, address: &Address, id: BlockId) -> Option<H256>
fn storage_root(&self, address: &Address, id: BlockId) -> Option<H256>
Attempt to get address storage root at given block. May not fail on BlockId::Latest. Read more
sourcefn block_hash(&self, id: BlockId) -> Option<H256>
fn block_hash(&self, id: BlockId) -> Option<H256>
Get block hash.
sourcefn code(&self, address: &Address, state: StateOrBlock) -> Option<Option<Bytes>>
fn code(&self, address: &Address, state: StateOrBlock) -> Option<Option<Bytes>>
Get address code at given block’s state.
sourcefn storage_at(
&self,
address: &Address,
position: &H256,
state: StateOrBlock
) -> Option<H256>
fn storage_at(
&self,
address: &Address,
position: &H256,
state: StateOrBlock
) -> Option<H256>
Get address code hash at given block’s state. Get value of the storage at given position at the given block’s state. Read more
sourcefn list_accounts(
&self,
id: BlockId,
after: Option<&Address>,
count: u64
) -> Option<Vec<Address>>
fn list_accounts(
&self,
id: BlockId,
after: Option<&Address>,
count: u64
) -> Option<Vec<Address>>
Get a list of all accounts in the block id
, if fat DB is in operation, otherwise None
.
If after
is set the list starts with the following item. Read more
sourcefn list_storage(
&self,
id: BlockId,
account: &Address,
after: Option<&H256>,
count: u64
) -> Option<Vec<H256>>
fn list_storage(
&self,
id: BlockId,
account: &Address,
after: Option<&H256>,
count: u64
) -> Option<Vec<H256>>
Get a list of all storage keys in the block id
, if fat DB is in operation, otherwise None
.
If after
is set the list starts with the following item. Read more
sourcefn block_transaction(&self, id: TransactionId) -> Option<LocalizedTransaction>
fn block_transaction(&self, id: TransactionId) -> Option<LocalizedTransaction>
Get transaction with given hash.
sourcefn queued_transaction(&self, hash: H256) -> Option<Arc<VerifiedTransaction>>
fn queued_transaction(&self, hash: H256) -> Option<Arc<VerifiedTransaction>>
Get pool transaction with a given hash.
sourcefn transaction_receipt(&self, id: TransactionId) -> Option<LocalizedReceipt>
fn transaction_receipt(&self, id: TransactionId) -> Option<LocalizedReceipt>
Get transaction receipt with given hash.
sourcefn localized_block_receipts(&self, id: BlockId) -> Option<Vec<LocalizedReceipt>>
fn localized_block_receipts(&self, id: BlockId) -> Option<Vec<LocalizedReceipt>>
Get localized receipts for all transaction in given block.
sourcefn tree_route(&self, from: &H256, to: &H256) -> Option<TreeRoute>
fn tree_route(&self, from: &H256, to: &H256) -> Option<TreeRoute>
Get a tree route between from
and to
.
See BlockChain::tree_route
. Read more
sourcefn find_uncles(&self, hash: &H256) -> Option<Vec<H256>>
fn find_uncles(&self, hash: &H256) -> Option<Vec<H256>>
Get all possible uncle hashes for a block.
sourcefn block_receipts(&self, hash: &H256) -> Option<BlockReceipts>
fn block_receipts(&self, hash: &H256) -> Option<BlockReceipts>
Get block receipts data by block header hash.
sourcefn queue_info(&self) -> BlockQueueInfo
fn queue_info(&self) -> BlockQueueInfo
Get block queue information.
sourcefn is_queue_empty(&self) -> bool
fn is_queue_empty(&self) -> bool
Returns true if block queue is empty.
sourcefn clear_queue(&self)
fn clear_queue(&self)
Clear block queue and abort all import activity.
sourcefn additional_params(&self) -> BTreeMap<String, String>
fn additional_params(&self) -> BTreeMap<String, String>
Get the registrar address, if it exists.
sourcefn logs(&self, filter: Filter) -> Result<Vec<LocalizedLogEntry>, BlockId>
fn logs(&self, filter: Filter) -> Result<Vec<LocalizedLogEntry>, BlockId>
Returns logs matching given filter. If one of the filtering block cannot be found, returns the block id that caused the error.
sourcefn filter_traces(&self, filter: TraceFilter) -> Option<Vec<LocalizedTrace>>
fn filter_traces(&self, filter: TraceFilter) -> Option<Vec<LocalizedTrace>>
Returns traces matching given filter.
sourcefn trace(&self, trace: TraceId) -> Option<LocalizedTrace>
fn trace(&self, trace: TraceId) -> Option<LocalizedTrace>
Returns trace with given id.
sourcefn transaction_traces(
&self,
transaction: TransactionId
) -> Option<Vec<LocalizedTrace>>
fn transaction_traces(
&self,
transaction: TransactionId
) -> Option<Vec<LocalizedTrace>>
Returns traces created by transaction.
sourcefn block_traces(&self, block: BlockId) -> Option<Vec<LocalizedTrace>>
fn block_traces(&self, block: BlockId) -> Option<Vec<LocalizedTrace>>
Returns traces created by transaction from block.
sourcefn last_hashes(&self) -> LastHashes
fn last_hashes(&self) -> LastHashes
Get last hashes starting from best block.
sourcefn transactions_to_propagate(&self) -> Vec<Arc<VerifiedTransaction>>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
fn transactions_to_propagate(&self) -> Vec<Arc<VerifiedTransaction>>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
List all ready transactions that should be propagated to other peers.
sourcefn transaction(&self, tx_hash: &H256) -> Option<Arc<VerifiedTransaction>>
fn transaction(&self, tx_hash: &H256) -> Option<Arc<VerifiedTransaction>>
Get verified transaction with specified transaction hash.
sourcefn signing_chain_id(&self) -> Option<u64>
fn signing_chain_id(&self) -> Option<u64>
Get the preferred chain ID to sign on
sourcefn block_extra_info(&self, id: BlockId) -> Option<BTreeMap<String, String>>
fn block_extra_info(&self, id: BlockId) -> Option<BTreeMap<String, String>>
Returns engine-related extra info for BlockId
.
sourcefn uncle_extra_info(&self, id: UncleId) -> Option<BTreeMap<String, String>>
fn uncle_extra_info(&self, id: UncleId) -> Option<BTreeMap<String, String>>
Returns engine-related extra info for UncleId
.
sourcefn pruning_info(&self) -> PruningInfo
fn pruning_info(&self) -> PruningInfo
Returns information about pruning/data availability.
sourcefn create_transaction(
&self,
_: TransactionRequest
) -> Result<SignedTransaction, Error>
fn create_transaction(
&self,
_: TransactionRequest
) -> Result<SignedTransaction, Error>
Returns a transaction signed with the key configured in the engine signer.
sourcefn transact(&self, tx_request: TransactionRequest) -> Result<(), Error>
fn transact(&self, tx_request: TransactionRequest) -> Result<(), Error>
Schedule state-altering transaction to be executed on the next pending block with the given gas and nonce parameters. Read more
sourcefn registrar_address(&self) -> Option<Address>
fn registrar_address(&self) -> Option<Address>
Get the address of the registry itself.
sourcefn state_data(&self, hash: &H256) -> Option<Bytes>
fn state_data(&self, hash: &H256) -> Option<Bytes>
Get latest state node
sourcefn latest_code(&self, address: &Address) -> Option<Bytes>
fn latest_code(&self, address: &Address) -> Option<Bytes>
Get address code at the latest block’s state.
sourcefn latest_storage_at(&self, address: &Address, position: &H256) -> H256
fn latest_storage_at(&self, address: &Address, position: &H256) -> H256
Get value of the storage at given position at the latest block’s state.
sourcefn gas_price_corpus(&self, sample_size: usize) -> Corpus<U256>
fn gas_price_corpus(&self, sample_size: usize) -> Corpus<U256>
Sorted list of transaction gas prices from at least last sample_size blocks.
sourcefn priority_gas_price_corpus(
&self,
sample_size: usize,
eip1559_transition: BlockNumber
) -> Corpus<U256>
fn priority_gas_price_corpus(
&self,
sample_size: usize,
eip1559_transition: BlockNumber
) -> Corpus<U256>
Sorted list of transaction priority gas prices from at least last sample_size blocks.
sourceimpl BlockChainReset for Client
impl BlockChainReset for Client
sourceimpl BlockInfo for Client
impl BlockInfo for Client
sourcefn block_header(&self, id: BlockId) -> Option<Header>
fn block_header(&self, id: BlockId) -> Option<Header>
Get raw block header data by block id.
sourcefn best_block_header(&self) -> Header
fn best_block_header(&self) -> Header
Get the best block header.
sourceimpl BroadcastProposalBlock for Client
impl BroadcastProposalBlock for Client
sourcefn broadcast_proposal_block(&self, block: SealedBlock)
fn broadcast_proposal_block(&self, block: SealedBlock)
Broadcast a block proposal.
sourceimpl Call for Client
impl Call for Client
sourcefn call(
&self,
transaction: &SignedTransaction,
analytics: CallAnalytics,
state: &mut Self::State,
header: &Header
) -> Result<Executed, CallError>
fn call(
&self,
transaction: &SignedTransaction,
analytics: CallAnalytics,
state: &mut Self::State,
header: &Header
) -> Result<Executed, CallError>
Makes a non-persistent transaction call.
sourcefn call_many(
&self,
transactions: &[(SignedTransaction, CallAnalytics)],
state: &mut Self::State,
header: &Header
) -> Result<Vec<Executed>, CallError>
fn call_many(
&self,
transactions: &[(SignedTransaction, CallAnalytics)],
state: &mut Self::State,
header: &Header
) -> Result<Vec<Executed>, CallError>
Makes multiple non-persistent but dependent transaction calls. Returns a vector of successes or a failure if any of the transaction fails. Read more
sourcefn estimate_gas(
&self,
t: &SignedTransaction,
state: &Self::State,
header: &Header
) -> Result<U256, CallError>
fn estimate_gas(
&self,
t: &SignedTransaction,
state: &Self::State,
header: &Header
) -> Result<U256, CallError>
Estimates how much gas will be necessary for a call.
sourceimpl CallContract for Client
impl CallContract for Client
sourceimpl ChainInfo for Client
impl ChainInfo for Client
sourcefn chain_info(&self) -> BlockChainInfo
fn chain_info(&self) -> BlockChainInfo
Get blockchain information.
sourceimpl DatabaseRestore for Client
impl DatabaseRestore for Client
sourcefn restore_db(&self, new_db: &str) -> Result<(), EthcoreError>
fn restore_db(&self, new_db: &str) -> Result<(), EthcoreError>
Restart the client with a new backend
sourceimpl EngineClient for Client
impl EngineClient for Client
sourcefn update_sealing(&self, force: ForceUpdateSealing)
fn update_sealing(&self, force: ForceUpdateSealing)
Make a new block and seal it.
sourcefn submit_seal(&self, block_hash: H256, seal: Vec<Bytes>)
fn submit_seal(&self, block_hash: H256, seal: Vec<Bytes>)
Submit a seal for a block in the mining queue.
sourcefn broadcast_consensus_message(&self, message: Bytes)
fn broadcast_consensus_message(&self, message: Bytes)
Broadcast a consensus message to the network.
sourcefn epoch_transition_for(&self, parent_hash: H256) -> Option<EpochTransition>
fn epoch_transition_for(&self, parent_hash: H256) -> Option<EpochTransition>
Get the transition to the epoch the given parent hash is part of or transitions to. This will give the epoch that any children of this parent belong to. Read more
sourcefn as_full_client(&self) -> Option<&dyn BlockChainClient>
fn as_full_client(&self) -> Option<&dyn BlockChainClient>
Attempt to cast the engine client to a full client.
sourcefn block_number(&self, id: BlockId) -> Option<BlockNumber>
fn block_number(&self, id: BlockId) -> Option<BlockNumber>
Get a block number by ID.
sourcefn block_header(&self, id: BlockId) -> Option<Header>
fn block_header(&self, id: BlockId) -> Option<Header>
Get raw block header data by block id.
sourceimpl EngineInfo for Client
impl EngineInfo for Client
sourceimpl ImportBlock for Client
impl ImportBlock for Client
sourcefn import_block(&self, unverified: Unverified) -> EthcoreResult<H256>
fn import_block(&self, unverified: Unverified) -> EthcoreResult<H256>
Import a block into the blockchain.
sourceimpl ImportExportBlocks for Client
impl ImportExportBlocks for Client
sourcefn export_blocks<'a>(
&self,
out: Box<dyn Write + 'a>,
from: BlockId,
to: BlockId,
format: Option<DataFormat>
) -> Result<(), String>
fn export_blocks<'a>(
&self,
out: Box<dyn Write + 'a>,
from: BlockId,
to: BlockId,
format: Option<DataFormat>
) -> Result<(), String>
Export blocks to destination, with the given from, to and format argument. destination could be a file or stdout. If the format is hex, each block is written on a new line. For binary exports, all block data is written to the same line. Read more
sourcefn import_blocks<'a>(
&self,
source: Box<dyn Read + 'a>,
format: Option<DataFormat>
) -> Result<(), String>
fn import_blocks<'a>(
&self,
source: Box<dyn Read + 'a>,
format: Option<DataFormat>
) -> Result<(), String>
Import blocks from destination, with the given format argument Source could be a file or stdout. For hex format imports, it attempts to read the blocks on a line by line basis. For binary format imports, reads the 8 byte RLP header in order to decode the block length to be read. Read more
sourceimpl ImportSealedBlock for Client
impl ImportSealedBlock for Client
sourcefn import_sealed_block(&self, block: SealedBlock) -> EthcoreResult<H256>
fn import_sealed_block(&self, block: SealedBlock) -> EthcoreResult<H256>
Import sealed block. Skips all verifications.
sourceimpl IoClient for Client
impl IoClient for Client
sourcefn queue_transactions(&self, transactions: Vec<Bytes>, peer_id: usize)
fn queue_transactions(&self, transactions: Vec<Bytes>, peer_id: usize)
Queue transactions for importing.
sourcefn queue_ancient_block(
&self,
unverified: Unverified,
receipts_bytes: Bytes
) -> EthcoreResult<H256>
fn queue_ancient_block(
&self,
unverified: Unverified,
receipts_bytes: Bytes
) -> EthcoreResult<H256>
Queue block import with transaction receipts. Does no sealing and transaction validation.
sourcefn ancient_block_queue_fullness(&self) -> f32
fn ancient_block_queue_fullness(&self) -> f32
Return percentage of how full is queue that handles ancient blocks. 0 if empty, 1 if full.
sourcefn queue_consensus_message(&self, message: Bytes)
fn queue_consensus_message(&self, message: Bytes)
Queue conensus engine message.
sourceimpl PrepareOpenBlock for Client
impl PrepareOpenBlock for Client
sourceimpl PrometheusMetrics for Client
impl PrometheusMetrics for Client
fn prometheus_metrics(&self, r: &mut PrometheusRegistry)
sourceimpl ProvingBlockChainClient for Client
impl ProvingBlockChainClient for Client
sourcefn prove_storage(
&self,
key1: H256,
key2: H256,
id: BlockId
) -> Option<(Vec<Bytes>, H256)>
fn prove_storage(
&self,
key1: H256,
key2: H256,
id: BlockId
) -> Option<(Vec<Bytes>, H256)>
Prove account storage at a specific block id. Read more
sourcefn prove_account(
&self,
key1: H256,
id: BlockId
) -> Option<(Vec<Bytes>, BasicAccount)>
fn prove_account(
&self,
key1: H256,
id: BlockId
) -> Option<(Vec<Bytes>, BasicAccount)>
Prove account existence at a specific block id. The key is the keccak hash of the account’s address. Returns a vector of raw trie nodes (in order from the root) proving the query. Read more
sourceimpl RegistryInfo for Client
impl RegistryInfo for Client
sourceimpl ReopenBlock for Client
impl ReopenBlock for Client
sourcefn reopen_block(&self, block: ClosedBlock) -> OpenBlock<'_>
fn reopen_block(&self, block: ClosedBlock) -> OpenBlock<'_>
Reopens an OpenBlock and updates uncles.
sourceimpl ScheduleInfo for Client
impl ScheduleInfo for Client
sourcefn latest_schedule(&self) -> Schedule
fn latest_schedule(&self) -> Schedule
Returns latest schedule.
sourceimpl StateClient for Client
impl StateClient for Client
sourceimpl TransactionInfo for Client
impl TransactionInfo for Client
sourcefn transaction_block(&self, id: TransactionId) -> Option<H256>
fn transaction_block(&self, id: TransactionId) -> Option<H256>
Get the hash of block that contains the transaction, if any.
impl AccountData for Client
impl BlockChain for Client
impl BlockChainClient for Client
impl BlockProducer for Client
impl SealedBlockImporter for Client
impl SnapshotClient for Client
impl TransactionVerifierClient for Client
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more