Skip to content

Commit

Permalink
use get_mempool_entry instead of is_in_mempool
Browse files Browse the repository at this point in the history
  • Loading branch information
jp1ac4 committed Nov 17, 2023
1 parent ef87631 commit 90c8a76
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
21 changes: 4 additions & 17 deletions src/bitcoin/d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,10 @@ impl BitcoinD {
.get("walletconflicts")
.and_then(Json::as_array)
.expect("A valid list of wallet conflicts must always be present.");
if confs == 0 && !conflicts.is_empty() && !self.is_in_mempool(&spending_txid) {
if confs == 0
&& !conflicts.is_empty()
&& self.get_mempool_entry(&spending_txid).is_none()
{
log::debug!("Noticed '{}' as spending '{}', but is unconfirmed with conflicts and is not in mempool anymore. Discarding it.", &spending_txid, &spent_outpoint);
break;
}
Expand Down Expand Up @@ -1118,22 +1121,6 @@ impl BitcoinD {
)
}

/// Whether this transaction is in the mempool.
pub fn is_in_mempool(&self, txid: &bitcoin::Txid) -> bool {
match self
.make_fallible_node_request("getmempoolentry", &params!(Json::String(txid.to_string())))
{
Ok(_) => true,
Err(BitcoindError::Server(jsonrpc::Error::Rpc(jsonrpc::error::RpcError {
code: -5,
..
}))) => false,
Err(e) => {
panic!("Unexpected error returned by bitcoind {}", e);
}
}
}

/// Get mempool entry.
/// Returns `None` if the transaction is not in the mempool.
pub fn get_mempool_entry(&self, txid: &bitcoin::Txid) -> Option<GetMempoolEntryRes> {
Expand Down
2 changes: 1 addition & 1 deletion src/bitcoin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl BitcoinInterface for d::BitcoinD {
}

// If the transaction was dropped from the mempool, discard the coin.
if !self.is_in_mempool(&op.txid) {
if self.get_mempool_entry(&op.txid).is_none() {
expired.push(*op);
}
}
Expand Down

0 comments on commit 90c8a76

Please sign in to comment.