@@ -142,15 +142,15 @@ impl<K: Clone + Ord + Debug> Indexer for KeychainTxOutIndex<K> {
142
142
143
143
fn index_txout ( & mut self , outpoint : OutPoint , txout : & TxOut ) -> Self :: ChangeSet {
144
144
let mut changeset = ChangeSet :: default ( ) ;
145
- if let Some ( ( keychain, index) ) = self . inner . scan_txout ( outpoint, txout) {
145
+ if let Some ( ( keychain, index) ) = self . inner . scan_txout ( outpoint, txout) . cloned ( ) {
146
146
let did = self
147
147
. keychains_to_descriptor_ids
148
- . get ( keychain)
148
+ . get ( & keychain)
149
149
. expect ( "invariant" ) ;
150
- if self . last_revealed . get ( did) < Some ( index) {
151
- self . last_revealed . insert ( * did, * index) ;
152
- changeset. last_revealed . insert ( * did, * index) ;
153
- self . replenish_lookahead_did ( * did) ;
150
+ if self . last_revealed . get ( did) < Some ( & index) {
151
+ self . last_revealed . insert ( * did, index) ;
152
+ changeset. last_revealed . insert ( * did, index) ;
153
+ self . replenish_lookahead ( * did, & keychain , self . lookahead ) ;
154
154
}
155
155
}
156
156
changeset
@@ -376,7 +376,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
376
376
. insert ( keychain. clone ( ) , desc_id) ;
377
377
self . descriptor_ids_to_keychains
378
378
. insert ( desc_id, keychain. clone ( ) ) ;
379
- self . replenish_lookahead ( & keychain, self . lookahead ) ;
379
+ self . replenish_lookahead_keychain ( & keychain, self . lookahead ) ;
380
380
changeset
381
381
. keychains_added
382
382
. insert ( keychain. clone ( ) , descriptor) ;
@@ -439,39 +439,42 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
439
439
. filter ( |& index| index > 0 ) ;
440
440
441
441
if let Some ( temp_lookahead) = temp_lookahead {
442
- self . replenish_lookahead ( keychain, temp_lookahead) ;
442
+ self . replenish_lookahead_keychain ( keychain, temp_lookahead) ;
443
443
}
444
444
}
445
445
}
446
446
447
- fn replenish_lookahead_did ( & mut self , did : DescriptorId ) {
447
+ fn replenish_lookahead_did ( & mut self , did : DescriptorId , lookahead : u32 ) {
448
448
if let Some ( keychain) = self . descriptor_ids_to_keychains . get ( & did) . cloned ( ) {
449
- self . replenish_lookahead ( & keychain, self . lookahead ) ;
449
+ self . replenish_lookahead ( did , & keychain, lookahead) ;
450
450
}
451
451
}
452
452
453
- fn replenish_lookahead ( & mut self , keychain : & K , lookahead : u32 ) {
453
+ fn replenish_lookahead_keychain ( & mut self , keychain : & K , lookahead : u32 ) {
454
454
if let Some ( did) = self . keychains_to_descriptor_ids . get ( keychain) {
455
- let descriptor = self
456
- . descriptor_ids_to_descriptors
457
- . get ( did)
458
- . expect ( "invariant" ) ;
459
- let next_store_index = self
455
+ self . replenish_lookahead ( * did, keychain, lookahead) ;
456
+ }
457
+ }
458
+
459
+ fn replenish_lookahead ( & mut self , did : DescriptorId , keychain : & K , lookahead : u32 ) {
460
+ let descriptor = self
461
+ . descriptor_ids_to_descriptors
462
+ . get ( & did)
463
+ . expect ( "invariant" ) ;
464
+ let next_store_index = self
465
+ . inner
466
+ . all_spks ( )
467
+ . range ( & ( keychain. clone ( ) , u32:: MIN ) ..=& ( keychain. clone ( ) , u32:: MAX ) )
468
+ . last ( )
469
+ . map_or ( 0 , |( ( _, index) , _) | * index + 1 ) ;
470
+ let next_reveal_index = self . last_revealed . get ( & did) . map_or ( 0 , |v| * v + 1 ) ;
471
+ for ( new_index, new_spk) in
472
+ SpkIterator :: new_with_range ( descriptor, next_store_index..next_reveal_index + lookahead)
473
+ {
474
+ let _inserted = self
460
475
. inner
461
- . all_spks ( )
462
- . range ( & ( keychain. clone ( ) , u32:: MIN ) ..=& ( keychain. clone ( ) , u32:: MAX ) )
463
- . last ( )
464
- . map_or ( 0 , |( ( _, index) , _) | * index + 1 ) ;
465
- let next_reveal_index = self . last_revealed . get ( did) . map_or ( 0 , |v| * v + 1 ) ;
466
- for ( new_index, new_spk) in SpkIterator :: new_with_range (
467
- descriptor,
468
- next_store_index..next_reveal_index + lookahead,
469
- ) {
470
- let _inserted = self
471
- . inner
472
- . insert_spk ( ( keychain. clone ( ) , new_index) , new_spk) ;
473
- debug_assert ! ( _inserted, "replenish lookahead: must not have existing spk: keychain={:?}, lookahead={}, next_store_index={}, next_reveal_index={}" , keychain, lookahead, next_store_index, next_reveal_index) ;
474
- }
476
+ . insert_spk ( ( keychain. clone ( ) , new_index) , new_spk) ;
477
+ debug_assert ! ( _inserted, "replenish lookahead: must not have existing spk: keychain={:?}, lookahead={}, next_store_index={}, next_reveal_index={}" , keychain, lookahead, next_store_index, next_reveal_index) ;
475
478
}
476
479
}
477
480
@@ -719,7 +722,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
719
722
let _ = self . inner . insert_spk ( ( keychain. clone ( ) , next_index) , spk) ;
720
723
self . last_revealed . insert ( * did, next_index) ;
721
724
changeset. last_revealed . insert ( * did, next_index) ;
722
- self . replenish_lookahead ( keychain, self . lookahead ) ;
725
+ self . replenish_lookahead_keychain ( keychain, self . lookahead ) ;
723
726
}
724
727
let script = self
725
728
. inner
@@ -823,7 +826,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
823
826
}
824
827
825
828
for did in last_revealed. keys ( ) {
826
- self . replenish_lookahead_did ( * did) ;
829
+ self . replenish_lookahead_did ( * did, self . lookahead ) ;
827
830
}
828
831
}
829
832
}
0 commit comments