use bitcoin::hash_types::BlockHash;
use bitcoin::network::constants::Network;
+use lightning::chain::BestBlock;
use std::ops::Deref;
}
/// A chain tip relative to another chain tip in terms of block hash and chainwork.
-#[derive(Clone, Debug, PartialEq)]
+#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ChainTip {
/// A chain tip with the same hash as another chain's tip.
Common,
}
/// A block header with validated proof of work and corresponding block hash.
-#[derive(Clone, Copy, Debug, PartialEq)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ValidatedBlockHeader {
pub(crate) block_hash: BlockHash,
inner: BlockHeaderData,
Ok(())
}
+
+ /// Returns the [`BestBlock`] corresponding to this validated block header, which can be passed
+ /// into [`ChannelManager::new`] as part of its [`ChainParameters`]. Useful for ensuring that
+ /// the [`SpvClient`] and [`ChannelManager`] are initialized to the same block during a fresh
+ /// start.
+ ///
+ /// [`SpvClient`]: crate::SpvClient
+ /// [`ChainParameters`]: lightning::ln::channelmanager::ChainParameters
+ /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
+ /// [`ChannelManager::new`]: lightning::ln::channelmanager::ChannelManager::new
+ pub fn to_best_block(&self) -> BestBlock {
+ BestBlock::new(self.block_hash, self.inner.height)
+ }
}
/// A block with validated data against its transaction list and corresponding block hash.