6
6
// accordance with one or both of these licenses.
7
7
8
8
use crate :: types:: { CustomTlvRecord , DynStore , PaymentStore , Sweeper , Wallet } ;
9
-
10
9
use crate :: {
11
10
hex_utils, BumpTransactionEventHandler , ChannelManager , Error , Graph , PeerInfo , PeerStore ,
12
11
UserChannelId ,
@@ -19,6 +18,7 @@ use crate::fee_estimator::ConfirmationTarget;
19
18
use crate :: liquidity:: LiquiditySource ;
20
19
use crate :: logger:: Logger ;
21
20
21
+ use crate :: payment:: asynchronous:: static_invoice_store:: StaticInvoiceStore ;
22
22
use crate :: payment:: store:: {
23
23
PaymentDetails , PaymentDetailsUpdate , PaymentDirection , PaymentKind , PaymentStatus ,
24
24
} ;
@@ -27,7 +27,7 @@ use crate::io::{
27
27
EVENT_QUEUE_PERSISTENCE_KEY , EVENT_QUEUE_PERSISTENCE_PRIMARY_NAMESPACE ,
28
28
EVENT_QUEUE_PERSISTENCE_SECONDARY_NAMESPACE ,
29
29
} ;
30
- use crate :: logger:: { log_debug, log_error, log_info, LdkLogger } ;
30
+ use crate :: logger:: { log_debug, log_error, log_info, log_trace , LdkLogger } ;
31
31
32
32
use crate :: runtime:: Runtime ;
33
33
@@ -458,6 +458,7 @@ where
458
458
runtime : Arc < Runtime > ,
459
459
logger : L ,
460
460
config : Arc < Config > ,
461
+ static_invoice_store : Option < StaticInvoiceStore > ,
461
462
}
462
463
463
464
impl < L : Deref + Clone + Sync + Send + ' static > EventHandler < L >
@@ -470,8 +471,9 @@ where
470
471
channel_manager : Arc < ChannelManager > , connection_manager : Arc < ConnectionManager < L > > ,
471
472
output_sweeper : Arc < Sweeper > , network_graph : Arc < Graph > ,
472
473
liquidity_source : Option < Arc < LiquiditySource < Arc < Logger > > > > ,
473
- payment_store : Arc < PaymentStore > , peer_store : Arc < PeerStore < L > > , runtime : Arc < Runtime > ,
474
- logger : L , config : Arc < Config > ,
474
+ payment_store : Arc < PaymentStore > , peer_store : Arc < PeerStore < L > > ,
475
+ static_invoice_store : Option < StaticInvoiceStore > , runtime : Arc < Runtime > , logger : L ,
476
+ config : Arc < Config > ,
475
477
) -> Self {
476
478
Self {
477
479
event_queue,
@@ -487,6 +489,7 @@ where
487
489
logger,
488
490
runtime,
489
491
config,
492
+ static_invoice_store,
490
493
}
491
494
}
492
495
@@ -1494,11 +1497,55 @@ where
1494
1497
LdkEvent :: OnionMessagePeerConnected { .. } => {
1495
1498
debug_assert ! ( false , "We currently don't support onion message interception, so this event should never be emitted." ) ;
1496
1499
} ,
1497
- LdkEvent :: PersistStaticInvoice { .. } => {
1498
- debug_assert ! ( false , "We currently don't support static invoice persistence, so this event should never be emitted." ) ;
1500
+
1501
+ LdkEvent :: PersistStaticInvoice {
1502
+ invoice,
1503
+ invoice_slot,
1504
+ recipient_id,
1505
+ invoice_persisted_path,
1506
+ } => {
1507
+ if let Some ( store) = self . static_invoice_store . as_ref ( ) {
1508
+ match store
1509
+ . handle_persist_static_invoice ( invoice, invoice_slot, recipient_id)
1510
+ . await
1511
+ {
1512
+ Ok ( _) => {
1513
+ self . channel_manager . static_invoice_persisted ( invoice_persisted_path) ;
1514
+ } ,
1515
+ Err ( e) => {
1516
+ log_error ! ( self . logger, "Failed to persist static invoice: {}" , e) ;
1517
+ return Err ( ReplayEvent ( ) ) ;
1518
+ } ,
1519
+ } ;
1520
+ }
1499
1521
} ,
1500
- LdkEvent :: StaticInvoiceRequested { .. } => {
1501
- debug_assert ! ( false , "We currently don't support static invoice persistence, so this event should never be emitted." ) ;
1522
+ LdkEvent :: StaticInvoiceRequested { recipient_id, invoice_slot, reply_path } => {
1523
+ if let Some ( store) = self . static_invoice_store . as_ref ( ) {
1524
+ let invoice =
1525
+ store. handle_static_invoice_requested ( & recipient_id, invoice_slot) . await ;
1526
+
1527
+ match invoice {
1528
+ Ok ( Some ( invoice) ) => {
1529
+ if let Err ( e) =
1530
+ self . channel_manager . send_static_invoice ( invoice, reply_path)
1531
+ {
1532
+ log_error ! ( self . logger, "Failed to send static invoice: {:?}" , e) ;
1533
+ }
1534
+ } ,
1535
+ Ok ( None ) => {
1536
+ log_trace ! (
1537
+ self . logger,
1538
+ "No static invoice found for recipient {} and slot {}" ,
1539
+ hex_utils:: to_string( & recipient_id) ,
1540
+ invoice_slot
1541
+ ) ;
1542
+ } ,
1543
+ Err ( e) => {
1544
+ log_error ! ( self . logger, "Failed to retrieve static invoice: {}" , e) ;
1545
+ return Err ( ReplayEvent ( ) ) ;
1546
+ } ,
1547
+ }
1548
+ }
1502
1549
} ,
1503
1550
LdkEvent :: FundingTransactionReadyForSigning { .. } => {
1504
1551
debug_assert ! ( false , "We currently don't support interactive-tx, so this event should never be emitted." ) ;
0 commit comments