pub struct CheckPoint(/* private fields */);
Expand description
A checkpoint is a node of a reference-counted linked list of BlockId
s.
Checkpoints are cheaply cloneable and are useful to find the agreement point between two sparse block chains.
Implementations§
Source§impl CheckPoint
impl CheckPoint
Sourcepub fn from_block_ids(
block_ids: impl IntoIterator<Item = BlockId>,
) -> Result<Self, Option<Self>>
pub fn from_block_ids( block_ids: impl IntoIterator<Item = BlockId>, ) -> Result<Self, Option<Self>>
Construct a checkpoint from a list of BlockId
s 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 beNone
. - The
blocks
iterator is not in ascending height order. - The
blocks
iterator contains multipleBlockId
s of the same height.
The error type is the last successful checkpoint constructed (if any).
Sourcepub fn from_header(header: &Header, height: u32) -> Self
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.
Sourcepub fn push(self, block: BlockId) -> Result<Self, Self>
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.
Sourcepub fn extend(
self,
blocks: impl IntoIterator<Item = BlockId>,
) -> Result<Self, Self>
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.
Sourcepub fn prev(&self) -> Option<CheckPoint>
pub fn prev(&self) -> Option<CheckPoint>
Get the previous checkpoint in the chain
Sourcepub fn iter(&self) -> CheckPointIter ⓘ
pub fn iter(&self) -> CheckPointIter ⓘ
Iterate from this checkpoint in descending height.
Sourcepub fn get(&self, height: u32) -> Option<Self>
pub fn get(&self, height: u32) -> Option<Self>
Get checkpoint at height
.
Returns None
if checkpoint at height
does not exist`.
Sourcepub fn range<R>(&self, range: R) -> impl Iterator<Item = CheckPoint>where
R: RangeBounds<u32>,
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).
Sourcepub fn insert(self, block_id: BlockId) -> Self
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 following 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
.
§Panics
This panics if called with a genesis block that differs from that of self
.
Trait Implementations§
Source§impl Clone for CheckPoint
impl Clone for CheckPoint
Source§fn clone(&self) -> CheckPoint
fn clone(&self) -> CheckPoint
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more