X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fchain%2Fmod.rs;h=2e1eaea4e5f5b7d54c9828f4b6db769388f0ec89;hb=da298e498fc8bdf6af2b2becf82b0123118f46b4;hp=2d62016e9ec53e35b771efb5bdce8fde860941fe;hpb=58e4ce251e202cacadb82341ed16d299057fc646;p=rust-lightning diff --git a/lightning/src/chain/mod.rs b/lightning/src/chain/mod.rs index 2d62016e..2e1eaea4 100644 --- a/lightning/src/chain/mod.rs +++ b/lightning/src/chain/mod.rs @@ -10,19 +10,53 @@ //! 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; pub mod transaction; 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 { + /// Returns the best block from the genesis of the given network. + pub fn from_genesis(network: Network) -> Self { + BestBlock { + block_hash: genesis_block(network).header.block_hash(), + height: 0, + } + } + + /// Returns the best block 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)] @@ -235,6 +269,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, @@ -246,7 +281,7 @@ pub struct WatchedOutput { pub script_pubkey: Script, } -impl Listen for std::ops::Deref { +impl Listen for core::ops::Deref { fn block_connected(&self, block: &Block, height: u32) { (**self).block_connected(block, height); } @@ -256,7 +291,7 @@ impl Listen for std::ops::Deref { } } -impl Listen for (T, U) +impl Listen for (T, U) where T::Target: Listen, U::Target: Listen,