Skip to content

Commit 10cc283

Browse files
Fix RPC Txid handling and mempool eviction
- Replace `bitcoin::consensus::encode::deserialize_hex()` with `hex_str.parse::<Txid>()` when parsing Txids from RPC, and `serialize_hex()` with `txid.to_string()` when sending to RPC, ensuring proper handling of Bitcoin Core's reversed-byte hexadecimal format. - Fix mempool eviction logic: transactions that are no longer in the mempool are now correctly removed from wallet consideration, preventing stale pending transactions from inflating unconfirmed balances.
1 parent 5d2092b commit 10cc283

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/chain/bitcoind.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ impl BitcoindClient {
754754
async fn get_raw_transaction_rpc(
755755
rpc_client: Arc<RpcClient>, txid: &Txid,
756756
) -> std::io::Result<Option<Transaction>> {
757-
let txid_hex = bitcoin::consensus::encode::serialize_hex(txid);
757+
let txid_hex = txid.to_string();
758758
let txid_json = serde_json::json!(txid_hex);
759759
match rpc_client
760760
.call_method::<GetRawTransactionResponse>("getrawtransaction", &[txid_json])
@@ -792,7 +792,7 @@ impl BitcoindClient {
792792
async fn get_raw_transaction_rest(
793793
rest_client: Arc<RestClient>, txid: &Txid,
794794
) -> std::io::Result<Option<Transaction>> {
795-
let txid_hex = bitcoin::consensus::encode::serialize_hex(txid);
795+
let txid_hex = txid.to_string();
796796
let tx_path = format!("tx/{}.json", txid_hex);
797797
match rest_client
798798
.request_resource::<JsonResponse, GetRawTransactionResponse>(&tx_path)
@@ -889,7 +889,7 @@ impl BitcoindClient {
889889
async fn get_mempool_entry_inner(
890890
client: Arc<RpcClient>, txid: Txid,
891891
) -> std::io::Result<Option<MempoolEntry>> {
892-
let txid_hex = bitcoin::consensus::encode::serialize_hex(&txid);
892+
let txid_hex = txid.to_string();
893893
let txid_json = serde_json::json!(txid_hex);
894894

895895
match client.call_method::<GetMempoolEntryResponse>("getmempoolentry", &[txid_json]).await {
@@ -1109,7 +1109,7 @@ impl BitcoindClient {
11091109
let mempool_entries_cache = mempool_entries_cache.lock().await;
11101110
let evicted_txids = unconfirmed_txids
11111111
.into_iter()
1112-
.filter(|txid| mempool_entries_cache.contains_key(txid))
1112+
.filter(|txid| !mempool_entries_cache.contains_key(txid))
11131113
.map(|txid| (txid, latest_mempool_timestamp))
11141114
.collect();
11151115
Ok(evicted_txids)
@@ -1236,7 +1236,7 @@ impl TryInto<GetRawMempoolResponse> for JsonResponse {
12361236

12371237
for hex in res {
12381238
let txid = if let Some(hex_str) = hex.as_str() {
1239-
match bitcoin::consensus::encode::deserialize_hex(hex_str) {
1239+
match hex_str.parse::<Txid>() {
12401240
Ok(txid) => txid,
12411241
Err(_) => {
12421242
return Err(std::io::Error::new(

0 commit comments

Comments
 (0)