@@ -310,7 +310,7 @@ impl Wallet {
310
310
#[ cfg( debug_assertions) ]
311
311
if balance. confirmed != Amount :: ZERO {
312
312
debug_assert ! (
313
- self . list_confirmed_utxos ( ) . map_or( false , |v| !v. is_empty( ) ) ,
313
+ self . list_confirmed_utxos_inner ( ) . map_or( false , |v| !v. is_empty( ) ) ,
314
314
"Confirmed amounts should always be available for Anchor spending"
315
315
) ;
316
316
}
@@ -560,70 +560,8 @@ impl Wallet {
560
560
561
561
Ok ( txid)
562
562
}
563
- }
564
-
565
- impl Listen for Wallet {
566
- fn filtered_block_connected (
567
- & self , _header : & bitcoin:: block:: Header ,
568
- _txdata : & lightning:: chain:: transaction:: TransactionData , _height : u32 ,
569
- ) {
570
- debug_assert ! ( false , "Syncing filtered blocks is currently not supported" ) ;
571
- // As far as we can tell this would be a no-op anyways as we don't have to tell BDK about
572
- // the header chain of intermediate blocks. According to the BDK team, it's sufficient to
573
- // only connect full blocks starting from the last point of disagreement.
574
- }
575
-
576
- fn block_connected ( & self , block : & bitcoin:: Block , height : u32 ) {
577
- let mut locked_wallet = self . inner . lock ( ) . unwrap ( ) ;
578
-
579
- let pre_checkpoint = locked_wallet. latest_checkpoint ( ) ;
580
- if pre_checkpoint. height ( ) != height - 1
581
- || pre_checkpoint. hash ( ) != block. header . prev_blockhash
582
- {
583
- log_debug ! (
584
- self . logger,
585
- "Detected reorg while applying a connected block to on-chain wallet: new block with hash {} at height {}" ,
586
- block. header. block_hash( ) ,
587
- height
588
- ) ;
589
- }
590
-
591
- match locked_wallet. apply_block ( block, height) {
592
- Ok ( ( ) ) => {
593
- if let Err ( e) = self . update_payment_store ( & mut * locked_wallet) {
594
- log_error ! ( self . logger, "Failed to update payment store: {}" , e) ;
595
- return ;
596
- }
597
- } ,
598
- Err ( e) => {
599
- log_error ! (
600
- self . logger,
601
- "Failed to apply connected block to on-chain wallet: {}" ,
602
- e
603
- ) ;
604
- return ;
605
- } ,
606
- } ;
607
563
608
- let mut locked_persister = self . persister . lock ( ) . unwrap ( ) ;
609
- match locked_wallet. persist ( & mut locked_persister) {
610
- Ok ( _) => ( ) ,
611
- Err ( e) => {
612
- log_error ! ( self . logger, "Failed to persist on-chain wallet: {}" , e) ;
613
- return ;
614
- } ,
615
- } ;
616
- }
617
-
618
- fn block_disconnected ( & self , _header : & bitcoin:: block:: Header , _height : u32 ) {
619
- // This is a no-op as we don't have to tell BDK about disconnections. According to the BDK
620
- // team, it's sufficient in case of a reorg to always connect blocks starting from the last
621
- // point of disagreement.
622
- }
623
- }
624
-
625
- impl WalletSource for Wallet {
626
- fn list_confirmed_utxos ( & self ) -> Result < Vec < Utxo > , ( ) > {
564
+ fn list_confirmed_utxos_inner ( & self ) -> Result < Vec < Utxo > , ( ) > {
627
565
let locked_wallet = self . inner . lock ( ) . unwrap ( ) ;
628
566
let mut utxos = Vec :: new ( ) ;
629
567
let confirmed_txs: Vec < Txid > = locked_wallet
@@ -715,7 +653,7 @@ impl WalletSource for Wallet {
715
653
Ok ( utxos)
716
654
}
717
655
718
- fn get_change_script ( & self ) -> Result < ScriptBuf , ( ) > {
656
+ fn get_change_script_inner ( & self ) -> Result < ScriptBuf , ( ) > {
719
657
let mut locked_wallet = self . inner . lock ( ) . unwrap ( ) ;
720
658
let mut locked_persister = self . persister . lock ( ) . unwrap ( ) ;
721
659
@@ -727,7 +665,7 @@ impl WalletSource for Wallet {
727
665
Ok ( address_info. address . script_pubkey ( ) )
728
666
}
729
667
730
- fn sign_psbt ( & self , mut psbt : Psbt ) -> Result < Transaction , ( ) > {
668
+ fn sign_psbt_inner ( & self , mut psbt : Psbt ) -> Result < Transaction , ( ) > {
731
669
let locked_wallet = self . inner . lock ( ) . unwrap ( ) ;
732
670
733
671
// While BDK populates both `witness_utxo` and `non_witness_utxo` fields, LDK does not. As
@@ -757,6 +695,86 @@ impl WalletSource for Wallet {
757
695
}
758
696
}
759
697
698
+ impl Listen for Wallet {
699
+ fn filtered_block_connected (
700
+ & self , _header : & bitcoin:: block:: Header ,
701
+ _txdata : & lightning:: chain:: transaction:: TransactionData , _height : u32 ,
702
+ ) {
703
+ debug_assert ! ( false , "Syncing filtered blocks is currently not supported" ) ;
704
+ // As far as we can tell this would be a no-op anyways as we don't have to tell BDK about
705
+ // the header chain of intermediate blocks. According to the BDK team, it's sufficient to
706
+ // only connect full blocks starting from the last point of disagreement.
707
+ }
708
+
709
+ fn block_connected ( & self , block : & bitcoin:: Block , height : u32 ) {
710
+ let mut locked_wallet = self . inner . lock ( ) . unwrap ( ) ;
711
+
712
+ let pre_checkpoint = locked_wallet. latest_checkpoint ( ) ;
713
+ if pre_checkpoint. height ( ) != height - 1
714
+ || pre_checkpoint. hash ( ) != block. header . prev_blockhash
715
+ {
716
+ log_debug ! (
717
+ self . logger,
718
+ "Detected reorg while applying a connected block to on-chain wallet: new block with hash {} at height {}" ,
719
+ block. header. block_hash( ) ,
720
+ height
721
+ ) ;
722
+ }
723
+
724
+ match locked_wallet. apply_block ( block, height) {
725
+ Ok ( ( ) ) => {
726
+ if let Err ( e) = self . update_payment_store ( & mut * locked_wallet) {
727
+ log_error ! ( self . logger, "Failed to update payment store: {}" , e) ;
728
+ return ;
729
+ }
730
+ } ,
731
+ Err ( e) => {
732
+ log_error ! (
733
+ self . logger,
734
+ "Failed to apply connected block to on-chain wallet: {}" ,
735
+ e
736
+ ) ;
737
+ return ;
738
+ } ,
739
+ } ;
740
+
741
+ let mut locked_persister = self . persister . lock ( ) . unwrap ( ) ;
742
+ match locked_wallet. persist ( & mut locked_persister) {
743
+ Ok ( _) => ( ) ,
744
+ Err ( e) => {
745
+ log_error ! ( self . logger, "Failed to persist on-chain wallet: {}" , e) ;
746
+ return ;
747
+ } ,
748
+ } ;
749
+ }
750
+
751
+ fn block_disconnected ( & self , _header : & bitcoin:: block:: Header , _height : u32 ) {
752
+ // This is a no-op as we don't have to tell BDK about disconnections. According to the BDK
753
+ // team, it's sufficient in case of a reorg to always connect blocks starting from the last
754
+ // point of disagreement.
755
+ }
756
+ }
757
+
758
+ impl WalletSource for Wallet {
759
+ fn list_confirmed_utxos < ' a > (
760
+ & ' a self ,
761
+ ) -> Pin < Box < dyn Future < Output = Result < Vec < Utxo > , ( ) > > + Send + ' a > > {
762
+ Box :: pin ( async move { self . list_confirmed_utxos_inner ( ) } )
763
+ }
764
+
765
+ fn get_change_script < ' a > (
766
+ & ' a self ,
767
+ ) -> Pin < Box < dyn Future < Output = Result < ScriptBuf , ( ) > > + Send + ' a > > {
768
+ Box :: pin ( async move { self . get_change_script_inner ( ) } )
769
+ }
770
+
771
+ fn sign_psbt < ' a > (
772
+ & ' a self , psbt : Psbt ,
773
+ ) -> Pin < Box < dyn Future < Output = Result < Transaction , ( ) > > + Send + ' a > > {
774
+ Box :: pin ( async move { self . sign_psbt_inner ( psbt) } )
775
+ }
776
+ }
777
+
760
778
/// Similar to [`KeysManager`], but overrides the destination and shutdown scripts so they are
761
779
/// directly spendable by the BDK wallet.
762
780
pub ( crate ) struct WalletKeysManager {
0 commit comments