@@ -448,21 +448,26 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
448448 /// Store lookahead scripts until `target_index` (inclusive).
449449 ///
450450 /// This does not change the global `lookahead` setting.
451- pub fn lookahead_to_target (
452- & mut self ,
453- keychain : K ,
454- target_index : u32 ,
455- derived_spks : & mut impl Extend < Indexed < ScriptBuf > > ,
456- ) {
451+ pub fn lookahead_to_target ( & mut self , keychain : K , target_index : u32 ) -> ChangeSet {
452+ let mut changeset = ChangeSet :: default ( ) ;
457453 if let Some ( ( next_index, _) ) = self . next_index ( keychain. clone ( ) ) {
458454 let temp_lookahead = ( target_index + 1 )
459455 . checked_sub ( next_index)
460456 . filter ( |& index| index > 0 ) ;
461457
462458 if let Some ( temp_lookahead) = temp_lookahead {
463- self . replenish_inner_index_keychain ( keychain, temp_lookahead, derived_spks) ;
459+ let did = self
460+ . keychain_to_descriptor_id
461+ . get ( & keychain)
462+ . expect ( "invariant" ) ;
463+ self . replenish_inner_index_keychain (
464+ keychain,
465+ temp_lookahead,
466+ changeset. spk_cache . entry ( * did) . or_default ( ) ,
467+ ) ;
464468 }
465469 }
470+ changeset
466471 }
467472
468473 fn replenish_inner_index_did (
@@ -524,7 +529,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
524529 let spk_i = * _i;
525530 * _i = spk_i. saturating_add ( 1 ) ;
526531
527- if let Some ( spk) = spk_cache. get ( _i ) {
532+ if let Some ( spk) = spk_cache. get ( & spk_i ) {
528533 return Some ( ( spk_i, spk. clone ( ) ) ) ;
529534 }
530535 let spk = _desc
0 commit comments