]> Untitled Git - bdk/commitdiff
[bdk_chain_redesign] Fix `apply_additions` logic for `IndexedTxGraph`.
author志宇 <hello@evanlinjin.me>
Mon, 27 Mar 2023 13:51:11 +0000 (21:51 +0800)
committer志宇 <hello@evanlinjin.me>
Mon, 27 Mar 2023 13:51:11 +0000 (21:51 +0800)
crates/chain/src/indexed_tx_graph.rs

index 91ecd571908b4d6c842d610f0bd01bd3d6319bf5..4245e57d98e1b7bd4fe1e4871b4eb022bc79c57e 100644 (file)
@@ -22,6 +22,7 @@ pub struct TxOutInChain<'a, I, A> {
     pub txout: FullTxOut<ObservedIn<&'a A>>,
 }
 
+#[must_use]
 pub struct IndexedAdditions<A, D> {
     pub graph_additions: Additions<A>,
     pub index_delta: D,
@@ -83,8 +84,17 @@ impl<A: BlockAnchor, I: TxIndex> IndexedTxGraph<A, I> {
             graph_additions,
             index_delta,
         } = additions;
-        self.graph.apply_additions(graph_additions);
+
         self.index.apply_additions(index_delta);
+
+        for tx in &graph_additions.tx {
+            self.index.index_tx(tx);
+        }
+        for (&outpoint, txout) in &graph_additions.txout {
+            self.index.index_txout(outpoint, txout);
+        }
+
+        self.graph.apply_additions(graph_additions);
     }
 
     /// Insert a `txout` that exists in `outpoint` with the given `observation`.