@@ -5,7 +5,7 @@ use bdk_chain::{
5
5
bitcoin:: { Address , Amount , Txid } ,
6
6
local_chain:: { CheckPoint , LocalChain } ,
7
7
spk_txout:: SpkTxOutIndex ,
8
- Balance , BlockId , IndexedTxGraph , Merge ,
8
+ Balance , BlockId , Merge , TxGraph ,
9
9
} ;
10
10
use bdk_testenv:: { anyhow, TestEnv } ;
11
11
use bitcoin:: { hashes:: Hash , Block , OutPoint , ScriptBuf , WScriptHash } ;
@@ -148,7 +148,7 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
148
148
env. mine_blocks ( 101 , None ) ?;
149
149
150
150
let ( mut chain, _) = LocalChain :: from_genesis_hash ( env. rpc_client ( ) . get_block_hash ( 0 ) ?) ;
151
- let mut indexed_tx_graph = IndexedTxGraph :: < BlockId , _ > :: new ( {
151
+ let mut tx_graph = TxGraph :: < BlockId , _ > :: new ( {
152
152
let mut index = SpkTxOutIndex :: < usize > :: default ( ) ;
153
153
index. insert_spk ( 0 , addr_0. script_pubkey ( ) ) ;
154
154
index. insert_spk ( 1 , addr_1. script_pubkey ( ) ) ;
@@ -161,8 +161,8 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
161
161
while let Some ( emission) = emitter. next_block ( ) ? {
162
162
let height = emission. block_height ( ) ;
163
163
let _ = chain. apply_update ( emission. checkpoint ) ?;
164
- let indexed_additions = indexed_tx_graph . apply_block_relevant ( & emission. block , height) ;
165
- assert ! ( indexed_additions . is_empty( ) ) ;
164
+ let tx_graph_changeset = tx_graph . apply_block_relevant ( & emission. block , height) ;
165
+ assert ! ( tx_graph_changeset . is_empty( ) ) ;
166
166
}
167
167
168
168
// send 3 txs to a tracked address, these txs will be in the mempool
@@ -189,18 +189,17 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
189
189
assert ! ( emitter. next_block( ) ?. is_none( ) ) ;
190
190
191
191
let mempool_txs = emitter. mempool ( ) ?;
192
- let indexed_additions = indexed_tx_graph . batch_insert_unconfirmed ( mempool_txs) ;
192
+ let tx_graph_changeset = tx_graph . batch_insert_unconfirmed ( mempool_txs) ;
193
193
assert_eq ! (
194
- indexed_additions
195
- . tx_graph
194
+ tx_graph_changeset
196
195
. txs
197
196
. iter( )
198
197
. map( |tx| tx. compute_txid( ) )
199
198
. collect:: <BTreeSet <Txid >>( ) ,
200
199
exp_txids,
201
200
"changeset should have the 3 mempool transactions" ,
202
201
) ;
203
- assert ! ( indexed_additions . tx_graph . anchors. is_empty( ) ) ;
202
+ assert ! ( tx_graph_changeset . anchors. is_empty( ) ) ;
204
203
}
205
204
206
205
// mine a block that confirms the 3 txs
@@ -222,10 +221,10 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
222
221
let emission = emitter. next_block ( ) ?. expect ( "must get mined block" ) ;
223
222
let height = emission. block_height ( ) ;
224
223
let _ = chain. apply_update ( emission. checkpoint ) ?;
225
- let indexed_additions = indexed_tx_graph . apply_block_relevant ( & emission. block , height) ;
226
- assert ! ( indexed_additions . tx_graph . txs. is_empty( ) ) ;
227
- assert ! ( indexed_additions . tx_graph . txouts. is_empty( ) ) ;
228
- assert_eq ! ( indexed_additions . tx_graph . anchors, exp_anchors) ;
224
+ let tx_graph_changeset = tx_graph . apply_block_relevant ( & emission. block , height) ;
225
+ assert ! ( tx_graph_changeset . txs. is_empty( ) ) ;
226
+ assert ! ( tx_graph_changeset . txouts. is_empty( ) ) ;
227
+ assert_eq ! ( tx_graph_changeset . anchors, exp_anchors) ;
229
228
}
230
229
231
230
Ok ( ( ) )
@@ -276,7 +275,7 @@ fn ensure_block_emitted_after_reorg_is_at_reorg_height() -> anyhow::Result<()> {
276
275
277
276
fn process_block (
278
277
recv_chain : & mut LocalChain ,
279
- recv_graph : & mut IndexedTxGraph < BlockId , SpkTxOutIndex < ( ) > > ,
278
+ recv_graph : & mut TxGraph < BlockId , SpkTxOutIndex < ( ) > > ,
280
279
block : Block ,
281
280
block_height : u32 ,
282
281
) -> anyhow:: Result < ( ) > {
@@ -287,7 +286,7 @@ fn process_block(
287
286
288
287
fn sync_from_emitter < C > (
289
288
recv_chain : & mut LocalChain ,
290
- recv_graph : & mut IndexedTxGraph < BlockId , SpkTxOutIndex < ( ) > > ,
289
+ recv_graph : & mut TxGraph < BlockId , SpkTxOutIndex < ( ) > > ,
291
290
emitter : & mut Emitter < C > ,
292
291
) -> anyhow:: Result < ( ) >
293
292
where
@@ -302,13 +301,11 @@ where
302
301
303
302
fn get_balance (
304
303
recv_chain : & LocalChain ,
305
- recv_graph : & IndexedTxGraph < BlockId , SpkTxOutIndex < ( ) > > ,
304
+ recv_graph : & TxGraph < BlockId , SpkTxOutIndex < ( ) > > ,
306
305
) -> anyhow:: Result < Balance > {
307
306
let chain_tip = recv_chain. tip ( ) . block_id ( ) ;
308
307
let outpoints = recv_graph. index . outpoints ( ) . clone ( ) ;
309
- let balance = recv_graph
310
- . graph ( )
311
- . balance ( recv_chain, chain_tip, outpoints, |_, _| true ) ;
308
+ let balance = recv_graph. balance ( recv_chain, chain_tip, outpoints, |_, _| true ) ;
312
309
Ok ( balance)
313
310
}
314
311
@@ -340,7 +337,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
340
337
341
338
// setup receiver
342
339
let ( mut recv_chain, _) = LocalChain :: from_genesis_hash ( env. rpc_client ( ) . get_block_hash ( 0 ) ?) ;
343
- let mut recv_graph = IndexedTxGraph :: < BlockId , _ > :: new ( {
340
+ let mut recv_graph = TxGraph :: < BlockId , _ > :: new ( {
344
341
let mut recv_index = SpkTxOutIndex :: default ( ) ;
345
342
recv_index. insert_spk ( ( ) , spk_to_track. clone ( ) ) ;
346
343
recv_index
0 commit comments