]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Calcualte fees in check_spends!() so taht callsites can use it
authorMatt Corallo <git@bluematt.me>
Mon, 2 Mar 2020 16:44:11 +0000 (11:44 -0500)
committerMatt Corallo <git@bluematt.me>
Mon, 10 Aug 2020 16:11:40 +0000 (12:11 -0400)
lightning/src/ln/functional_test_utils.rs

index 66bae1d41658075f5d12576f976f4f9a149fbea5..f0fcb96349a46d567f2e3e60d23e339e4bb099a4 100644 (file)
@@ -494,14 +494,26 @@ pub fn create_announced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &'a
 macro_rules! check_spends {
        ($tx: expr, $($spends_txn: expr),*) => {
                {
-                       $tx.verify(|out_point| {
+                       let get_output = |out_point: &bitcoin::blockdata::transaction::OutPoint| {
                                $(
                                        if out_point.txid == $spends_txn.txid() {
                                                return $spends_txn.output.get(out_point.vout as usize).cloned()
                                        }
                                )*
                                None
-                       }).unwrap();
+                       };
+                       let mut total_value_in = 0;
+                       for input in $tx.input.iter() {
+                               total_value_in += get_output(&input.previous_output).unwrap().value;
+                       }
+                       let mut total_value_out = 0;
+                       for output in $tx.output.iter() {
+                               total_value_out += output.value;
+                       }
+                       //TODO: let min_fee = $tx.get_weight() as u64 / 4; // One sat per vbyte
+                       //TODO: assert!(total_value_out + min_fee <= total_value_in);
+                       $tx.verify(get_output).unwrap();
+                       total_value_in - total_value_out
                }
        }
 }