55// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66// accordance with one or both of these licenses.
77
8+ use crate :: payment:: asynchronous:: static_invoice_store:: StaticInvoiceStore ;
89use crate :: types:: { CustomTlvRecord , DynStore , PaymentStore , Sweeper , Wallet } ;
9-
1010use crate :: {
1111 hex_utils, BumpTransactionEventHandler , ChannelManager , Error , Graph , PeerInfo , PeerStore ,
1212 UserChannelId ,
@@ -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,46 @@ 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+ 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+ }
14991520 } ,
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+ }
15021540 } ,
15031541 LdkEvent :: FundingTransactionReadyForSigning { .. } => {
15041542 debug_assert ! ( false , "We currently don't support interactive-tx, so this event should never be emitted." ) ;
0 commit comments