pub struct LocalChain { /* private fields */ }
Expand description

This is a local implementation of ChainOracle.

Implementations§

Get the genesis hash.

Construct LocalChain from genesis hash.

Construct a LocalChain from an initial changeset.

Construct a LocalChain from a given checkpoint tip.

Constructs a LocalChain from a BTreeMap of height to [BlockHash].

The BTreeMap enforces the height order. However, the caller must ensure the blocks are all of the same chain.

Get the highest checkpoint.

Applies the given update to the chain.

The method returns ChangeSet on success. This represents the changes applied to self.

There must be no ambiguity about which of the existing chain’s blocks are still valid and which are now invalid. That is, the new chain must implicitly connect to a definite block in the existing chain and invalidate the block after it (if it exists) by including a block at the same height but with a different hash to explicitly exclude it as a connection point.

Errors

An error will occur if the update does not correctly connect with self.

Update the chain with a given [Header] at height which you claim is connected to a existing block in the chain.

This is useful when you have a block header that you want to record as part of the chain but don’t necessarily know that the prev_blockhash is in the chain.

This will usually insert two new BlockIds into the chain: the header’s block and the header’s prev_blockhash block. connected_to must already be in the chain but is allowed to be prev_blockhash (in which case only one new block id will be inserted). To be successful, connected_to must be chosen carefully so that LocalChain’s update rules are satisfied.

Errors

ApplyHeaderError::InconsistentBlocks occurs if the connected_to block and the [Header] is inconsistent. For example, if the connected_to block is the same height as header or prev_blockhash, but has a different block hash. Or if the connected_to height is greater than the header’s height.

ApplyHeaderError::CannotConnect occurs if the internal call to apply_update fails.

Update the chain with a given [Header] connecting it with the previous block.

This is a convenience method to call apply_header_connected_to with the connected_to parameter being height-1:prev_blockhash. If there is no previous block (i.e. genesis), we use the current block as connected_to.

Apply the given changeset.

Insert a BlockId.

Errors

Replacing the block hash of an existing checkpoint will result in an error.

Removes blocks from (and inclusive of) the given block_id.

This will remove blocks with a height equal or greater than block_id, but only if block_id exists in the chain.

Errors

This will fail with MissingGenesisError if the caller attempts to disconnect from the genesis block.

Derives an initial ChangeSet, meaning that it can be applied to an empty chain to recover the current chain.

Iterate over checkpoints in descending height order.

Get checkpoint at given height (if it exists).

This is a shorthand for calling CheckPoint::get on the tip.

Iterate checkpoints over a height range.

Note that we always iterate checkpoints in reverse height order (iteration starts at tip height).

This is a shorthand for calling CheckPoint::range on the tip.

Trait Implementations§

Error type.
Determines whether block of BlockId exists as an ancestor of chain_tip. Read more
Get the best chain’s chain tip.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.