X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fchain%2Fchaininterface.rs;h=8fef60b3b2c11d574691f31211c73478d8388a6e;hb=bab89ae5c01d0e186f2989210970bb12a0c8c291;hp=ef8f9bf15525cba26685cb2da7823cf4ccd58982;hpb=6185a2819090bd077954244c5e2adaab5efcaa1a;p=rust-lightning diff --git a/src/chain/chaininterface.rs b/src/chain/chaininterface.rs index ef8f9bf1..8fef60b3 100644 --- a/src/chain/chaininterface.rs +++ b/src/chain/chaininterface.rs @@ -1,12 +1,15 @@ -use bitcoin::blockdata::block::BlockHeader; +use bitcoin::blockdata::block::{Block, BlockHeader}; use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::script::Script; use bitcoin::util::hash::Sha256dHash; - -use std::sync::{Weak,Mutex}; +use std::sync::{Mutex,Weak,MutexGuard}; +use std::sync::atomic::{AtomicUsize, Ordering}; /// An interface to request notification of certain scripts as they appear the /// chain. +/// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're +/// called from inside the library in response to ChainListener events, P2P events, or timer +/// events). pub trait ChainWatchInterface: Sync + Send { /// Provides a scriptPubKey which much be watched for. fn install_watch_script(&self, script_pub_key: Script); @@ -18,13 +21,16 @@ pub trait ChainWatchInterface: Sync + Send { /// Indicates that a listener needs to see all transactions. fn watch_all_txn(&self); - /// Sends a transaction out to (hopefully) be mined - fn broadcast_transaction(&self, tx: &Transaction); - fn register_listener(&self, listener: Weak); //TODO: unregister } +/// An interface to send a transaction to the Bitcoin network. +pub trait BroadcasterInterface: Sync + Send { + /// Sends a transaction out to (hopefully) be mined. + fn broadcast_transaction(&self, tx: &Transaction); +} + /// A trait indicating a desire to listen for events from the chain pub trait ChainListener: Sync + Send { /// Notifies a listener that a block was connected. @@ -45,8 +51,13 @@ pub enum ConfirmationTarget { HighPriority, } +/// A trait which should be implemented to provide feerate information on a number of time +/// horizons. +/// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're +/// called from inside the library in response to ChainListener events, P2P events, or timer +/// events). pub trait FeeEstimator: Sync + Send { - fn get_est_sat_per_vbyte(&self, ConfirmationTarget) -> u64; + fn get_est_sat_per_vbyte(&self, confirmation_target: ConfirmationTarget) -> u64; } /// Utility to capture some common parts of ChainWatchInterface implementors. @@ -54,59 +65,100 @@ pub trait FeeEstimator: Sync + Send { pub struct ChainWatchInterfaceUtil { watched: Mutex<(Vec