@@ -4,7 +4,8 @@ use bdk_bitcoind_rpc::Emitter;
44use bdk_chain:: {
55 bitcoin:: { Address , Amount , Txid } ,
66 local_chain:: { CheckPoint , LocalChain } ,
7- Balance , BlockId , IndexedTxGraph , Merge , SpkTxOutIndex ,
7+ tx_graph:: TxGraph ,
8+ Balance , BlockId , Merge , SpkTxOutIndex ,
89} ;
910use bdk_testenv:: { anyhow, TestEnv } ;
1011use bitcoin:: { hashes:: Hash , Block , OutPoint , ScriptBuf , WScriptHash } ;
@@ -149,7 +150,7 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
149150 println ! ( "mined blocks!" ) ;
150151
151152 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 ( {
153154 let mut index = SpkTxOutIndex :: < usize > :: default ( ) ;
154155 index. insert_spk ( 0 , addr_0. script_pubkey ( ) ) ;
155156 index. insert_spk ( 1 , addr_1. script_pubkey ( ) ) ;
@@ -162,8 +163,8 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
162163 while let Some ( emission) = emitter. next_block ( ) ? {
163164 let height = emission. block_height ( ) ;
164165 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( ) ) ;
167168 }
168169
169170 // 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<()> {
190191 assert ! ( emitter. next_block( ) ?. is_none( ) ) ;
191192
192193 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) ;
194195 assert_eq ! (
195- indexed_additions
196- . graph
196+ tx_graph_changeset
197197 . txs
198198 . iter( )
199199 . map( |tx| tx. compute_txid( ) )
200200 . collect:: <BTreeSet <Txid >>( ) ,
201201 exp_txids,
202202 "changeset should have the 3 mempool transactions" ,
203203 ) ;
204- assert ! ( indexed_additions . graph . anchors. is_empty( ) ) ;
204+ assert ! ( tx_graph_changeset . anchors. is_empty( ) ) ;
205205 }
206206
207207 // mine a block that confirms the 3 txs
@@ -223,10 +223,10 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
223223 let emission = emitter. next_block ( ) ?. expect ( "must get mined block" ) ;
224224 let height = emission. block_height ( ) ;
225225 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) ;
230230 }
231231
232232 Ok ( ( ) )
@@ -277,18 +277,18 @@ fn ensure_block_emitted_after_reorg_is_at_reorg_height() -> anyhow::Result<()> {
277277
278278fn process_block (
279279 recv_chain : & mut LocalChain ,
280- recv_graph : & mut IndexedTxGraph < BlockId , SpkTxOutIndex < ( ) > > ,
280+ recv_graph : & mut TxGraph < BlockId , SpkTxOutIndex < ( ) > > ,
281281 block : Block ,
282282 block_height : u32 ,
283283) -> anyhow:: Result < ( ) > {
284284 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) ;
286286 Ok ( ( ) )
287287}
288288
289289fn sync_from_emitter < C > (
290290 recv_chain : & mut LocalChain ,
291- recv_graph : & mut IndexedTxGraph < BlockId , SpkTxOutIndex < ( ) > > ,
291+ recv_graph : & mut TxGraph < BlockId , SpkTxOutIndex < ( ) > > ,
292292 emitter : & mut Emitter < C > ,
293293) -> anyhow:: Result < ( ) >
294294where
@@ -303,13 +303,11 @@ where
303303
304304fn get_balance (
305305 recv_chain : & LocalChain ,
306- recv_graph : & IndexedTxGraph < BlockId , SpkTxOutIndex < ( ) > > ,
306+ recv_graph : & TxGraph < BlockId , SpkTxOutIndex < ( ) > > ,
307307) -> anyhow:: Result < Balance > {
308308 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 ) ;
313311 Ok ( balance)
314312}
315313
@@ -341,7 +339,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
341339
342340 // setup receiver
343341 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 ( {
345343 let mut recv_index = SpkTxOutIndex :: default ( ) ;
346344 recv_index. insert_spk ( ( ) , spk_to_track. clone ( ) ) ;
347345 recv_index
0 commit comments