diff --git a/src/bitcoin/mod.rs b/src/bitcoin/mod.rs index e73a7eb97..18380b8a3 100644 --- a/src/bitcoin/mod.rs +++ b/src/bitcoin/mod.rs @@ -15,6 +15,9 @@ use std::{fmt, sync}; use miniscript::bitcoin::{self, address, bip32::ChildNumber}; +// A spent coin's outpoint together with its spend transaction's txid, height and time. +type SpentCoin = (bitcoin::OutPoint, bitcoin::Txid, i32, u32); + const COINBASE_MATURITY: i32 = 100; /// Information about a block @@ -93,10 +96,7 @@ pub trait BitcoinInterface: Send { fn spent_coins( &self, outpoints: &[(bitcoin::OutPoint, bitcoin::Txid)], - ) -> ( - Vec<(bitcoin::OutPoint, bitcoin::Txid, Block)>, - Vec, - ); + ) -> (Vec, Vec); /// Get the common ancestor between the Bitcoin backend's tip and the given tip. fn common_ancestor(&self, tip: &BlockChainTip) -> Option; @@ -279,10 +279,7 @@ impl BitcoinInterface for d::BitcoinD { fn spent_coins( &self, outpoints: &[(bitcoin::OutPoint, bitcoin::Txid)], - ) -> ( - Vec<(bitcoin::OutPoint, bitcoin::Txid, Block)>, - Vec, - ) { + ) -> (Vec, Vec) { // Spend coins to be returned. let mut spent = Vec::with_capacity(outpoints.len()); // Coins whose spending transaction isn't in our local mempool anymore. @@ -300,7 +297,7 @@ impl BitcoinInterface for d::BitcoinD { // If the transaction was confirmed, mark it as such. if let Some(block) = res.block { - spent.push((*op, *txid, block)); + spent.push((*op, *txid, block.height, block.time)); continue; } @@ -323,7 +320,7 @@ impl BitcoinInterface for d::BitcoinD { }) }); if let Some((txid, block)) = conflict { - spent.push((*op, txid, block)); + spent.push((*op, txid, block.height, block.time)); continue; } @@ -463,10 +460,7 @@ impl BitcoinInterface for sync::Arc> fn spent_coins( &self, outpoints: &[(bitcoin::OutPoint, bitcoin::Txid)], - ) -> ( - Vec<(bitcoin::OutPoint, bitcoin::Txid, Block)>, - Vec, - ) { + ) -> (Vec, Vec) { self.lock().unwrap().spent_coins(outpoints) } diff --git a/src/bitcoin/poller/looper.rs b/src/bitcoin/poller/looper.rs index 38dc006e2..076ddd7b8 100644 --- a/src/bitcoin/poller/looper.rs +++ b/src/bitcoin/poller/looper.rs @@ -149,10 +149,6 @@ fn update_coins( .chain(spending.iter().cloned()) .collect(); let (spent, expired_spending) = bit.spent_coins(spending_coins.as_slice()); - let spent = spent - .into_iter() - .map(|(oupoint, txid, block)| (oupoint, txid, block.height, block.time)) - .collect(); log::debug!("Newly spent coins: {:?}", spent); UpdatedCoins { diff --git a/src/testutils.rs b/src/testutils.rs index ad126d82b..3fb276ed5 100644 --- a/src/testutils.rs +++ b/src/testutils.rs @@ -95,7 +95,7 @@ impl BitcoinInterface for DummyBitcoind { &self, _: &[(bitcoin::OutPoint, bitcoin::Txid)], ) -> ( - Vec<(bitcoin::OutPoint, bitcoin::Txid, Block)>, + Vec<(bitcoin::OutPoint, bitcoin::Txid, i32, u32)>, Vec, ) { (Vec::new(), Vec::new())