@@ -15,7 +15,7 @@ use crate::io;
15
15
use crate :: ln:: msgs:: DecodeError ;
16
16
use crate :: ln:: types:: ChannelId ;
17
17
use crate :: prelude:: * ;
18
- use crate :: sign:: { ChangeDestinationSource , OutputSpender , SpendableOutputDescriptor } ;
18
+ use crate :: sign:: { ChangeDestinationSource , ChangeDestinationSourceSync , ChangeDestinationSourceSyncWrapper , OutputSpender , SpendableOutputDescriptor } ;
19
19
use crate :: sync:: Mutex ;
20
20
use crate :: util:: logger:: Logger ;
21
21
use crate :: util:: persist:: {
@@ -33,6 +33,7 @@ use bitcoin::{BlockHash, ScriptBuf, Transaction, Txid};
33
33
use core:: future:: Future ;
34
34
use core:: ops:: Deref ;
35
35
use core:: task;
36
+ use std:: sync:: Arc ;
36
37
37
38
use super :: async_poll:: dummy_waker;
38
39
@@ -356,6 +357,60 @@ where
356
357
logger : L ,
357
358
}
358
359
360
+ pub struct OutputSweeperSync < B : Deref , D : Deref , E : Deref , F : Deref , K : Deref , L : Deref , O : Deref >
361
+ where
362
+ B :: Target : BroadcasterInterface ,
363
+ D :: Target : ChangeDestinationSource ,
364
+ E :: Target : FeeEstimator ,
365
+ F :: Target : Filter + Sync + Send ,
366
+ K :: Target : KVStore ,
367
+ L :: Target : Logger ,
368
+ O :: Target : OutputSpender ,
369
+ {
370
+ sweeper : OutputSweeper < B , D , E , F , K , L , O > ,
371
+ }
372
+
373
+ impl < B : Deref , D : Deref , E : Deref , F : Deref , K : Deref , L : Deref , O : Deref >
374
+ OutputSweeperSync < B , D , E , F , K , L , O >
375
+ where
376
+ B :: Target : BroadcasterInterface ,
377
+ D :: Target : ChangeDestinationSource ,
378
+ E :: Target : FeeEstimator ,
379
+ F :: Target : Filter + Sync + Send ,
380
+ K :: Target : KVStore ,
381
+ L :: Target : Logger ,
382
+ O :: Target : OutputSpender ,
383
+ {
384
+ fn new < DA : ChangeDestinationSourceSync > (
385
+ best_block : BestBlock , broadcaster : B , fee_estimator : E , chain_data_source : Option < F > ,
386
+ output_spender : O , change_destination_source : DA , kv_store : K , logger : L ,
387
+ ) -> Self {
388
+ let change_destination_source = Arc :: new ( ChangeDestinationSourceSyncWrapper :: new ( change_destination_source) ) ;
389
+
390
+ let sweeper = OutputSweeper :: new (
391
+ best_block, broadcaster, fee_estimator, chain_data_source, output_spender,
392
+ change_destination_source, kv_store, logger,
393
+ ) ;
394
+ Self { sweeper }
395
+ }
396
+
397
+ /// Regenerates and broadcasts the spending transaction for any outputs that are pending
398
+ pub fn regenerate_and_broadcast_spend_if_necessary ( & self ) -> Result < ( ) , ( ) > {
399
+ let mut fut = Box :: pin ( self . sweeper . regenerate_and_broadcast_spend_if_necessary_async ( ) ) ;
400
+ let mut waker = dummy_waker ( ) ;
401
+ let mut ctx = task:: Context :: from_waker ( & mut waker) ;
402
+ match fut. as_mut ( ) . poll ( & mut ctx) {
403
+ task:: Poll :: Ready ( result) => {
404
+ result
405
+ } ,
406
+ task:: Poll :: Pending => {
407
+ // In a sync context, we can't wait for the future to complete.
408
+ panic ! ( "task not ready" ) ;
409
+ } ,
410
+ }
411
+ }
412
+ }
413
+
359
414
impl < B : Deref , D : Deref , E : Deref , F : Deref , K : Deref , L : Deref , O : Deref >
360
415
OutputSweeper < B , D , E , F , K , L , O >
361
416
where
0 commit comments