Remove unused lifetimes.
[rust-lightning] / lightning / src / chain / chaininterface.rs
index 32fef48eb44a54acaa7a576502ad1e0f1e56311d..4f5eeeac58772120382accdcd16def25a2d3bbd4 100644 (file)
@@ -50,6 +50,15 @@ pub trait ChainWatchInterface: Sync + Send {
        /// bytes are the block height, the next 3 the transaction index within the block, and the
        /// final two the output within the transaction.
        fn get_chain_utxo(&self, genesis_hash: Sha256dHash, unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError>;
+
+       /// Gets the list of transactions and transaction indices that the ChainWatchInterface is
+       /// watching for.
+       fn filter_block<'a>(&self, block: &'a Block) -> (Vec<&'a Transaction>, Vec<u32>);
+
+       /// Returns a usize that changes when the ChainWatchInterface's watched data is modified.
+       /// Users of `filter_block` should pre-save a copy of `reentered`'s return value and use it to
+       /// determine whether they need to re-filter a given block.
+       fn reentered(&self) -> usize;
 }
 
 /// An interface to send a transaction to the Bitcoin network.
@@ -106,6 +115,9 @@ pub trait FeeEstimator: Sync + Send {
        fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u64;
 }
 
+/// Minimum relay fee as required by bitcoin network mempool policy.
+pub const MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = 4000;
+
 /// Utility for tracking registered txn/outpoints and checking for matches
 pub struct ChainWatchedUtil {
        watch_all: bool,
@@ -195,14 +207,14 @@ impl ChainWatchedUtil {
 
 /// Utility for notifying listeners about new blocks, and handling block rescans if new watch
 /// data is registered.
-pub struct BlockNotifier<'a> {
-       listeners: Mutex<Vec<Weak<ChainListener + 'a>>>, //TODO(vmw): try removing Weak
+pub struct BlockNotifier {
+       listeners: Mutex<Vec<Weak<ChainListener>>>, //TODO(vmw): try removing Weak
        chain_monitor: Arc<ChainWatchInterface>,
 }
 
-impl<'a> BlockNotifier<'a> {
+impl BlockNotifier {
        /// Constructs a new BlockNotifier without any listeners.
-       pub fn new(chain_monitor: Arc<ChainWatchInterface>) -> BlockNotifier<'a> {
+       pub fn new(chain_monitor: Arc<ChainWatchInterface>) -> BlockNotifier {
                BlockNotifier {
                        listeners: Mutex::new(Vec::new()),
                        chain_monitor,
@@ -212,7 +224,7 @@ impl<'a> BlockNotifier<'a> {
        /// Register the given listener to receive events. Only a weak pointer is provided and
        /// the registration should be freed once that pointer expires.
        // TODO: unregister
-       pub fn register_listener(&self, listener: Weak<ChainListener + 'a>) {
+       pub fn register_listener(&self, listener: Weak<ChainListener>) {
                let mut vec = self.listeners.lock().unwrap();
                vec.push(listener);
        }
@@ -301,6 +313,25 @@ impl ChainWatchInterface for ChainWatchInterfaceUtil {
                }
                Err(ChainError::NotSupported)
        }
+
+       fn filter_block<'a>(&self, block: &'a Block) -> (Vec<&'a Transaction>, Vec<u32>) {
+               let mut matched = Vec::new();
+               let mut matched_index = Vec::new();
+               {
+                       let watched = self.watched.lock().unwrap();
+                       for (index, transaction) in block.txdata.iter().enumerate() {
+                               if self.does_match_tx_unguarded(transaction, &watched) {
+                                       matched.push(transaction);
+                                       matched_index.push(index as u32);
+                               }
+                       }
+               }
+               (matched, matched_index)
+       }
+
+       fn reentered(&self) -> usize {
+               self.reentered.load(Ordering::Relaxed)
+       }
 }
 
 impl ChainWatchInterfaceUtil {