Struct bdk_chain::local_chain::CheckPoint

source ·
pub struct CheckPoint(/* private fields */);
Expand description

A LocalChain checkpoint is used to find the agreement point between two chains and as a transaction anchor.

Each checkpoint contains the height and hash of a block (BlockId).

Internally, checkpoints are nodes of a reference-counted linked-list. This allows the caller to cheaply clone a CheckPoint without copying the whole list and to view the entire chain without holding a lock on LocalChain.

Implementations§

source§

impl CheckPoint

source

pub fn new(block: BlockId) -> Self

Construct a new base block at the front of a linked list.

source

pub fn from_block_ids( block_ids: impl IntoIterator<Item = BlockId> ) -> Result<Self, Option<Self>>

Construct a checkpoint from a list of BlockIds in ascending height order.

§Errors

This method will error if any of the follow occurs:

  • The blocks iterator is empty, in which case, the error will be None.
  • The blocks iterator is not in ascending height order.
  • The blocks iterator contains multiple BlockIds of the same height.

The error type is the last successful checkpoint constructed (if any).

source

pub fn from_header(header: &Header, height: u32) -> Self

Construct a checkpoint from the given header and block height.

If header is of the genesis block, the checkpoint won’t have a prev node. Otherwise, we return a checkpoint linked with the previous block.

source

pub fn push(self, block: BlockId) -> Result<Self, Self>

Puts another checkpoint onto the linked list representing the blockchain.

Returns an Err(self) if the block you are pushing on is not at a greater height that the one you are pushing on to.

source

pub fn extend( self, blocks: impl IntoIterator<Item = BlockId> ) -> Result<Self, Self>

Extends the checkpoint linked list by a iterator of block ids.

Returns an Err(self) if there is block which does not have a greater height than the previous one.

source

pub fn block_id(&self) -> BlockId

Get the BlockId of the checkpoint.

source

pub fn height(&self) -> u32

Get the height of the checkpoint.

source

pub fn hash(&self) -> BlockHash

Get the block hash of the checkpoint.

source

pub fn prev(&self) -> Option<CheckPoint>

Get the previous checkpoint in the chain

source

pub fn iter(&self) -> CheckPointIter

Iterate from this checkpoint in descending height.

source

pub fn get(&self, height: u32) -> Option<Self>

Get checkpoint at height.

Returns None if checkpoint at height does not exist`.

source

pub fn range<R>(&self, range: R) -> impl Iterator<Item = CheckPoint>
where R: RangeBounds<u32>,

Iterate checkpoints over a height range.

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

source

pub fn insert(self, block_id: BlockId) -> Self

Inserts block_id at its height within the chain.

The effect of insert depends on whether a height already exists. If it doesn’t the block_id we inserted and all pre-existing blocks higher than it will be re-inserted after it. If the height already existed and has a conflicting block hash then it will be purged along with all block followin it. The returned chain will have a tip of the block_id passed in. Of course, if the block_id was already present then this just returns self.

Trait Implementations§

source§

impl Clone for CheckPoint

source§

fn clone(&self) -> CheckPoint

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for CheckPoint

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl IntoIterator for CheckPoint

§

type Item = CheckPoint

The type of the elements being iterated over.
§

type IntoIter = CheckPointIter

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq for CheckPoint

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V