@@ -2309,6 +2309,57 @@ impl<D> Wallet<D> {
23092309 pub fn local_chain ( & self ) -> & LocalChain {
23102310 & self . chain
23112311 }
2312+
2313+ /// Set lookahead for all keychains.
2314+ ///
2315+ /// Passing a lookahead of 0 will result in an error. This is because if we sync
2316+ /// the chain with a lookahead of 0, we would not find any update since we don't
2317+ /// have any scripts stored.
2318+ pub fn set_lookahead_for_all ( & mut self , lookahead : u32 ) {
2319+ const DEFAULT_KEYCHAIN_LOOKAHEAD : u32 = 10 ;
2320+
2321+ self . indexed_graph . index . set_lookahead_for_all (
2322+ if lookahead > 0 {
2323+ lookahead
2324+ } else {
2325+ DEFAULT_KEYCHAIN_LOOKAHEAD
2326+ }
2327+ ) ;
2328+ }
2329+
2330+ /// Insert all the block's relevant transactions into the IndexedTxGraph.
2331+ pub fn apply_block_relevant (
2332+ & mut self ,
2333+ block : bitcoin:: Block ,
2334+ height : u32 ,
2335+ ) -> Result < ( ) , CannotConnectError >
2336+ where
2337+ D : PersistBackend < ChangeSet > ,
2338+ {
2339+ let chain_update = CheckPoint :: from_header ( & block. header , height) . into_update ( false ) ;
2340+ let mut changeset = ChangeSet :: from ( self . chain . apply_update ( chain_update) ?) ;
2341+ changeset. append ( ChangeSet :: from (
2342+ self . indexed_graph . apply_block_relevant ( block, height) ,
2343+ ) ) ;
2344+ self . persist . stage ( changeset) ;
2345+ Ok ( ( ) )
2346+ }
2347+
2348+ /// Batch insert unconfirmed transactions into the IndexedTxGraph.
2349+ /// Filtering out those that are not relevant.
2350+ ///
2351+ /// Read more here: [`self.indexed_graph.batch_insert_relevant_unconfirmed()`]
2352+ pub fn batch_insert_relevant_unconfirmed < ' t > (
2353+ & mut self ,
2354+ unconfirmed_txs : impl IntoIterator < Item = ( & ' t Transaction , u64 ) > ,
2355+ ) where
2356+ D : PersistBackend < ChangeSet > ,
2357+ {
2358+ let indexed_graph_changeset = self
2359+ . indexed_graph
2360+ . batch_insert_relevant_unconfirmed ( unconfirmed_txs) ;
2361+ self . persist . stage ( ChangeSet :: from ( indexed_graph_changeset) ) ;
2362+ }
23122363}
23132364
23142365impl < D > AsRef < bdk_chain:: tx_graph:: TxGraph < ConfirmationTimeHeightAnchor > > for Wallet < D > {
0 commit comments