pub struct BlockLocator {
pub block_hash: BlockHash,
pub height: u32,
pub previous_blocks: [Option<BlockHash>; 12],
}Expand description
Identifies a position in the chain by its block hash and height, along with recent ancestor hashes used to locate the fork point of a reorg.
Fields§
§block_hash: BlockHashThe block’s hash.
height: u32The block’s height.
previous_blocks: [Option<BlockHash>; 12]Ancestor block hashes immediately before Self::block_hash, in reverse chronological
order.
These ensure we can find the fork point of a reorg if our block source no longer has the previous tip after a restart.
Implementations§
Source§impl BlockLocator
impl BlockLocator
Sourcepub fn from_network(network: Network) -> Self
pub fn from_network(network: Network) -> Self
Constructs a BlockLocator that represents the genesis block at height 0 of the given
network.
Sourcepub fn new(block_hash: BlockHash, height: u32) -> Self
pub fn new(block_hash: BlockHash, height: u32) -> Self
Returns a BlockLocator as identified by the given block hash and height.
This is not exported to bindings users directly as the bindings auto-generate an
equivalent new.
Sourcepub fn advance(&mut self, new_hash: BlockHash)
pub fn advance(&mut self, new_hash: BlockHash)
Advances to a new block at height Self::height + 1.
Sourcepub fn update_for_new_tip(
&mut self,
new_tip_hash: BlockHash,
new_tip_height: u32,
)
pub fn update_for_new_tip( &mut self, new_tip_hash: BlockHash, new_tip_height: u32, )
Updates this locator for a new chain tip, either delegating to Self::advance if the new
block is simply one higher than the current tip and wiping Self::previous_blocks if a
few blocks have been skipped.
Sourcepub fn get_hash_at_height(&self, height: u32) -> Option<BlockHash>
pub fn get_hash_at_height(&self, height: u32) -> Option<BlockHash>
Returns the block hash at the given height, if available in our history.
Sourcepub fn find_common_ancestor(
&self,
other: &BlockLocator,
) -> Option<(BlockHash, u32)>
pub fn find_common_ancestor( &self, other: &BlockLocator, ) -> Option<(BlockHash, u32)>
Finds the most recent common ancestor between two BlockLocators by searching their
ancestor hash histories.
Returns the common block hash and height, or None if no common block is found in the available histories.
Trait Implementations§
Source§impl Clone for BlockLocator
impl Clone for BlockLocator
Source§fn clone(&self) -> BlockLocator
fn clone(&self) -> BlockLocator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for BlockLocator
Source§impl Debug for BlockLocator
impl Debug for BlockLocator
impl Eq for BlockLocator
Source§impl Hash for BlockLocator
impl Hash for BlockLocator
Source§impl PartialEq for BlockLocator
impl PartialEq for BlockLocator
Source§impl Readable for BlockLocator
impl Readable for BlockLocator
impl StructuralPartialEq for BlockLocator
Source§impl Writeable for BlockLocator
impl Writeable for BlockLocator
Auto Trait Implementations§
impl Freeze for BlockLocator
impl RefUnwindSafe for BlockLocator
impl Send for BlockLocator
impl Sync for BlockLocator
impl Unpin for BlockLocator
impl UnsafeUnpin for BlockLocator
impl UnwindSafe for BlockLocator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> LengthReadable for Twhere
T: Readable,
impl<T> LengthReadable for Twhere
T: Readable,
Source§fn read_from_fixed_length_buffer<R>(reader: &mut R) -> Result<T, DecodeError>where
R: LengthLimitedRead,
fn read_from_fixed_length_buffer<R>(reader: &mut R) -> Result<T, DecodeError>where
R: LengthLimitedRead,
Self in from the given LengthLimitedRead.