1
- use crate :: {
2
- hex_utils, ChannelManager , Config , Error , KeysManager , NetworkGraph , UserChannelId , Wallet ,
3
- } ;
1
+ use crate :: { hex_utils, ChannelManager , Config , Error , NetworkGraph , UserChannelId , Wallet } ;
4
2
5
3
use crate :: payment_store:: {
6
4
PaymentDetails , PaymentDetailsUpdate , PaymentDirection , PaymentStatus , PaymentStore ,
@@ -10,9 +8,10 @@ use crate::io::{
10
8
EVENT_QUEUE_PERSISTENCE_KEY , EVENT_QUEUE_PERSISTENCE_PRIMARY_NAMESPACE ,
11
9
EVENT_QUEUE_PERSISTENCE_SECONDARY_NAMESPACE ,
12
10
} ;
13
- use crate :: logger:: { log_debug, log_error, log_info, Logger } ;
11
+ use crate :: logger:: { log_error, log_info, Logger } ;
12
+ use crate :: types:: Sweeper ;
14
13
15
- use lightning:: chain:: chaininterface:: { BroadcasterInterface , ConfirmationTarget , FeeEstimator } ;
14
+ use lightning:: chain:: chaininterface:: ConfirmationTarget ;
16
15
use lightning:: events:: Event as LdkEvent ;
17
16
use lightning:: events:: PaymentPurpose ;
18
17
use lightning:: impl_writeable_tlv_based_enum;
@@ -22,8 +21,8 @@ use lightning::util::errors::APIError;
22
21
use lightning:: util:: persist:: KVStore ;
23
22
use lightning:: util:: ser:: { Readable , ReadableArgs , Writeable , Writer } ;
24
23
25
- use bitcoin:: secp256k1:: { PublicKey , Secp256k1 } ;
26
- use bitcoin:: { LockTime , OutPoint , PackedLockTime } ;
24
+ use bitcoin:: secp256k1:: PublicKey ;
25
+ use bitcoin:: { LockTime , OutPoint } ;
27
26
use rand:: { thread_rng, Rng } ;
28
27
use std:: collections:: VecDeque ;
29
28
use std:: ops:: Deref ;
@@ -246,8 +245,8 @@ where
246
245
event_queue : Arc < EventQueue < K , L > > ,
247
246
channel_manager : Arc < ChannelManager < K > > ,
248
247
network_graph : Arc < NetworkGraph > ,
249
- keys_manager : Arc < KeysManager > ,
250
248
payment_store : Arc < PaymentStore < K , L > > ,
249
+ output_sweeper : Arc < Sweeper < K > > ,
251
250
runtime : Arc < RwLock < Option < tokio:: runtime:: Runtime > > > ,
252
251
logger : L ,
253
252
config : Arc < Config > ,
@@ -260,16 +259,16 @@ where
260
259
pub fn new (
261
260
wallet : Arc < Wallet < bdk:: database:: SqliteDatabase , L > > , event_queue : Arc < EventQueue < K , L > > ,
262
261
channel_manager : Arc < ChannelManager < K > > , network_graph : Arc < NetworkGraph > ,
263
- keys_manager : Arc < KeysManager > , payment_store : Arc < PaymentStore < K , L > > ,
262
+ payment_store : Arc < PaymentStore < K , L > > , output_sweeper : Arc < Sweeper < K > > ,
264
263
runtime : Arc < RwLock < Option < tokio:: runtime:: Runtime > > > , logger : L , config : Arc < Config > ,
265
264
) -> Self {
266
265
Self {
267
266
event_queue,
268
267
wallet,
269
268
channel_manager,
270
269
network_graph,
271
- keys_manager,
272
270
payment_store,
271
+ output_sweeper,
273
272
logger,
274
273
runtime,
275
274
config,
@@ -574,39 +573,7 @@ where
574
573
}
575
574
}
576
575
LdkEvent :: SpendableOutputs { outputs, channel_id : _ } => {
577
- // TODO: We should eventually remember the outputs and supply them to the wallet's coin selection, once BDK allows us to do so.
578
- let destination_address = self . wallet . get_new_address ( ) . unwrap_or_else ( |e| {
579
- log_error ! ( self . logger, "Failed to get destination address: {}" , e) ;
580
- panic ! ( "Failed to get destination address" ) ;
581
- } ) ;
582
-
583
- let output_descriptors = & outputs. iter ( ) . collect :: < Vec < _ > > ( ) ;
584
- let tx_feerate = self
585
- . wallet
586
- . get_est_sat_per_1000_weight ( ConfirmationTarget :: NonAnchorChannelFee ) ;
587
-
588
- // We set nLockTime to the current height to discourage fee sniping.
589
- let cur_height = self . channel_manager . current_best_block ( ) . height ( ) ;
590
- let locktime: PackedLockTime =
591
- LockTime :: from_height ( cur_height) . map_or ( PackedLockTime :: ZERO , |l| l. into ( ) ) ;
592
- let res = self . keys_manager . spend_spendable_outputs (
593
- output_descriptors,
594
- Vec :: new ( ) ,
595
- destination_address. script_pubkey ( ) ,
596
- tx_feerate,
597
- Some ( locktime) ,
598
- & Secp256k1 :: new ( ) ,
599
- ) ;
600
-
601
- match res {
602
- Ok ( Some ( spending_tx) ) => self . wallet . broadcast_transactions ( & [ & spending_tx] ) ,
603
- Ok ( None ) => {
604
- log_debug ! ( self . logger, "Omitted spending static outputs: {:?}" , outputs) ;
605
- }
606
- Err ( err) => {
607
- log_error ! ( self . logger, "Error spending outputs: {:?}" , err) ;
608
- }
609
- }
576
+ self . output_sweeper . add_outputs ( outputs)
610
577
}
611
578
LdkEvent :: OpenChannelRequest {
612
579
temporary_channel_id,
0 commit comments