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