5
5
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
6
6
// accordance with one or both of these licenses.
7
7
8
+ use crate :: payment:: asynchronous:: static_invoice_store:: StaticInvoiceStore ;
8
9
use crate :: types:: { CustomTlvRecord , DynStore , PaymentStore , Sweeper , Wallet } ;
9
-
10
10
use crate :: {
11
11
hex_utils, BumpTransactionEventHandler , ChannelManager , Error , Graph , PeerInfo , PeerStore ,
12
12
UserChannelId ,
@@ -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,46 @@ 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
+ Err ( e) => {
1514
+ log_error ! ( self . logger, "Failed to persist static invoice: {}" , e) ;
1515
+ } ,
1516
+ } ;
1517
+
1518
+ self . channel_manager . static_invoice_persisted ( invoice_persisted_path) ;
1519
+ }
1499
1520
} ,
1500
- LdkEvent :: StaticInvoiceRequested { .. } => {
1501
- debug_assert ! ( false , "We currently don't support static invoice persistence, so this event should never be emitted." ) ;
1521
+ LdkEvent :: StaticInvoiceRequested { recipient_id, invoice_slot, reply_path } => {
1522
+ if let Some ( store) = self . static_invoice_store . as_ref ( ) {
1523
+ let invoice =
1524
+ store. handle_static_invoice_requested ( & recipient_id, invoice_slot) . await ;
1525
+
1526
+ match invoice {
1527
+ Ok ( Some ( invoice) ) => {
1528
+ if let Err ( e) =
1529
+ self . channel_manager . send_static_invoice ( invoice, reply_path)
1530
+ {
1531
+ log_error ! ( self . logger, "Failed to send static invoice: {:?}" , e) ;
1532
+ }
1533
+ } ,
1534
+ Ok ( None ) => { } ,
1535
+ Err ( e) => {
1536
+ log_error ! ( self . logger, "Failed to retrieve static invoice: {}" , e) ;
1537
+ } ,
1538
+ }
1539
+ }
1502
1540
} ,
1503
1541
LdkEvent :: FundingTransactionReadyForSigning { .. } => {
1504
1542
debug_assert ! ( false , "We currently don't support interactive-tx, so this event should never be emitted." ) ;
0 commit comments