1
1
use crate :: {
2
- hex_utils, ChannelId , ChannelManager , Config , Error , KeysManager , NetworkGraph , UserChannelId ,
3
- Wallet ,
2
+ hex_utils, ChannelId , ChannelManager , Config , Error , NetworkGraph , UserChannelId , Wallet ,
4
3
} ;
5
4
6
5
use crate :: payment_store:: {
7
6
PaymentDetails , PaymentDetailsUpdate , PaymentDirection , PaymentStatus , PaymentStore ,
8
7
} ;
9
8
10
9
use crate :: io:: { KVStore , EVENT_QUEUE_PERSISTENCE_KEY , EVENT_QUEUE_PERSISTENCE_NAMESPACE } ;
11
- use crate :: logger:: { log_debug, log_error, log_info, Logger } ;
10
+ use crate :: logger:: { log_error, log_info, Logger } ;
11
+ use crate :: types:: Sweeper ;
12
12
13
- use lightning:: chain:: chaininterface:: { BroadcasterInterface , ConfirmationTarget , FeeEstimator } ;
13
+ use lightning:: chain:: chaininterface:: ConfirmationTarget ;
14
14
use lightning:: events:: Event as LdkEvent ;
15
15
use lightning:: events:: PaymentPurpose ;
16
16
use lightning:: impl_writeable_tlv_based_enum;
@@ -19,8 +19,8 @@ use lightning::routing::gossip::NodeId;
19
19
use lightning:: util:: errors:: APIError ;
20
20
use lightning:: util:: ser:: { Readable , ReadableArgs , Writeable , Writer } ;
21
21
22
- use bitcoin:: secp256k1:: { PublicKey , Secp256k1 } ;
23
- use bitcoin:: { LockTime , OutPoint , PackedLockTime } ;
22
+ use bitcoin:: secp256k1:: PublicKey ;
23
+ use bitcoin:: { LockTime , OutPoint } ;
24
24
use rand:: { thread_rng, Rng } ;
25
25
use std:: collections:: VecDeque ;
26
26
use std:: ops:: Deref ;
@@ -227,8 +227,8 @@ where
227
227
event_queue : Arc < EventQueue < K , L > > ,
228
228
channel_manager : Arc < ChannelManager < K > > ,
229
229
network_graph : Arc < NetworkGraph > ,
230
- keys_manager : Arc < KeysManager > ,
231
230
payment_store : Arc < PaymentStore < K , L > > ,
231
+ output_sweeper : Arc < Sweeper < K > > ,
232
232
runtime : Arc < RwLock < Option < tokio:: runtime:: Runtime > > > ,
233
233
logger : L ,
234
234
config : Arc < Config > ,
@@ -241,16 +241,16 @@ where
241
241
pub fn new (
242
242
wallet : Arc < Wallet < bdk:: database:: SqliteDatabase , L > > , event_queue : Arc < EventQueue < K , L > > ,
243
243
channel_manager : Arc < ChannelManager < K > > , network_graph : Arc < NetworkGraph > ,
244
- keys_manager : Arc < KeysManager > , payment_store : Arc < PaymentStore < K , L > > ,
244
+ payment_store : Arc < PaymentStore < K , L > > , output_sweeper : Arc < Sweeper < K > > ,
245
245
runtime : Arc < RwLock < Option < tokio:: runtime:: Runtime > > > , logger : L , config : Arc < Config > ,
246
246
) -> Self {
247
247
Self {
248
248
event_queue,
249
249
wallet,
250
250
channel_manager,
251
251
network_graph,
252
- keys_manager,
253
252
payment_store,
253
+ output_sweeper,
254
254
logger,
255
255
runtime,
256
256
config,
@@ -552,40 +552,7 @@ where
552
552
} ) ;
553
553
}
554
554
}
555
- LdkEvent :: SpendableOutputs { outputs } => {
556
- // TODO: We should eventually remember the outputs and supply them to the wallet's coin selection, once BDK allows us to do so.
557
- let destination_address = self . wallet . get_new_address ( ) . unwrap_or_else ( |e| {
558
- log_error ! ( self . logger, "Failed to get destination address: {}" , e) ;
559
- panic ! ( "Failed to get destination address" ) ;
560
- } ) ;
561
-
562
- let output_descriptors = & outputs. iter ( ) . collect :: < Vec < _ > > ( ) ;
563
- let tx_feerate =
564
- self . wallet . get_est_sat_per_1000_weight ( ConfirmationTarget :: Normal ) ;
565
-
566
- // We set nLockTime to the current height to discourage fee sniping.
567
- let cur_height = self . channel_manager . current_best_block ( ) . height ( ) ;
568
- let locktime: PackedLockTime =
569
- LockTime :: from_height ( cur_height) . map_or ( PackedLockTime :: ZERO , |l| l. into ( ) ) ;
570
- let res = self . keys_manager . spend_spendable_outputs (
571
- output_descriptors,
572
- Vec :: new ( ) ,
573
- destination_address. script_pubkey ( ) ,
574
- tx_feerate,
575
- Some ( locktime) ,
576
- & Secp256k1 :: new ( ) ,
577
- ) ;
578
-
579
- match res {
580
- Ok ( Some ( spending_tx) ) => self . wallet . broadcast_transactions ( & [ & spending_tx] ) ,
581
- Ok ( None ) => {
582
- log_debug ! ( self . logger, "Omitted spending static outputs: {:?}" , outputs) ;
583
- }
584
- Err ( err) => {
585
- log_error ! ( self . logger, "Error spending outputs: {:?}" , err) ;
586
- }
587
- }
588
- }
555
+ LdkEvent :: SpendableOutputs { outputs } => self . output_sweeper . add_outputs ( outputs) ,
589
556
LdkEvent :: OpenChannelRequest {
590
557
temporary_channel_id,
591
558
counterparty_node_id,
0 commit comments