66// accordance with one or both of these licenses.
77
88use crate :: types:: { CustomTlvRecord , DynStore , PaymentStore , Sweeper , Wallet } ;
9-
109use crate :: {
1110 hex_utils, BumpTransactionEventHandler , ChannelManager , Error , Graph , PeerInfo , PeerStore ,
1211 UserChannelId ,
@@ -19,6 +18,7 @@ use crate::fee_estimator::ConfirmationTarget;
1918use crate :: liquidity:: LiquiditySource ;
2019use crate :: logger:: Logger ;
2120
21+ use crate :: payment:: asynchronous:: static_invoice_store:: StaticInvoiceStore ;
2222use crate :: payment:: store:: {
2323 PaymentDetails , PaymentDetailsUpdate , PaymentDirection , PaymentKind , PaymentStatus ,
2424} ;
@@ -27,7 +27,7 @@ use crate::io::{
2727 EVENT_QUEUE_PERSISTENCE_KEY , EVENT_QUEUE_PERSISTENCE_PRIMARY_NAMESPACE ,
2828 EVENT_QUEUE_PERSISTENCE_SECONDARY_NAMESPACE ,
2929} ;
30- use crate :: logger:: { log_debug, log_error, log_info, LdkLogger } ;
30+ use crate :: logger:: { log_debug, log_error, log_info, log_trace , LdkLogger } ;
3131
3232use crate :: runtime:: Runtime ;
3333
@@ -458,6 +458,7 @@ where
458458 runtime : Arc < Runtime > ,
459459 logger : L ,
460460 config : Arc < Config > ,
461+ static_invoice_store : Option < StaticInvoiceStore > ,
461462}
462463
463464impl < L : Deref + Clone + Sync + Send + ' static > EventHandler < L >
@@ -470,8 +471,9 @@ where
470471 channel_manager : Arc < ChannelManager > , connection_manager : Arc < ConnectionManager < L > > ,
471472 output_sweeper : Arc < Sweeper > , network_graph : Arc < Graph > ,
472473 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 > ,
475477 ) -> Self {
476478 Self {
477479 event_queue,
@@ -487,6 +489,7 @@ where
487489 logger,
488490 runtime,
489491 config,
492+ static_invoice_store,
490493 }
491494 }
492495
@@ -1494,11 +1497,55 @@ where
14941497 LdkEvent :: OnionMessagePeerConnected { .. } => {
14951498 debug_assert ! ( false , "We currently don't support onion message interception, so this event should never be emitted." ) ;
14961499 } ,
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+ }
14991521 } ,
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+ }
15021549 } ,
15031550 LdkEvent :: FundingTransactionReadyForSigning { .. } => {
15041551 debug_assert ! ( false , "We currently don't support interactive-tx, so this event should never be emitted." ) ;
0 commit comments