X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fchain%2Fchaininterface.rs;h=7e9e9aeff05b902923703846337cc5c9b9666edd;hb=b17211ffe42d029280fc45df42dd1d6152eadd13;hp=ef8f9bf15525cba26685cb2da7823cf4ccd58982;hpb=6185a2819090bd077954244c5e2adaab5efcaa1a;p=rust-lightning diff --git a/src/chain/chaininterface.rs b/src/chain/chaininterface.rs index ef8f9bf1..7e9e9aef 100644 --- a/src/chain/chaininterface.rs +++ b/src/chain/chaininterface.rs @@ -1,30 +1,36 @@ -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); + fn install_watch_script(&self, script_pub_key: &Script); /// 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. @@ -45,8 +51,18 @@ 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; + /// Gets estimated satoshis of fee required per 1000 Weight-Units. This translates to: + /// * satoshis-per-byte * 250 + /// * ceil(satoshis-per-kbyte / 4) + /// Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs + /// don't put us below 1 satoshi-per-byte). + fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u64; } /// Utility to capture some common parts of ChainWatchInterface implementors. @@ -54,59 +70,101 @@ pub trait FeeEstimator: Sync + Send { pub struct ChainWatchInterfaceUtil { watched: Mutex<(Vec