]> Untitled Git - bdk/commitdiff
chore: make TxCache.save_txs can order independent
authorbodymindarts <justin@galoy.io>
Wed, 30 Nov 2022 14:17:49 +0000 (15:17 +0100)
committerSteve Myers <steve@notmandatory.org>
Fri, 16 Dec 2022 21:09:44 +0000 (15:09 -0600)
src/blockchain/electrum.rs

index 54381241ad2ec91ba3fe851458b2a4673db3bf43..23c7500e405d0f1c78f0c3e3b23595b473b5fd9b 100644 (file)
@@ -281,9 +281,11 @@ impl<'a, 'b, D: Database> TxCache<'a, 'b, D> {
                 .client
                 .batch_transaction_get(need_fetch.clone())
                 .map_err(Error::Electrum)?;
-            for (tx, _txid) in txs.into_iter().zip(need_fetch) {
-                debug_assert_eq!(*_txid, tx.txid());
-                self.cache.insert(tx.txid(), tx);
+            let mut txs: HashMap<_, _> = txs.into_iter().map(|tx| (tx.txid(), tx)).collect();
+            for txid in need_fetch {
+                if let Some(tx) = txs.remove(txid) {
+                    self.cache.insert(*txid, tx);
+                }
             }
         }