Update to rust-secp256k1 v0.11 and rust-bitcoin v0.14
[rust-lightning] / src / chain / chaininterface.rs
index 518b20b128c70a6143cdb15587b694fe2bd23585..bda99b2d83c2d47ecf95a274b9cdc412f47db705 100644 (file)
@@ -2,7 +2,8 @@ use bitcoin::blockdata::block::{Block, BlockHeader};
 use bitcoin::blockdata::transaction::Transaction;
 use bitcoin::blockdata::script::Script;
 use bitcoin::util::hash::Sha256dHash;
-use std::sync::{Mutex,Weak,MutexGuard};
+use util::logger::Logger;
+use std::sync::{Mutex,Weak,MutexGuard,Arc};
 use std::sync::atomic::{AtomicUsize, Ordering};
 
 /// An interface to request notification of certain scripts as they appear the
@@ -57,7 +58,12 @@ 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, confirmation_target: 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.
@@ -65,7 +71,8 @@ pub trait FeeEstimator: Sync + Send {
 pub struct ChainWatchInterfaceUtil {
        watched: Mutex<(Vec<Script>, Vec<(Sha256dHash, u32)>, bool)>, //TODO: Something clever to optimize this
        listeners: Mutex<Vec<Weak<ChainListener>>>,
-       reentered: AtomicUsize
+       reentered: AtomicUsize,
+       logger: Arc<Logger>,
 }
 
 /// Register listener
@@ -95,11 +102,12 @@ impl ChainWatchInterface for ChainWatchInterfaceUtil {
 }
 
 impl ChainWatchInterfaceUtil {
-       pub fn new() -> ChainWatchInterfaceUtil {
+       pub fn new(logger: Arc<Logger>) -> ChainWatchInterfaceUtil {
                ChainWatchInterfaceUtil {
                        watched: Mutex::new((Vec::new(), Vec::new(), false)),
                        listeners: Mutex::new(Vec::new()),
-                       reentered: AtomicUsize::new(1)
+                       reentered: AtomicUsize::new(1),
+                       logger: logger,
                }
        }
 
@@ -173,7 +181,7 @@ impl ChainWatchInterfaceUtil {
                for input in tx.input.iter() {
                        for outpoint in watched.1.iter() {
                                let &(outpoint_hash, outpoint_index) = outpoint;
-                               if outpoint_hash == input.prev_hash && outpoint_index == input.prev_index {
+                               if outpoint_hash == input.previous_output.txid && outpoint_index == input.previous_output.vout {
                                        return true;
                                }
                        }