X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fchain%2Fmod.rs;h=cec09459233daef7b9c38582e17f984d10fa0d6d;hb=d1e8d9ced595efe1dbcddde480fccc0d3f98184d;hp=856a9e8af62287b76f3e174f2543091361eca300;hpb=4363f965d6da2b5252b3e2fef09354b8970a9fe1;p=rust-lightning diff --git a/lightning/src/chain/mod.rs b/lightning/src/chain/mod.rs index 856a9e8a..cec09459 100644 --- a/lightning/src/chain/mod.rs +++ b/lightning/src/chain/mod.rs @@ -10,14 +10,18 @@ //! Structs and traits which allow other parts of rust-lightning to interact with the blockchain. use bitcoin::blockdata::block::{Block, BlockHeader}; +use bitcoin::blockdata::constants::genesis_block; use bitcoin::blockdata::script::Script; use bitcoin::blockdata::transaction::{Transaction, TxOut}; use bitcoin::hash_types::{BlockHash, Txid}; +use bitcoin::network::constants::Network; use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, MonitorEvent}; use chain::keysinterface::Sign; use chain::transaction::{OutPoint, TransactionData}; +use prelude::*; + pub mod chaininterface; pub mod chainmonitor; pub mod channelmonitor; @@ -26,6 +30,35 @@ pub mod keysinterface; pub(crate) mod onchaintx; pub(crate) mod package; +/// The best known block as identified by its hash and height. +#[derive(Clone, Copy, PartialEq)] +pub struct BestBlock { + block_hash: BlockHash, + height: u32, +} + +impl BestBlock { + /// Constructs a `BestBlock` that represents the genesis block at height 0 of the given + /// network. + pub fn from_genesis(network: Network) -> Self { + BestBlock { + block_hash: genesis_block(network).header.block_hash(), + height: 0, + } + } + + /// Returns a `BestBlock` as identified by the given block hash and height. + pub fn new(block_hash: BlockHash, height: u32) -> Self { + BestBlock { block_hash, height } + } + + /// Returns the best block hash. + pub fn block_hash(&self) -> BlockHash { self.block_hash } + + /// Returns the best block height. + pub fn height(&self) -> u32 { self.height } +} + /// An error when accessing the chain via [`Access`]. #[derive(Clone)] pub enum AccessError { @@ -237,6 +270,7 @@ pub trait Filter { /// /// [`ChannelMonitor`]: channelmonitor::ChannelMonitor /// [`ChannelMonitor::block_connected`]: channelmonitor::ChannelMonitor::block_connected +#[derive(Clone, PartialEq, Hash)] pub struct WatchedOutput { /// First block where the transaction output may have been spent. pub block_hash: Option,