@@ -28,8 +28,8 @@ use lightning_liquidity::lsps1::msgs::{
2828 ChannelInfo , LSPS1Options , OrderId , OrderParameters , PaymentInfo ,
2929} ;
3030use lightning_liquidity:: lsps2:: client:: LSPS2ClientConfig ;
31- use lightning_liquidity:: lsps2:: event:: LSPS2ClientEvent ;
32- use lightning_liquidity:: lsps2:: msgs:: OpeningFeeParams ;
31+ use lightning_liquidity:: lsps2:: event:: { LSPS2ClientEvent , LSPS2ServiceEvent } ;
32+ use lightning_liquidity:: lsps2:: msgs:: { OpeningFeeParams , RawOpeningFeeParams } ;
3333use lightning_liquidity:: lsps2:: service:: LSPS2ServiceConfig ;
3434use lightning_liquidity:: lsps2:: utils:: compute_opening_fee;
3535use lightning_liquidity:: { LiquidityClientConfig , LiquidityServiceConfig } ;
@@ -39,6 +39,8 @@ use bitcoin::secp256k1::{PublicKey, Secp256k1};
3939
4040use tokio:: sync:: oneshot;
4141
42+ use chrono:: { DateTime , Utc } ;
43+
4244use std:: collections:: HashMap ;
4345use std:: ops:: Deref ;
4446use std:: sync:: { Arc , Mutex , RwLock } ;
@@ -395,6 +397,111 @@ where
395397 log_error ! ( self . logger, "Received unexpected LSPS1Client::OrderStatus event!" ) ;
396398 }
397399 } ,
400+ Event :: LSPS2Service ( LSPS2ServiceEvent :: GetInfo {
401+ request_id,
402+ counterparty_node_id,
403+ token : _,
404+ } ) => {
405+ if let Some ( lsps2_service_handler) =
406+ self . liquidity_manager . lsps2_service_handler ( ) . as_ref ( )
407+ {
408+ let min_fee_msat = 0 ;
409+ let proportional = 0 ;
410+ let mut valid_until: DateTime < Utc > = Utc :: now ( ) ;
411+ valid_until += chrono:: Duration :: minutes ( 10 ) ;
412+ let min_lifetime = 1008 ;
413+ let max_client_to_self_delay = 144 ;
414+ let min_payment_size_msat = 1000 ;
415+ let max_payment_size_msat = 10_000_000_000 ;
416+
417+ let opening_fee_params = RawOpeningFeeParams {
418+ min_fee_msat,
419+ proportional,
420+ valid_until,
421+ min_lifetime,
422+ max_client_to_self_delay,
423+ min_payment_size_msat,
424+ max_payment_size_msat,
425+ } ;
426+
427+ let opening_fee_params_menu = vec ! [ opening_fee_params] ;
428+
429+ if let Err ( e) = lsps2_service_handler. opening_fee_params_generated (
430+ & counterparty_node_id,
431+ request_id,
432+ opening_fee_params_menu,
433+ ) {
434+ log_error ! (
435+ self . logger,
436+ "Failed to handle generated opening fee params: {:?}" ,
437+ e
438+ ) ;
439+ }
440+ } else {
441+ log_error ! ( self . logger, "Failed to handle LSPS2ServiceEvent as LSPS2 liquidity service was not configured." , ) ;
442+ return ;
443+ }
444+ } ,
445+ Event :: LSPS2Service ( LSPS2ServiceEvent :: BuyRequest {
446+ request_id,
447+ counterparty_node_id,
448+ opening_fee_params : _,
449+ payment_size_msat : _,
450+ } ) => {
451+ if let Some ( lsps2_service_handler) =
452+ self . liquidity_manager . lsps2_service_handler ( ) . as_ref ( )
453+ {
454+ let user_channel_id = 0 ;
455+ let scid = self . channel_manager . get_intercept_scid ( ) ;
456+ let cltv_expiry_delta = 72 ;
457+ let client_trusts_lsp = true ;
458+
459+ if let Err ( e) = lsps2_service_handler. invoice_parameters_generated (
460+ & counterparty_node_id,
461+ request_id,
462+ scid,
463+ cltv_expiry_delta,
464+ client_trusts_lsp,
465+ user_channel_id,
466+ ) {
467+ log_error ! ( self . logger, "Failed to provide invoice parameters: {:?}" , e) ;
468+ }
469+ } else {
470+ log_error ! ( self . logger, "Failed to handle LSPS2ServiceEvent as LSPS2 liquidity service was not configured." , ) ;
471+ return ;
472+ }
473+ } ,
474+ Event :: LSPS2Service ( LSPS2ServiceEvent :: OpenChannel {
475+ their_network_key,
476+ amt_to_forward_msat,
477+ opening_fee_msat : _,
478+ user_channel_id,
479+ intercept_scid : _,
480+ } ) => {
481+ if self . liquidity_manager . lsps2_service_handler ( ) . is_none ( ) {
482+ log_error ! ( self . logger, "Failed to handle LSPS2ServiceEvent as LSPS2 liquidity service was not configured." , ) ;
483+ return ;
484+ } ;
485+
486+ let channel_size_sats = ( amt_to_forward_msat / 1000 ) * 4 ;
487+ let mut config = * self . channel_manager . get_current_default_configuration ( ) ;
488+ config
489+ . channel_handshake_config
490+ . max_inbound_htlc_value_in_flight_percent_of_channel = 100 ;
491+ config. channel_config . forwarding_fee_base_msat = 0 ;
492+ config. channel_config . forwarding_fee_proportional_millionths = 0 ;
493+
494+ if let Err ( e) = self . channel_manager . create_channel (
495+ their_network_key,
496+ channel_size_sats,
497+ 0 ,
498+ user_channel_id,
499+ None ,
500+ Some ( config) ,
501+ ) {
502+ log_error ! ( self . logger, "Failed to open jit channel: {:?}" , e) ;
503+ }
504+ } ,
398505 Event :: LSPS2Client ( LSPS2ClientEvent :: OpeningParametersReady {
399506 request_id,
400507 counterparty_node_id,
0 commit comments