@@ -21,14 +21,16 @@ use lightning::routing::router::{RouteHint, RouteHintHop};
21
21
22
22
use lightning_invoice:: { Bolt11Invoice , Bolt11InvoiceDescription , InvoiceBuilder , RoutingFees } ;
23
23
24
- use lightning_liquidity:: events:: Event ;
25
- use lightning_liquidity:: lsps0:: ser:: RequestId ;
24
+ use lightning_liquidity:: events:: LiquidityEvent ;
25
+ use lightning_liquidity:: lsps0:: ser:: { LSPSDateTime , LSPSRequestId } ;
26
26
use lightning_liquidity:: lsps1:: client:: LSPS1ClientConfig as LdkLSPS1ClientConfig ;
27
27
use lightning_liquidity:: lsps1:: event:: LSPS1ClientEvent ;
28
- use lightning_liquidity:: lsps1:: msgs:: { ChannelInfo , LSPS1Options , OrderId , OrderParameters } ;
28
+ use lightning_liquidity:: lsps1:: msgs:: {
29
+ LSPS1ChannelInfo , LSPS1Options , LSPS1OrderId , LSPS1OrderParams ,
30
+ } ;
29
31
use lightning_liquidity:: lsps2:: client:: LSPS2ClientConfig as LdkLSPS2ClientConfig ;
30
32
use lightning_liquidity:: lsps2:: event:: { LSPS2ClientEvent , LSPS2ServiceEvent } ;
31
- use lightning_liquidity:: lsps2:: msgs:: { OpeningFeeParams , RawOpeningFeeParams } ;
33
+ use lightning_liquidity:: lsps2:: msgs:: { LSPS2OpeningFeeParams , LSPS2RawOpeningFeeParams } ;
32
34
use lightning_liquidity:: lsps2:: service:: LSPS2ServiceConfig as LdkLSPS2ServiceConfig ;
33
35
use lightning_liquidity:: lsps2:: utils:: compute_opening_fee;
34
36
use lightning_liquidity:: { LiquidityClientConfig , LiquidityServiceConfig } ;
@@ -40,12 +42,13 @@ use bitcoin::secp256k1::{PublicKey, Secp256k1};
40
42
41
43
use tokio:: sync:: oneshot;
42
44
43
- use chrono:: { DateTime , Utc } ;
45
+ use chrono:: Utc ;
44
46
45
47
use rand:: Rng ;
46
48
47
49
use std:: collections:: HashMap ;
48
50
use std:: ops:: Deref ;
51
+ use std:: str:: FromStr ;
49
52
use std:: sync:: { Arc , Mutex , RwLock } ;
50
53
use std:: time:: Duration ;
51
54
@@ -61,10 +64,10 @@ struct LSPS1Client {
61
64
token : Option < String > ,
62
65
ldk_client_config : LdkLSPS1ClientConfig ,
63
66
pending_opening_params_requests :
64
- Mutex < HashMap < RequestId , oneshot:: Sender < LSPS1OpeningParamsResponse > > > ,
65
- pending_create_order_requests : Mutex < HashMap < RequestId , oneshot:: Sender < LSPS1OrderStatus > > > ,
67
+ Mutex < HashMap < LSPSRequestId , oneshot:: Sender < LSPS1OpeningParamsResponse > > > ,
68
+ pending_create_order_requests : Mutex < HashMap < LSPSRequestId , oneshot:: Sender < LSPS1OrderStatus > > > ,
66
69
pending_check_order_status_requests :
67
- Mutex < HashMap < RequestId , oneshot:: Sender < LSPS1OrderStatus > > > ,
70
+ Mutex < HashMap < LSPSRequestId , oneshot:: Sender < LSPS1OrderStatus > > > ,
68
71
}
69
72
70
73
#[ derive( Debug , Clone ) ]
@@ -79,8 +82,8 @@ struct LSPS2Client {
79
82
lsp_address : SocketAddress ,
80
83
token : Option < String > ,
81
84
ldk_client_config : LdkLSPS2ClientConfig ,
82
- pending_fee_requests : Mutex < HashMap < RequestId , oneshot:: Sender < LSPS2FeeResponse > > > ,
83
- pending_buy_requests : Mutex < HashMap < RequestId , oneshot:: Sender < LSPS2BuyResponse > > > ,
85
+ pending_fee_requests : Mutex < HashMap < LSPSRequestId , oneshot:: Sender < LSPS2FeeResponse > > > ,
86
+ pending_buy_requests : Mutex < HashMap < LSPSRequestId , oneshot:: Sender < LSPS2BuyResponse > > > ,
84
87
}
85
88
86
89
#[ derive( Debug , Clone ) ]
@@ -293,7 +296,7 @@ where
293
296
294
297
pub ( crate ) async fn handle_next_event ( & self ) {
295
298
match self . liquidity_manager . next_event_async ( ) . await {
296
- Event :: LSPS1Client ( LSPS1ClientEvent :: SupportedOptionsReady {
299
+ LiquidityEvent :: LSPS1Client ( LSPS1ClientEvent :: SupportedOptionsReady {
297
300
request_id,
298
301
counterparty_node_id,
299
302
supported_options,
@@ -346,7 +349,7 @@ where
346
349
) ;
347
350
}
348
351
} ,
349
- Event :: LSPS1Client ( LSPS1ClientEvent :: OrderCreated {
352
+ LiquidityEvent :: LSPS1Client ( LSPS1ClientEvent :: OrderCreated {
350
353
request_id,
351
354
counterparty_node_id,
352
355
order_id,
@@ -404,7 +407,7 @@ where
404
407
log_error ! ( self . logger, "Received unexpected LSPS1Client::OrderCreated event!" ) ;
405
408
}
406
409
} ,
407
- Event :: LSPS1Client ( LSPS1ClientEvent :: OrderStatus {
410
+ LiquidityEvent :: LSPS1Client ( LSPS1ClientEvent :: OrderStatus {
408
411
request_id,
409
412
counterparty_node_id,
410
413
order_id,
@@ -462,7 +465,7 @@ where
462
465
log_error ! ( self . logger, "Received unexpected LSPS1Client::OrderStatus event!" ) ;
463
466
}
464
467
} ,
465
- Event :: LSPS2Service ( LSPS2ServiceEvent :: GetInfo {
468
+ LiquidityEvent :: LSPS2Service ( LSPS2ServiceEvent :: GetInfo {
466
469
request_id,
467
470
counterparty_node_id,
468
471
token,
@@ -501,10 +504,11 @@ where
501
504
}
502
505
}
503
506
504
- let mut valid_until: DateTime < Utc > = Utc :: now ( ) ;
505
- valid_until += LSPS2_GETINFO_REQUEST_EXPIRY ;
507
+ let expiry_time = Utc :: now ( ) + LSPS2_GETINFO_REQUEST_EXPIRY ;
508
+ let valid_until = LSPSDateTime :: from_str ( & expiry_time. to_string ( ) )
509
+ . expect ( "TODO: switch to use constructor when merged" ) ;
506
510
507
- let opening_fee_params = RawOpeningFeeParams {
511
+ let opening_fee_params = LSPS2RawOpeningFeeParams {
508
512
min_fee_msat : service_config. min_channel_opening_fee_msat ,
509
513
proportional : service_config. channel_opening_fee_ppm ,
510
514
valid_until,
@@ -532,7 +536,7 @@ where
532
536
return ;
533
537
}
534
538
} ,
535
- Event :: LSPS2Service ( LSPS2ServiceEvent :: BuyRequest {
539
+ LiquidityEvent :: LSPS2Service ( LSPS2ServiceEvent :: BuyRequest {
536
540
request_id,
537
541
counterparty_node_id,
538
542
opening_fee_params : _,
@@ -599,7 +603,7 @@ where
599
603
return ;
600
604
}
601
605
} ,
602
- Event :: LSPS2Service ( LSPS2ServiceEvent :: OpenChannel {
606
+ LiquidityEvent :: LSPS2Service ( LSPS2ServiceEvent :: OpenChannel {
603
607
their_network_key,
604
608
amt_to_forward_msat,
605
609
opening_fee_msat : _,
@@ -713,7 +717,7 @@ where
713
717
} ,
714
718
}
715
719
} ,
716
- Event :: LSPS2Client ( LSPS2ClientEvent :: OpeningParametersReady {
720
+ LiquidityEvent :: LSPS2Client ( LSPS2ClientEvent :: OpeningParametersReady {
717
721
request_id,
718
722
counterparty_node_id,
719
723
opening_fee_params_menu,
@@ -763,7 +767,7 @@ where
763
767
) ;
764
768
}
765
769
} ,
766
- Event :: LSPS2Client ( LSPS2ClientEvent :: InvoiceParametersReady {
770
+ LiquidityEvent :: LSPS2Client ( LSPS2ClientEvent :: InvoiceParametersReady {
767
771
request_id,
768
772
counterparty_node_id,
769
773
intercept_scid,
@@ -903,7 +907,7 @@ where
903
907
return Err ( Error :: LiquidityRequestFailed ) ;
904
908
}
905
909
906
- let order_params = OrderParameters {
910
+ let order_params = LSPS1OrderParams {
907
911
lsp_balance_sat,
908
912
client_balance_sat,
909
913
required_channel_confirmations : lsp_limits. min_required_channel_confirmations ,
@@ -952,7 +956,7 @@ where
952
956
}
953
957
954
958
pub ( crate ) async fn lsps1_check_order_status (
955
- & self , order_id : OrderId ,
959
+ & self , order_id : LSPS1OrderId ,
956
960
) -> Result < LSPS1OrderStatus , Error > {
957
961
let lsps1_client = self . lsps1_client . as_ref ( ) . ok_or ( Error :: LiquiditySourceUnavailable ) ?;
958
962
let client_handler = self . liquidity_manager . lsps1_client_handler ( ) . ok_or_else ( || {
@@ -1120,7 +1124,7 @@ where
1120
1124
}
1121
1125
1122
1126
async fn lsps2_send_buy_request (
1123
- & self , amount_msat : Option < u64 > , opening_fee_params : OpeningFeeParams ,
1127
+ & self , amount_msat : Option < u64 > , opening_fee_params : LSPS2OpeningFeeParams ,
1124
1128
) -> Result < LSPS2BuyResponse , Error > {
1125
1129
let lsps2_client = self . lsps2_client . as_ref ( ) . ok_or ( Error :: LiquiditySourceUnavailable ) ?;
1126
1130
@@ -1291,32 +1295,32 @@ pub(crate) struct LSPS1OpeningParamsResponse {
1291
1295
#[ derive( Debug , Clone ) ]
1292
1296
pub struct LSPS1OrderStatus {
1293
1297
/// The id of the channel order.
1294
- pub order_id : OrderId ,
1298
+ pub order_id : LSPS1OrderId ,
1295
1299
/// The parameters of channel order.
1296
- pub order_params : OrderParameters ,
1300
+ pub order_params : LSPS1OrderParams ,
1297
1301
/// Contains details about how to pay for the order.
1298
- pub payment_options : PaymentInfo ,
1302
+ pub payment_options : LSPS1PaymentInfo ,
1299
1303
/// Contains information about the channel state.
1300
- pub channel_state : Option < ChannelInfo > ,
1304
+ pub channel_state : Option < LSPS1ChannelInfo > ,
1301
1305
}
1302
1306
1303
1307
#[ cfg( not( feature = "uniffi" ) ) ]
1304
- type PaymentInfo = lightning_liquidity:: lsps1:: msgs:: PaymentInfo ;
1308
+ type LSPS1PaymentInfo = lightning_liquidity:: lsps1:: msgs:: LSPS1PaymentInfo ;
1305
1309
1306
1310
/// Details regarding how to pay for an order.
1307
1311
#[ cfg( feature = "uniffi" ) ]
1308
1312
#[ derive( Clone , Debug , PartialEq , Eq ) ]
1309
- pub struct PaymentInfo {
1313
+ pub struct LSPS1PaymentInfo {
1310
1314
/// A Lightning payment using BOLT 11.
1311
- pub bolt11 : Option < crate :: uniffi_types:: Bolt11PaymentInfo > ,
1315
+ pub bolt11 : Option < crate :: uniffi_types:: LSPS1Bolt11PaymentInfo > ,
1312
1316
/// An onchain payment.
1313
- pub onchain : Option < OnchainPaymentInfo > ,
1317
+ pub onchain : Option < LSPS1OnchainPaymentInfo > ,
1314
1318
}
1315
1319
1316
1320
#[ cfg( feature = "uniffi" ) ]
1317
- impl From < lightning_liquidity:: lsps1:: msgs:: PaymentInfo > for PaymentInfo {
1318
- fn from ( value : lightning_liquidity:: lsps1:: msgs:: PaymentInfo ) -> Self {
1319
- PaymentInfo {
1321
+ impl From < lightning_liquidity:: lsps1:: msgs:: LSPS1PaymentInfo > for LSPS1PaymentInfo {
1322
+ fn from ( value : lightning_liquidity:: lsps1:: msgs:: LSPS1PaymentInfo ) -> Self {
1323
+ LSPS1PaymentInfo {
1320
1324
bolt11 : value. bolt11 . map ( |b| b. into ( ) ) ,
1321
1325
onchain : value. onchain . map ( |o| o. into ( ) ) ,
1322
1326
}
@@ -1326,11 +1330,11 @@ impl From<lightning_liquidity::lsps1::msgs::PaymentInfo> for PaymentInfo {
1326
1330
/// An onchain payment.
1327
1331
#[ cfg( feature = "uniffi" ) ]
1328
1332
#[ derive( Clone , Debug , PartialEq , Eq ) ]
1329
- pub struct OnchainPaymentInfo {
1333
+ pub struct LSPS1OnchainPaymentInfo {
1330
1334
/// Indicates the current state of the payment.
1331
- pub state : lightning_liquidity:: lsps1:: msgs:: PaymentState ,
1335
+ pub state : lightning_liquidity:: lsps1:: msgs:: LSPS1PaymentState ,
1332
1336
/// The datetime when the payment option expires.
1333
- pub expires_at : chrono :: DateTime < chrono :: Utc > ,
1337
+ pub expires_at : LSPSDateTime ,
1334
1338
/// The total fee the LSP will charge to open this channel in satoshi.
1335
1339
pub fee_total_sat : u64 ,
1336
1340
/// The amount the client needs to pay to have the requested channel openend.
@@ -1349,8 +1353,8 @@ pub struct OnchainPaymentInfo {
1349
1353
}
1350
1354
1351
1355
#[ cfg( feature = "uniffi" ) ]
1352
- impl From < lightning_liquidity:: lsps1:: msgs:: OnchainPaymentInfo > for OnchainPaymentInfo {
1353
- fn from ( value : lightning_liquidity:: lsps1:: msgs:: OnchainPaymentInfo ) -> Self {
1356
+ impl From < lightning_liquidity:: lsps1:: msgs:: LSPS1OnchainPaymentInfo > for LSPS1OnchainPaymentInfo {
1357
+ fn from ( value : lightning_liquidity:: lsps1:: msgs:: LSPS1OnchainPaymentInfo ) -> Self {
1354
1358
Self {
1355
1359
state : value. state ,
1356
1360
expires_at : value. expires_at ,
@@ -1366,7 +1370,7 @@ impl From<lightning_liquidity::lsps1::msgs::OnchainPaymentInfo> for OnchainPayme
1366
1370
1367
1371
#[ derive( Debug , Clone ) ]
1368
1372
pub ( crate ) struct LSPS2FeeResponse {
1369
- opening_fee_params_menu : Vec < OpeningFeeParams > ,
1373
+ opening_fee_params_menu : Vec < LSPS2OpeningFeeParams > ,
1370
1374
}
1371
1375
1372
1376
#[ derive( Debug , Clone ) ]
@@ -1456,7 +1460,7 @@ impl LSPS1Liquidity {
1456
1460
}
1457
1461
1458
1462
/// Connects to the configured LSP and checks for the status of a previously-placed order.
1459
- pub fn check_order_status ( & self , order_id : OrderId ) -> Result < LSPS1OrderStatus , Error > {
1463
+ pub fn check_order_status ( & self , order_id : LSPS1OrderId ) -> Result < LSPS1OrderStatus , Error > {
1460
1464
let liquidity_source =
1461
1465
self . liquidity_source . as_ref ( ) . ok_or ( Error :: LiquiditySourceUnavailable ) ?;
1462
1466
0 commit comments