@@ -5,11 +5,12 @@ mod common;
5
5
6
6
use std:: { collections:: BTreeSet , sync:: Arc } ;
7
7
8
+ use bdk_chain:: indexed_tx_graph:: ChangeSet ;
8
9
use bdk_chain:: {
9
10
indexed_tx_graph:: { self , IndexedTxGraph } ,
10
11
indexer:: keychain_txout:: KeychainTxOutIndex ,
11
12
local_chain:: LocalChain ,
12
- tx_graph , Balance , CanonicalizationParams , ChainPosition , ConfirmationBlockTime , DescriptorExt ,
13
+ Balance , CanonicalizationParams , ChainPosition , ConfirmationBlockTime , DescriptorExt ,
13
14
SpkIterator ,
14
15
} ;
15
16
use bdk_testenv:: {
@@ -74,45 +75,41 @@ fn insert_relevant_txs() {
74
75
75
76
let txs = [ tx_c, tx_b, tx_a] ;
76
77
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;
97
97
98
98
assert_eq ! (
99
99
graph. batch_insert_relevant( txs. iter( ) . cloned( ) . map( |tx| ( tx, None ) ) ) ,
100
100
changeset,
101
101
) ;
102
102
103
103
// 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 ( ) ;
116
113
117
114
assert_eq ! ( graph. initial_changeset( ) , initial_changeset) ;
118
115
}
0 commit comments