@@ -31,8 +31,8 @@ use bdk_chain::{
3131use bitcoin:: secp256k1:: { All , Secp256k1 } ;
3232use bitcoin:: sighash:: { EcdsaSighashType , TapSighashType } ;
3333use bitcoin:: {
34- absolute, Address , Network , OutPoint , Script , ScriptBuf , Sequence , Transaction , TxOut , Txid ,
35- Weight , Witness ,
34+ absolute, Address , Block , Network , OutPoint , Script , ScriptBuf , Sequence , Transaction , TxOut ,
35+ Txid , Weight , Witness ,
3636} ;
3737use bitcoin:: { consensus:: encode:: serialize, BlockHash } ;
3838use bitcoin:: { constants:: genesis_block, psbt} ;
@@ -2327,6 +2327,40 @@ impl<D> Wallet<D> {
23272327 self . indexed_graph . index . set_lookahead_for_all ( lookahead) ;
23282328 Ok ( ( ) )
23292329 }
2330+
2331+ /// Insert all the block's relevant transactions into the IndexedTxGraph.
2332+ pub fn apply_block_relevant (
2333+ & mut self ,
2334+ block : Block ,
2335+ height : u32 ,
2336+ ) -> Result < ( ) , CannotConnectError >
2337+ where
2338+ D : PersistBackend < ChangeSet > ,
2339+ {
2340+ let chain_update = CheckPoint :: from_header ( & block. header , height) . into_update ( false ) ;
2341+ let mut changeset = ChangeSet :: from ( self . chain . apply_update ( chain_update) ?) ;
2342+ changeset. append ( ChangeSet :: from (
2343+ self . indexed_graph . apply_block_relevant ( block, height) ,
2344+ ) ) ;
2345+ self . persist . stage ( changeset) ;
2346+ Ok ( ( ) )
2347+ }
2348+
2349+ /// Batch insert unconfirmed transactions into the IndexedTxGraph,
2350+ /// filtering out those that are not relevant.
2351+ ///
2352+ /// Read more here: [`self.indexed_graph.batch_insert_relevant_unconfirmed()`]
2353+ pub fn batch_insert_relevant_unconfirmed < ' t > (
2354+ & mut self ,
2355+ unconfirmed_txs : impl IntoIterator < Item = ( & ' t Transaction , u64 ) > ,
2356+ ) where
2357+ D : PersistBackend < ChangeSet > ,
2358+ {
2359+ let indexed_graph_changeset = self
2360+ . indexed_graph
2361+ . batch_insert_relevant_unconfirmed ( unconfirmed_txs) ;
2362+ self . persist . stage ( ChangeSet :: from ( indexed_graph_changeset) ) ;
2363+ }
23302364}
23312365
23322366impl < D > AsRef < bdk_chain:: tx_graph:: TxGraph < ConfirmationTimeHeightAnchor > > for Wallet < D > {
0 commit comments