bitcoin: add mempool_entry to interface

This commit is contained in:
jp1ac4 2024-01-03 23:49:41 +00:00
parent edbf00f17c
commit 5f0022083d
No known key found for this signature in database
GPG Key ID: A7ACD32423568D7B
2 changed files with 17 additions and 0 deletions

View File

@ -116,6 +116,11 @@ pub trait BitcoinInterface: Send {
/// Get the details of unconfirmed transactions spending these outpoints, if any.
fn mempool_spenders(&self, outpoints: &[bitcoin::OutPoint]) -> Vec<MempoolEntry>;
/// Get mempool data for the given transaction.
///
/// Returns `None` if the transaction is not in the mempool.
fn mempool_entry(&self, txid: &bitcoin::Txid) -> Option<MempoolEntry>;
}
impl BitcoinInterface for d::BitcoinD {
@ -366,6 +371,10 @@ impl BitcoinInterface for d::BitcoinD {
.filter_map(|txid| self.mempool_entry(&txid))
.collect()
}
fn mempool_entry(&self, txid: &bitcoin::Txid) -> Option<MempoolEntry> {
self.mempool_entry(txid)
}
}
// FIXME: do we need to repeat the entire trait implemenation? Isn't there a nicer way?
@ -456,6 +465,10 @@ impl BitcoinInterface for sync::Arc<sync::Mutex<dyn BitcoinInterface + 'static>>
fn mempool_spenders(&self, outpoints: &[bitcoin::OutPoint]) -> Vec<MempoolEntry> {
self.lock().unwrap().mempool_spenders(outpoints)
}
fn mempool_entry(&self, txid: &bitcoin::Txid) -> Option<MempoolEntry> {
self.lock().unwrap().mempool_entry(txid)
}
}
// FIXME: We could avoid this type (and all the conversions entailing allocations) if bitcoind

View File

@ -123,6 +123,10 @@ impl BitcoinInterface for DummyBitcoind {
fn mempool_spenders(&self, _: &[bitcoin::OutPoint]) -> Vec<MempoolEntry> {
Vec::new()
}
fn mempool_entry(&self, _: &bitcoin::Txid) -> Option<MempoolEntry> {
None
}
}
struct DummyDbState {