@@ -5,11 +5,12 @@ mod common;
55
66use std:: { collections:: BTreeSet , sync:: Arc } ;
77
8+ use bdk_chain:: indexed_tx_graph:: ChangeSet ;
89use bdk_chain:: {
910 indexed_tx_graph:: { self , IndexedTxGraph } ,
1011 indexer:: keychain_txout:: KeychainTxOutIndex ,
1112 local_chain:: LocalChain ,
12- tx_graph , Balance , CanonicalizationParams , ChainPosition , ConfirmationBlockTime , DescriptorExt ,
13+ Balance , CanonicalizationParams , ChainPosition , ConfirmationBlockTime , DescriptorExt ,
1314 SpkIterator ,
1415} ;
1516use bdk_testenv:: {
@@ -74,45 +75,41 @@ fn insert_relevant_txs() {
7475
7576 let txs = [ tx_c, tx_b, tx_a] ;
7677
77- let changeset = indexed_tx_graph:: ChangeSet {
78- tx_graph : tx_graph:: ChangeSet {
79- txs : txs. iter ( ) . cloned ( ) . map ( Arc :: new) . collect ( ) ,
80- ..Default :: default ( )
81- } ,
82- indexer : keychain_txout:: ChangeSet {
83- last_revealed : [ ( descriptor. descriptor_id ( ) , 9_u32 ) ] . into ( ) ,
84- spk_cache : [ ( descriptor. descriptor_id ( ) , {
85- let index_after_spk_1 = 9 /* index of spk_1 */ + 1 ;
86- SpkIterator :: new_with_range (
87- & descriptor,
88- // This will also persist the staged spk cache inclusions from prev call to
89- // `.insert_descriptor`.
90- 0 ..index_after_spk_1 + lookahead,
91- )
92- . collect ( )
93- } ) ]
94- . into ( ) ,
95- } ,
96- } ;
78+ let mut changeset = ChangeSet :: default ( ) ;
79+ changeset
80+ . tx_graph
81+ . txs
82+ . extend ( txs. iter ( ) . cloned ( ) . map ( Arc :: new) ) ;
83+ let mut indexer_changeset = keychain_txout:: ChangeSet :: default ( ) ;
84+ indexer_changeset. last_revealed = [ ( descriptor. descriptor_id ( ) , 9_u32 ) ] . into ( ) ;
85+ indexer_changeset. spk_cache = [ ( descriptor. descriptor_id ( ) , {
86+ let index_after_spk_1 = 9 /* index of spk_1 */ + 1 ;
87+ SpkIterator :: new_with_range (
88+ & descriptor,
89+ // This will also persist the staged spk cache inclusions from prev call to
90+ // `.insert_descriptor`.
91+ 0 ..index_after_spk_1 + lookahead,
92+ )
93+ . collect ( )
94+ } ) ]
95+ . into ( ) ;
96+ changeset. indexer = indexer_changeset. into ( ) ;
9797
9898 assert_eq ! (
9999 graph. batch_insert_relevant( txs. iter( ) . cloned( ) . map( |tx| ( tx, None ) ) ) ,
100100 changeset,
101101 ) ;
102102
103103 // The initial changeset will also contain info about the keychain we added
104- let initial_changeset = indexed_tx_graph:: ChangeSet {
105- tx_graph : changeset. tx_graph ,
106- indexer : keychain_txout:: ChangeSet {
107- last_revealed : changeset. indexer . last_revealed ,
108- spk_cache : [ (
109- descriptor. descriptor_id ( ) ,
110- SpkIterator :: new_with_range ( & descriptor, 0 ..=9 /* index of spk_1*/ + lookahead)
111- . collect ( ) ,
112- ) ]
113- . into ( ) ,
114- } ,
115- } ;
104+ let mut initial_changeset = indexed_tx_graph:: ChangeSet :: default ( ) ;
105+ initial_changeset. tx_graph = changeset. tx_graph ;
106+ initial_changeset. indexer = keychain_txout:: ChangeSet :: default ( ) ;
107+ initial_changeset. indexer . last_revealed = changeset. indexer . last_revealed ;
108+ initial_changeset. indexer . spk_cache = [ (
109+ descriptor. descriptor_id ( ) ,
110+ SpkIterator :: new_with_range ( & descriptor, 0 ..=9 /*index of spk_1 */ + lookahead) . collect ( ) ,
111+ ) ]
112+ . into ( ) ;
116113
117114 assert_eq ! ( graph. initial_changeset( ) , initial_changeset) ;
118115}
0 commit comments