@@ -827,55 +827,6 @@ pub enum SpendingDelay {
827
827
} ,
828
828
}
829
829
830
- impl < B : Deref , D : Deref , E : Deref , F : Deref , K : Deref , L : Deref , O : Deref >
831
- ReadableArgs < ( B , E , Option < F > , O , D , K , L ) > for OutputSweeper < B , D , E , F , K , L , O >
832
- where
833
- B :: Target : BroadcasterInterface ,
834
- D :: Target : ChangeDestinationSource ,
835
- E :: Target : FeeEstimator ,
836
- F :: Target : Filter + Sync + Send ,
837
- K :: Target : KVStore ,
838
- L :: Target : Logger ,
839
- O :: Target : OutputSpender ,
840
- {
841
- #[ inline]
842
- fn read < R : io:: Read > (
843
- reader : & mut R , args : ( B , E , Option < F > , O , D , K , L ) ,
844
- ) -> Result < Self , DecodeError > {
845
- let (
846
- broadcaster,
847
- fee_estimator,
848
- chain_data_source,
849
- output_spender,
850
- change_destination_source,
851
- kv_store,
852
- logger,
853
- ) = args;
854
- let state = SweeperState :: read ( reader) ?;
855
- let best_block = state. best_block ;
856
-
857
- if let Some ( filter) = chain_data_source. as_ref ( ) {
858
- for output_info in & state. outputs {
859
- let watched_output = output_info. to_watched_output ( best_block. block_hash ) ;
860
- filter. register_output ( watched_output) ;
861
- }
862
- }
863
-
864
- let sweeper_state = Mutex :: new ( state) ;
865
- Ok ( Self {
866
- sweeper_state,
867
- pending_sweep : AtomicBool :: new ( false ) ,
868
- broadcaster,
869
- fee_estimator,
870
- chain_data_source,
871
- output_spender,
872
- change_destination_source,
873
- kv_store,
874
- logger,
875
- } )
876
- }
877
- }
878
-
879
830
impl < B : Deref , D : Deref , E : Deref , F : Deref , K : Deref , L : Deref , O : Deref >
880
831
ReadableArgs < ( B , E , Option < F > , O , D , K , L ) > for ( BestBlock , OutputSweeper < B , D , E , F , K , L , O > )
881
832
where
@@ -977,21 +928,6 @@ where
977
928
Self { sweeper }
978
929
}
979
930
980
- /// Regenerates and broadcasts the spending transaction for any outputs that are pending. Wraps
981
- /// [`OutputSweeper::regenerate_and_broadcast_spend_if_necessary`].
982
- pub fn regenerate_and_broadcast_spend_if_necessary ( & self ) -> Result < ( ) , ( ) > {
983
- let mut fut = Box :: pin ( self . sweeper . regenerate_and_broadcast_spend_if_necessary ( ) ) ;
984
- let mut waker = dummy_waker ( ) ;
985
- let mut ctx = task:: Context :: from_waker ( & mut waker) ;
986
- match fut. as_mut ( ) . poll ( & mut ctx) {
987
- task:: Poll :: Ready ( result) => result,
988
- task:: Poll :: Pending => {
989
- // In a sync context, we can't wait for the future to complete.
990
- unreachable ! ( "OutputSweeper::regenerate_and_broadcast_spend_if_necessary should not be pending in a sync context" ) ;
991
- } ,
992
- }
993
- }
994
-
995
931
/// Wrapper around [`OutputSweeper::track_spendable_outputs`].
996
932
pub fn track_spendable_outputs (
997
933
& self , output_descriptors : Vec < SpendableOutputDescriptor > , channel_id : Option < ChannelId > ,
@@ -1019,6 +955,27 @@ where
1019
955
self . sweeper . tracked_spendable_outputs ( )
1020
956
}
1021
957
958
+ /// Gets the latest best block which was connected either via [`Listen`] or [`Confirm`]
959
+ /// interfaces.
960
+ pub fn current_best_block ( & self ) -> BestBlock {
961
+ self . sweeper . current_best_block ( )
962
+ }
963
+
964
+ /// Regenerates and broadcasts the spending transaction for any outputs that are pending. Wraps
965
+ /// [`OutputSweeper::regenerate_and_broadcast_spend_if_necessary`].
966
+ pub fn regenerate_and_broadcast_spend_if_necessary ( & self ) -> Result < ( ) , ( ) > {
967
+ let mut fut = Box :: pin ( self . sweeper . regenerate_and_broadcast_spend_if_necessary ( ) ) ;
968
+ let mut waker = dummy_waker ( ) ;
969
+ let mut ctx = task:: Context :: from_waker ( & mut waker) ;
970
+ match fut. as_mut ( ) . poll ( & mut ctx) {
971
+ task:: Poll :: Ready ( result) => result,
972
+ task:: Poll :: Pending => {
973
+ // In a sync context, we can't wait for the future to complete.
974
+ unreachable ! ( "OutputSweeper::regenerate_and_broadcast_spend_if_necessary should not be pending in a sync context" ) ;
975
+ } ,
976
+ }
977
+ }
978
+
1022
979
/// Fetch the inner async sweeper.
1023
980
///
1024
981
/// In general you shouldn't have much reason to use this - you have a sync [`KVStore`] backing
@@ -1034,6 +991,28 @@ where
1034
991
}
1035
992
}
1036
993
994
+ impl < B : Deref , D : Deref , E : Deref , F : Deref , K : Deref , L : Deref , O : Deref > Listen
995
+ for OutputSweeperSync < B , D , E , F , K , L , O >
996
+ where
997
+ B :: Target : BroadcasterInterface ,
998
+ D :: Target : ChangeDestinationSourceSync ,
999
+ E :: Target : FeeEstimator ,
1000
+ F :: Target : Filter + Sync + Send ,
1001
+ K :: Target : KVStoreSync ,
1002
+ L :: Target : Logger ,
1003
+ O :: Target : OutputSpender ,
1004
+ {
1005
+ fn filtered_block_connected (
1006
+ & self , header : & Header , txdata : & chain:: transaction:: TransactionData , height : u32 ,
1007
+ ) {
1008
+ self . sweeper . filtered_block_connected ( header, txdata, height) ;
1009
+ }
1010
+
1011
+ fn blocks_disconnected ( & self , fork_point : BestBlock ) {
1012
+ self . sweeper . blocks_disconnected ( fork_point) ;
1013
+ }
1014
+ }
1015
+
1037
1016
impl < B : Deref , D : Deref , E : Deref , F : Deref , K : Deref , L : Deref , O : Deref > Confirm
1038
1017
for OutputSweeperSync < B , D , E , F , K , L , O >
1039
1018
where
@@ -1063,3 +1042,29 @@ where
1063
1042
self . sweeper . get_relevant_txids ( )
1064
1043
}
1065
1044
}
1045
+
1046
+ impl < B : Deref , D : Deref , E : Deref , F : Deref , K : Deref , L : Deref , O : Deref >
1047
+ ReadableArgs < ( B , E , Option < F > , O , D , K , L ) > for ( BestBlock , OutputSweeperSync < B , D , E , F , K , L , O > )
1048
+ where
1049
+ B :: Target : BroadcasterInterface ,
1050
+ D :: Target : ChangeDestinationSourceSync ,
1051
+ E :: Target : FeeEstimator ,
1052
+ F :: Target : Filter + Sync + Send ,
1053
+ K :: Target : KVStoreSync ,
1054
+ L :: Target : Logger ,
1055
+ O :: Target : OutputSpender ,
1056
+ {
1057
+ #[ inline]
1058
+ fn read < R : io:: Read > (
1059
+ reader : & mut R , args : ( B , E , Option < F > , O , D , K , L ) ,
1060
+ ) -> Result < Self , DecodeError > {
1061
+ let ( a, b, c, d, change_destination_source, kv_store, e) = args;
1062
+ let change_destination_source =
1063
+ ChangeDestinationSourceSyncWrapper :: new ( change_destination_source) ;
1064
+ let kv_store = KVStoreSyncWrapper ( kv_store) ;
1065
+ let args = ( a, b, c, d, change_destination_source, kv_store, e) ;
1066
+ let ( best_block, sweeper) =
1067
+ <( BestBlock , OutputSweeper < _ , _ , _ , _ , _ , _ , _ > ) >:: read ( reader, args) ?;
1068
+ Ok ( ( best_block, OutputSweeperSync { sweeper } ) )
1069
+ }
1070
+ }
0 commit comments