@@ -299,7 +299,7 @@ impl Wallet {
299299 #[ cfg( debug_assertions) ]
300300 if balance. confirmed != Amount :: ZERO {
301301 debug_assert ! (
302- self . list_confirmed_utxos ( ) . map_or( false , |v| !v. is_empty( ) ) ,
302+ self . list_confirmed_utxos_inner ( ) . map_or( false , |v| !v. is_empty( ) ) ,
303303 "Confirmed amounts should always be available for Anchor spending"
304304 ) ;
305305 }
@@ -549,70 +549,8 @@ impl Wallet {
549549
550550 Ok ( txid)
551551 }
552- }
553-
554- impl Listen for Wallet {
555- fn filtered_block_connected (
556- & self , _header : & bitcoin:: block:: Header ,
557- _txdata : & lightning:: chain:: transaction:: TransactionData , _height : u32 ,
558- ) {
559- debug_assert ! ( false , "Syncing filtered blocks is currently not supported" ) ;
560- // As far as we can tell this would be a no-op anyways as we don't have to tell BDK about
561- // the header chain of intermediate blocks. According to the BDK team, it's sufficient to
562- // only connect full blocks starting from the last point of disagreement.
563- }
564-
565- fn block_connected ( & self , block : & bitcoin:: Block , height : u32 ) {
566- let mut locked_wallet = self . inner . lock ( ) . unwrap ( ) ;
567-
568- let pre_checkpoint = locked_wallet. latest_checkpoint ( ) ;
569- if pre_checkpoint. height ( ) != height - 1
570- || pre_checkpoint. hash ( ) != block. header . prev_blockhash
571- {
572- log_debug ! (
573- self . logger,
574- "Detected reorg while applying a connected block to on-chain wallet: new block with hash {} at height {}" ,
575- block. header. block_hash( ) ,
576- height
577- ) ;
578- }
579-
580- match locked_wallet. apply_block ( block, height) {
581- Ok ( ( ) ) => {
582- if let Err ( e) = self . update_payment_store ( & mut * locked_wallet) {
583- log_error ! ( self . logger, "Failed to update payment store: {}" , e) ;
584- return ;
585- }
586- } ,
587- Err ( e) => {
588- log_error ! (
589- self . logger,
590- "Failed to apply connected block to on-chain wallet: {}" ,
591- e
592- ) ;
593- return ;
594- } ,
595- } ;
596552
597- let mut locked_persister = self . persister . lock ( ) . unwrap ( ) ;
598- match locked_wallet. persist ( & mut locked_persister) {
599- Ok ( _) => ( ) ,
600- Err ( e) => {
601- log_error ! ( self . logger, "Failed to persist on-chain wallet: {}" , e) ;
602- return ;
603- } ,
604- } ;
605- }
606-
607- fn block_disconnected ( & self , _header : & bitcoin:: block:: Header , _height : u32 ) {
608- // This is a no-op as we don't have to tell BDK about disconnections. According to the BDK
609- // team, it's sufficient in case of a reorg to always connect blocks starting from the last
610- // point of disagreement.
611- }
612- }
613-
614- impl WalletSource for Wallet {
615- fn list_confirmed_utxos ( & self ) -> Result < Vec < Utxo > , ( ) > {
553+ fn list_confirmed_utxos_inner ( & self ) -> Result < Vec < Utxo > , ( ) > {
616554 let locked_wallet = self . inner . lock ( ) . unwrap ( ) ;
617555 let mut utxos = Vec :: new ( ) ;
618556 let confirmed_txs: Vec < Txid > = locked_wallet
@@ -704,7 +642,7 @@ impl WalletSource for Wallet {
704642 Ok ( utxos)
705643 }
706644
707- fn get_change_script ( & self ) -> Result < ScriptBuf , ( ) > {
645+ fn get_change_script_inner ( & self ) -> Result < ScriptBuf , ( ) > {
708646 let mut locked_wallet = self . inner . lock ( ) . unwrap ( ) ;
709647 let mut locked_persister = self . persister . lock ( ) . unwrap ( ) ;
710648
@@ -716,7 +654,7 @@ impl WalletSource for Wallet {
716654 Ok ( address_info. address . script_pubkey ( ) )
717655 }
718656
719- fn sign_psbt ( & self , mut psbt : Psbt ) -> Result < Transaction , ( ) > {
657+ fn sign_psbt_inner ( & self , mut psbt : Psbt ) -> Result < Transaction , ( ) > {
720658 let locked_wallet = self . inner . lock ( ) . unwrap ( ) ;
721659
722660 // While BDK populates both `witness_utxo` and `non_witness_utxo` fields, LDK does not. As
@@ -746,6 +684,86 @@ impl WalletSource for Wallet {
746684 }
747685}
748686
687+ impl Listen for Wallet {
688+ fn filtered_block_connected (
689+ & self , _header : & bitcoin:: block:: Header ,
690+ _txdata : & lightning:: chain:: transaction:: TransactionData , _height : u32 ,
691+ ) {
692+ debug_assert ! ( false , "Syncing filtered blocks is currently not supported" ) ;
693+ // As far as we can tell this would be a no-op anyways as we don't have to tell BDK about
694+ // the header chain of intermediate blocks. According to the BDK team, it's sufficient to
695+ // only connect full blocks starting from the last point of disagreement.
696+ }
697+
698+ fn block_connected ( & self , block : & bitcoin:: Block , height : u32 ) {
699+ let mut locked_wallet = self . inner . lock ( ) . unwrap ( ) ;
700+
701+ let pre_checkpoint = locked_wallet. latest_checkpoint ( ) ;
702+ if pre_checkpoint. height ( ) != height - 1
703+ || pre_checkpoint. hash ( ) != block. header . prev_blockhash
704+ {
705+ log_debug ! (
706+ self . logger,
707+ "Detected reorg while applying a connected block to on-chain wallet: new block with hash {} at height {}" ,
708+ block. header. block_hash( ) ,
709+ height
710+ ) ;
711+ }
712+
713+ match locked_wallet. apply_block ( block, height) {
714+ Ok ( ( ) ) => {
715+ if let Err ( e) = self . update_payment_store ( & mut * locked_wallet) {
716+ log_error ! ( self . logger, "Failed to update payment store: {}" , e) ;
717+ return ;
718+ }
719+ } ,
720+ Err ( e) => {
721+ log_error ! (
722+ self . logger,
723+ "Failed to apply connected block to on-chain wallet: {}" ,
724+ e
725+ ) ;
726+ return ;
727+ } ,
728+ } ;
729+
730+ let mut locked_persister = self . persister . lock ( ) . unwrap ( ) ;
731+ match locked_wallet. persist ( & mut locked_persister) {
732+ Ok ( _) => ( ) ,
733+ Err ( e) => {
734+ log_error ! ( self . logger, "Failed to persist on-chain wallet: {}" , e) ;
735+ return ;
736+ } ,
737+ } ;
738+ }
739+
740+ fn block_disconnected ( & self , _header : & bitcoin:: block:: Header , _height : u32 ) {
741+ // This is a no-op as we don't have to tell BDK about disconnections. According to the BDK
742+ // team, it's sufficient in case of a reorg to always connect blocks starting from the last
743+ // point of disagreement.
744+ }
745+ }
746+
747+ impl WalletSource for Wallet {
748+ fn list_confirmed_utxos < ' a > (
749+ & ' a self ,
750+ ) -> Pin < Box < dyn Future < Output = Result < Vec < Utxo > , ( ) > > + Send + ' a > > {
751+ Box :: pin ( async move { self . list_confirmed_utxos_inner ( ) } )
752+ }
753+
754+ fn get_change_script < ' a > (
755+ & ' a self ,
756+ ) -> Pin < Box < dyn Future < Output = Result < ScriptBuf , ( ) > > + Send + ' a > > {
757+ Box :: pin ( async move { self . get_change_script_inner ( ) } )
758+ }
759+
760+ fn sign_psbt < ' a > (
761+ & ' a self , psbt : Psbt ,
762+ ) -> Pin < Box < dyn Future < Output = Result < Transaction , ( ) > > + Send + ' a > > {
763+ Box :: pin ( async move { self . sign_psbt_inner ( psbt) } )
764+ }
765+ }
766+
749767/// Similar to [`KeysManager`], but overrides the destination and shutdown scripts so they are
750768/// directly spendable by the BDK wallet.
751769pub ( crate ) struct WalletKeysManager {
0 commit comments