Struct vapcore_blockchain::BlockChain[][src]

pub struct BlockChain { /* fields omitted */ }

Structure providing fast access to blockchain data.

Does not do input data verification.

Implementations

impl BlockChain[src]

pub fn new(
    config: Config,
    genesis: &[u8],
    db: Arc<dyn BlockChainDB>
) -> BlockChain
[src]

Create new instance of blockchain from given Genesis.

pub fn tree_route(&self, from: H256, to: H256) -> Option<TreeRoute>[src]

Returns a tree route between from and to, which is a tuple of:

  • a vector of hashes of all blocks, ordered from from to to.

  • common ancestor of these blocks.

  • an index where best common ancestor would be

1.) from newer to older

  • bc: A1 -> A2 -> A3 -> A4 -> A5

  • from: A5, to: A4

  • route:

    { blocks: [A5], ancestor: A4, index: 1 }
    

2.) from older to newer

  • bc: A1 -> A2 -> A3 -> A4 -> A5

  • from: A3, to: A4

  • route:

    { blocks: [A4], ancestor: A3, index: 0 }
    

3.) fork:

  • bc:

    A1 -> A2 -> A3 -> A4
               -> B3 -> B4
    
  • from: B4, to: A4

  • route:

    { blocks: [B4, B3, A3, A4], ancestor: A2, index: 2 }
    

If the tree route verges into pruned or unknown blocks, None is returned.

is_from_route_finalized returns whether the from part of the route contains a finalized block. This only holds if the two parts (from and to) are on different branches, ie. on 2 different forks.

pub fn insert_unordered_block(
    &self,
    batch: &mut DBTransaction,
    block: Block,
    receipts: Vec<Receipt>,
    parent_td: Option<U256>,
    is_best: bool,
    is_ancient: bool
) -> bool
[src]

Inserts a verified, known block from the canonical chain.

Can be performed out-of-order, but care must be taken that the final chain is in a correct state. This is used by snapshot restoration and when downloading missing blocks for the chain gap. is_best forces the best block to be updated to this block. is_ancient forces the best block of the first block sequence to be updated to this block. parent_td is a parent total diffuculty Supply a dummy parent total difficulty when the parent block may not be in the chain. Returns true if the block is disconnected.

pub fn clear_cache(&self)[src]

clears all caches, re-loads best block from disk for testing purposes

pub fn update_best_ancient_block(&self, hash: &H256)[src]

Update the best ancient block to the given hash, after checking that it’s directly linked to the currently known best ancient block

pub fn insert_epoch_transition(
    &self,
    batch: &mut DBTransaction,
    epoch_num: u64,
    transition: EpochTransition
)
[src]

Insert an epoch transition. Provide an epoch number being transitioned to and epoch transition object.

The block the transition occurred at should have already been inserted into the chain.

pub fn epoch_transitions(&self) -> EpochTransitionIter<'_>[src]

Iterate over all epoch transitions. This will only return transitions within the canonical chain.

pub fn epoch_transition(
    &self,
    block_num: u64,
    block_hash: H256
) -> Option<EpochTransition>
[src]

Get a specific epoch transition by block number and provided block hash.

pub fn epoch_transition_for(&self, parent_hash: H256) -> Option<EpochTransition>[src]

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.

The block corresponding the the parent hash must be stored already.

pub fn insert_pending_transition(
    &self,
    batch: &mut DBTransaction,
    hash: H256,
    t: PendingEpochTransition
)
[src]

Write a pending epoch transition by block hash.

pub fn get_pending_transition(
    &self,
    hash: H256
) -> Option<PendingEpochTransition>
[src]

Get a pending epoch transition by block hash.

pub fn add_child(
    &self,
    batch: &mut DBTransaction,
    block_hash: H256,
    child_hash: H256
)
[src]

Add a child to a given block. Assumes that the block hash is in the chain and the child’s parent is this block.

Used in snapshots to glue the chunks together at the end.

pub fn insert_block(
    &self,
    batch: &mut DBTransaction,
    block: Block,
    receipts: Vec<Receipt>,
    extras: ExtrasInsert
) -> ImportRoute
[src]

Inserts the block into backing cache database. Expects the block to be valid and already verified. If the block is already known, does nothing.

pub fn insert_block_with_route(
    &self,
    batch: &mut DBTransaction,
    block: Block,
    receipts: Vec<Receipt>,
    route: TreeRoute,
    extras: ExtrasInsert
) -> ImportRoute
[src]

Inserts the block into backing cache database with already generated route information. Expects the block to be valid and already verified and route is tree route information from current best block to new block’s parent. If the block is already known, does nothing.

pub fn mark_finalized(
    &self,
    batch: &mut DBTransaction,
    block_hash: H256
) -> Option<()>
[src]

Mark a block to be considered finalized. Returns Some(()) if the operation succeeds, and None if the block hash is not found.

pub fn commit(&self)[src]

Apply pending insertion updates

pub fn ancestry_iter(&self, first: H256) -> Option<AncestryIter<'_>>[src]

Iterator that lists first and then all of first’s ancestors, by hash.

pub fn ancestry_with_metadata_iter<'a>(
    &'a self,
    first: H256
) -> AncestryWithMetadataIter<'_>
[src]

Iterator that lists first and then all of first’s ancestors, by extended header.

pub fn find_uncle_headers(
    &self,
    parent: &H256,
    uncle_generations: u64
) -> Option<Vec<Header>>
[src]

Given a block’s parent, find every block header which represents a valid possible uncle.

pub fn find_uncle_hashes(
    &self,
    parent: &H256,
    uncle_generations: u64
) -> Option<Vec<H256>>
[src]

Given a block’s parent, find every block hash which represents a valid possible uncle.

pub fn best_block_hash(&self) -> H256[src]

Get best block hash.

pub fn best_block_number(&self) -> BlockNumber[src]

Get best block number.

pub fn best_block_timestamp(&self) -> u64[src]

Get best block timestamp.

pub fn best_block_total_difficulty(&self) -> U256[src]

Get best block total difficulty.

pub fn best_block_header(&self) -> Header[src]

Get best block header

pub fn cache_size(&self) -> CacheSize[src]

Get current cache size.

pub fn collect_garbage(&self)[src]

Ticks our cache system and throws out any old data.

pub fn block_to_body(block: &[u8]) -> Bytes[src]

Create a block body from a block.

pub fn chain_info(&self) -> BlockChainInfo[src]

Returns general blockchain information

Trait Implementations

impl BlockProvider for BlockChain[src]

fn is_known(&self, hash: &H256) -> bool[src]

Returns true if the given block is known (though not necessarily a part of the canon chain).

fn block(&self, hash: &H256) -> Option<Block>[src]

Get raw block data

fn block_header_data(&self, hash: &H256) -> Option<Header>[src]

Get block header data

fn block_body(&self, hash: &H256) -> Option<Body>[src]

Get block body data

fn block_details(&self, hash: &H256) -> Option<BlockDetails>[src]

Get the familial details concerning a block.

fn block_hash(&self, index: BlockNumber) -> Option<H256>[src]

Get the hash of given block’s number.

fn transaction_address(&self, hash: &H256) -> Option<TransactionAddress>[src]

Get the address of transaction with given hash.

fn block_receipts(&self, hash: &H256) -> Option<BlockReceipts>[src]

Get receipts of block with given hash.

fn blocks_with_bloom<'a, B, I, II>(
    &self,
    blooms: II,
    from_block: BlockNumber,
    to_block: BlockNumber
) -> Vec<BlockNumber> where
    BloomRef<'a>: From<B>,
    II: IntoIterator<Item = B, IntoIter = I> + Copy,
    I: Iterator<Item = B>, 
[src]

Returns numbers of blocks containing given bloom.

fn logs<F>(
    &self,
    blocks: Vec<H256>,
    matches: F,
    limit: Option<usize>
) -> Vec<LocalizedLogEntry> where
    F: Fn(&LogEntry) -> bool + Send + Sync,
    Self: Sized
[src]

Returns logs matching given filter. The order of logs returned will be the same as the order of the blocks provided. And it’s the callers responsibility to sort blocks provided in advance.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,