@@ -8,7 +8,7 @@ use bdk_chain::{
88 keychain:: { Balance , DerivationAdditions , KeychainTxOutIndex } ,
99 local_chain:: LocalChain ,
1010 tx_graph:: Additions ,
11- BlockId , ObservedAs ,
11+ ConfirmationHeightAnchor , ObservedAs ,
1212} ;
1313use bitcoin:: { secp256k1:: Secp256k1 , BlockHash , OutPoint , Script , Transaction , TxIn , TxOut } ;
1414use miniscript:: Descriptor ;
@@ -28,7 +28,7 @@ fn insert_relevant_txs() {
2828 let spk_0 = descriptor. at_derivation_index ( 0 ) . script_pubkey ( ) ;
2929 let spk_1 = descriptor. at_derivation_index ( 9 ) . script_pubkey ( ) ;
3030
31- let mut graph = IndexedTxGraph :: < BlockId , KeychainTxOutIndex < ( ) > > :: default ( ) ;
31+ let mut graph = IndexedTxGraph :: < ConfirmationHeightAnchor , KeychainTxOutIndex < ( ) > > :: default ( ) ;
3232 graph. index . add_keychain ( ( ) , descriptor) ;
3333 graph. index . set_lookahead ( & ( ) , 10 ) ;
3434
@@ -118,7 +118,8 @@ fn test_list_owned_txouts() {
118118 let ( desc_1, _) = Descriptor :: parse_descriptor ( & Secp256k1 :: signing_only ( ) , "tr(tprv8ZgxMBicQKsPd3krDUsBAmtnRsK3rb8u5yi1zhQgMhF1tR8MW7xfE4rnrbbsrbPR52e7rKapu6ztw1jXveJSCGHEriUGZV7mCe88duLp5pj/86'/1'/0'/0/*)" ) . unwrap ( ) ;
119119 let ( desc_2, _) = Descriptor :: parse_descriptor ( & Secp256k1 :: signing_only ( ) , "tr(tprv8ZgxMBicQKsPd3krDUsBAmtnRsK3rb8u5yi1zhQgMhF1tR8MW7xfE4rnrbbsrbPR52e7rKapu6ztw1jXveJSCGHEriUGZV7mCe88duLp5pj/86'/1'/0'/1/*)" ) . unwrap ( ) ;
120120
121- let mut graph = IndexedTxGraph :: < BlockId , KeychainTxOutIndex < String > > :: default ( ) ;
121+ let mut graph =
122+ IndexedTxGraph :: < ConfirmationHeightAnchor , KeychainTxOutIndex < String > > :: default ( ) ;
122123
123124 graph. index . add_keychain ( "keychain_1" . into ( ) , desc_1) ;
124125 graph. index . add_keychain ( "keychain_2" . into ( ) , desc_2) ;
@@ -206,86 +207,94 @@ fn test_list_owned_txouts() {
206207 // For unconfirmed txs we pass in `None`.
207208
208209 let _ = graph. insert_relevant_txs (
209- [ & tx1, & tx2, & tx3, & tx6]
210- . iter ( )
211- . enumerate ( )
212- . map ( |( i, tx) | ( * tx, [ local_chain. get_block ( i as u32 ) . unwrap ( ) ] ) ) ,
210+ [ & tx1, & tx2, & tx3, & tx6] . iter ( ) . enumerate ( ) . map ( |( i, tx) | {
211+ (
212+ * tx,
213+ local_chain
214+ . get_block ( i as u32 )
215+ . map ( |anchor_block| ConfirmationHeightAnchor {
216+ anchor_block,
217+ confirmation_height : anchor_block. height ,
218+ } ) ,
219+ )
220+ } ) ,
213221 None ,
214222 ) ;
215223
216224 let _ = graph. insert_relevant_txs ( [ & tx4, & tx5] . iter ( ) . map ( |tx| ( * tx, None ) ) , Some ( 100 ) ) ;
217225
218226 // A helper lambda to extract and filter data from the graph.
219- let fetch = |ht : u32 , graph : & IndexedTxGraph < BlockId , KeychainTxOutIndex < String > > | {
220- let txouts = graph
221- . list_owned_txouts ( & local_chain, local_chain. get_block ( ht) . unwrap ( ) )
222- . collect :: < Vec < _ > > ( ) ;
223-
224- let utxos = graph
225- . list_owned_unspents ( & local_chain, local_chain. get_block ( ht) . unwrap ( ) )
226- . collect :: < Vec < _ > > ( ) ;
227-
228- let balance = graph. balance (
229- & local_chain,
230- local_chain. get_block ( ht) . unwrap ( ) ,
231- |spk : & Script | trusted_spks. contains ( spk) ,
232- ) ;
233-
234- assert_eq ! ( txouts. len( ) , 5 ) ;
235- assert_eq ! ( utxos. len( ) , 4 ) ;
236-
237- let confirmed_txouts_txid = txouts
238- . iter ( )
239- . filter_map ( |full_txout| {
240- if matches ! ( full_txout. chain_position, ObservedAs :: Confirmed ( _) ) {
241- Some ( full_txout. outpoint . txid )
242- } else {
243- None
244- }
245- } )
246- . collect :: < BTreeSet < _ > > ( ) ;
247-
248- let unconfirmed_txouts_txid = txouts
249- . iter ( )
250- . filter_map ( |full_txout| {
251- if matches ! ( full_txout. chain_position, ObservedAs :: Unconfirmed ( _) ) {
252- Some ( full_txout. outpoint . txid )
253- } else {
254- None
255- }
256- } )
257- . collect :: < BTreeSet < _ > > ( ) ;
258-
259- let confirmed_utxos_txid = utxos
260- . iter ( )
261- . filter_map ( |full_txout| {
262- if matches ! ( full_txout. chain_position, ObservedAs :: Confirmed ( _) ) {
263- Some ( full_txout. outpoint . txid )
264- } else {
265- None
266- }
267- } )
268- . collect :: < BTreeSet < _ > > ( ) ;
269-
270- let unconfirmed_utxos_txid = utxos
271- . iter ( )
272- . filter_map ( |full_txout| {
273- if matches ! ( full_txout. chain_position, ObservedAs :: Unconfirmed ( _) ) {
274- Some ( full_txout. outpoint . txid )
275- } else {
276- None
277- }
278- } )
279- . collect :: < BTreeSet < _ > > ( ) ;
280-
281- (
282- confirmed_txouts_txid,
283- unconfirmed_txouts_txid,
284- confirmed_utxos_txid,
285- unconfirmed_utxos_txid,
286- balance,
287- )
288- } ;
227+ let fetch =
228+ |ht : u32 , graph : & IndexedTxGraph < ConfirmationHeightAnchor , KeychainTxOutIndex < String > > | {
229+ let txouts = graph
230+ . list_owned_txouts ( & local_chain, local_chain. get_block ( ht) . unwrap ( ) )
231+ . collect :: < Vec < _ > > ( ) ;
232+
233+ let utxos = graph
234+ . list_owned_unspents ( & local_chain, local_chain. get_block ( ht) . unwrap ( ) )
235+ . collect :: < Vec < _ > > ( ) ;
236+
237+ let balance = graph. balance (
238+ & local_chain,
239+ local_chain. get_block ( ht) . unwrap ( ) ,
240+ |spk : & Script | trusted_spks. contains ( spk) ,
241+ ) ;
242+
243+ assert_eq ! ( txouts. len( ) , 5 ) ;
244+ assert_eq ! ( utxos. len( ) , 4 ) ;
245+
246+ let confirmed_txouts_txid = txouts
247+ . iter ( )
248+ . filter_map ( |full_txout| {
249+ if matches ! ( full_txout. chain_position, ObservedAs :: Confirmed ( _) ) {
250+ Some ( full_txout. outpoint . txid )
251+ } else {
252+ None
253+ }
254+ } )
255+ . collect :: < BTreeSet < _ > > ( ) ;
256+
257+ let unconfirmed_txouts_txid = txouts
258+ . iter ( )
259+ . filter_map ( |full_txout| {
260+ if matches ! ( full_txout. chain_position, ObservedAs :: Unconfirmed ( _) ) {
261+ Some ( full_txout. outpoint . txid )
262+ } else {
263+ None
264+ }
265+ } )
266+ . collect :: < BTreeSet < _ > > ( ) ;
267+
268+ let confirmed_utxos_txid = utxos
269+ . iter ( )
270+ . filter_map ( |full_txout| {
271+ if matches ! ( full_txout. chain_position, ObservedAs :: Confirmed ( _) ) {
272+ Some ( full_txout. outpoint . txid )
273+ } else {
274+ None
275+ }
276+ } )
277+ . collect :: < BTreeSet < _ > > ( ) ;
278+
279+ let unconfirmed_utxos_txid = utxos
280+ . iter ( )
281+ . filter_map ( |full_txout| {
282+ if matches ! ( full_txout. chain_position, ObservedAs :: Unconfirmed ( _) ) {
283+ Some ( full_txout. outpoint . txid )
284+ } else {
285+ None
286+ }
287+ } )
288+ . collect :: < BTreeSet < _ > > ( ) ;
289+
290+ (
291+ confirmed_txouts_txid,
292+ unconfirmed_txouts_txid,
293+ confirmed_utxos_txid,
294+ unconfirmed_utxos_txid,
295+ balance,
296+ )
297+ } ;
289298
290299 // ----- TEST BLOCK -----
291300
0 commit comments