]> Untitled Git - bdk/commitdiff
fix(electrum): Fix `fetch_prev_txout`
authorvalued mammal <valuedmammal@protonmail.com>
Tue, 14 May 2024 14:43:19 +0000 (10:43 -0400)
committervalued mammal <valuedmammal@protonmail.com>
Tue, 14 May 2024 14:50:02 +0000 (10:50 -0400)
Previously we inserted every TxOut of a previous tx
at the same outpoint, which is incorrect because an outpoint
only points to a single TxOut. Now just get the TxOut
corresponding to the txin prevout and insert it with
its outpoint.

crates/electrum/src/electrum_ext.rs

index 1434469518270e5a5256ad32a2aeb887de6afe9b..d02a7dcec6ff5a24a47474c55ef9847d33d7dcce 100644 (file)
@@ -523,10 +523,10 @@ fn fetch_prev_txout<C: ElectrumApi>(
     for tx in full_txs {
         for vin in &tx.input {
             let outpoint = vin.previous_output;
+            let vout = outpoint.vout;
             let prev_tx = fetch_tx(client, tx_cache, outpoint.txid)?;
-            for txout in prev_tx.output.clone() {
-                let _ = graph_update.insert_txout(outpoint, txout);
-            }
+            let txout = prev_tx.output[vout as usize].clone();
+            let _ = graph_update.insert_txout(outpoint, txout);
         }
     }
     Ok(())