X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fchain%2Fchaininterface.rs;h=f99f581f133a4fea18642c152444418d250a25f1;hb=68e6beab7cfb1be6f3d6d1356c7da90b0227849a;hp=ad298ce94db35eb4a29bec7c11fc884e6a8cf8af;hpb=4e05b107a3a42a770efb422b15f6cc4e49de2eac;p=rust-lightning diff --git a/src/chain/chaininterface.rs b/src/chain/chaininterface.rs index ad298ce9..f99f581f 100644 --- a/src/chain/chaininterface.rs +++ b/src/chain/chaininterface.rs @@ -1,9 +1,9 @@ -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. @@ -16,18 +16,21 @@ pub trait ChainWatchInterface: Sync + Send { /// Provides an outpoint which must be watched for, providing any transactions which spend the /// given outpoint. - fn install_watch_outpoint(&self, outpoint: (Sha256dHash, u32)); + fn install_watch_outpoint(&self, outpoint: (Sha256dHash, u32), out_script: &Script); /// 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. @@ -54,7 +57,7 @@ pub enum ConfirmationTarget { /// 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. @@ -62,59 +65,100 @@ pub trait FeeEstimator: Sync + Send { pub struct ChainWatchInterfaceUtil { watched: Mutex<(Vec