bitcoin: return spent block height & time separately
This commit is contained in:
parent
689442c2c9
commit
5011ad9290
@ -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
|
||||
@ -95,10 +98,7 @@ pub trait BitcoinInterface: Send {
|
||||
fn spent_coins(
|
||||
&self,
|
||||
outpoints: &[(bitcoin::OutPoint, bitcoin::Txid)],
|
||||
) -> (
|
||||
Vec<(bitcoin::OutPoint, bitcoin::Txid, Block)>,
|
||||
Vec<bitcoin::OutPoint>,
|
||||
);
|
||||
) -> (Vec<SpentCoin>, Vec<bitcoin::OutPoint>);
|
||||
|
||||
/// Get the common ancestor between the Bitcoin backend's tip and the given tip.
|
||||
fn common_ancestor(&self, tip: &BlockChainTip) -> Option<BlockChainTip>;
|
||||
@ -281,10 +281,7 @@ impl BitcoinInterface for d::BitcoinD {
|
||||
fn spent_coins(
|
||||
&self,
|
||||
outpoints: &[(bitcoin::OutPoint, bitcoin::Txid)],
|
||||
) -> (
|
||||
Vec<(bitcoin::OutPoint, bitcoin::Txid, Block)>,
|
||||
Vec<bitcoin::OutPoint>,
|
||||
) {
|
||||
) -> (Vec<SpentCoin>, Vec<bitcoin::OutPoint>) {
|
||||
// Spend coins to be returned.
|
||||
let mut spent = Vec::with_capacity(outpoints.len());
|
||||
// Coins whose spending transaction isn't in our local mempool anymore.
|
||||
@ -302,7 +299,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;
|
||||
}
|
||||
|
||||
@ -325,7 +322,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;
|
||||
}
|
||||
|
||||
@ -465,10 +462,7 @@ impl BitcoinInterface for sync::Arc<sync::Mutex<dyn BitcoinInterface + 'static>>
|
||||
fn spent_coins(
|
||||
&self,
|
||||
outpoints: &[(bitcoin::OutPoint, bitcoin::Txid)],
|
||||
) -> (
|
||||
Vec<(bitcoin::OutPoint, bitcoin::Txid, Block)>,
|
||||
Vec<bitcoin::OutPoint>,
|
||||
) {
|
||||
) -> (Vec<SpentCoin>, Vec<bitcoin::OutPoint>) {
|
||||
self.lock().unwrap().spent_coins(outpoints)
|
||||
}
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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<bitcoin::OutPoint>,
|
||||
) {
|
||||
(Vec::new(), Vec::new())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user