Skip to content

Commit 7eca470

Browse files
committed
f WIP/TODO Account for renamed lightning-liquidity types
1 parent 03123d7 commit 7eca470

File tree

3 files changed

+84
-78
lines changed

3 files changed

+84
-78
lines changed

bindings/ldk_node.udl

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ interface Node {
160160

161161
[Enum]
162162
interface Bolt11InvoiceDescription {
163-
Hash(string hash);
164-
Direct(string description);
163+
Hash(string hash);
164+
Direct(string description);
165165
};
166166

167167
interface Bolt11Payment {
@@ -245,7 +245,7 @@ interface LSPS1Liquidity {
245245
[Throws=NodeError]
246246
LSPS1OrderStatus request_channel(u64 lsp_balance_sat, u64 client_balance_sat, u32 channel_expiry_blocks, boolean announce_channel);
247247
[Throws=NodeError]
248-
LSPS1OrderStatus check_order_status(OrderId order_id);
248+
LSPS1OrderStatus check_order_status(LSPS1OrderId order_id);
249249
};
250250

251251
[Error]
@@ -459,13 +459,13 @@ dictionary CustomTlvRecord {
459459
};
460460

461461
dictionary LSPS1OrderStatus {
462-
OrderId order_id;
463-
OrderParameters order_params;
464-
PaymentInfo payment_options;
465-
ChannelOrderInfo? channel_state;
462+
LSPS1OrderId order_id;
463+
LSPS1OrderParams order_params;
464+
LSPS1PaymentInfo payment_options;
465+
LSPS1ChannelInfo? channel_state;
466466
};
467467

468-
dictionary OrderParameters {
468+
dictionary LSPS1OrderParams {
469469
u64 lsp_balance_sat;
470470
u64 client_balance_sat;
471471
u16 required_channel_confirmations;
@@ -475,22 +475,22 @@ dictionary OrderParameters {
475475
boolean announce_channel;
476476
};
477477

478-
dictionary PaymentInfo {
479-
Bolt11PaymentInfo? bolt11;
480-
OnchainPaymentInfo? onchain;
478+
dictionary LSPS1PaymentInfo {
479+
LSPS1Bolt11PaymentInfo? bolt11;
480+
LSPS1OnchainPaymentInfo? onchain;
481481
};
482482

483-
dictionary Bolt11PaymentInfo {
484-
PaymentState state;
485-
DateTime expires_at;
483+
dictionary LSPS1Bolt11PaymentInfo {
484+
LSPS1PaymentState state;
485+
LSPSDateTime expires_at;
486486
u64 fee_total_sat;
487487
u64 order_total_sat;
488488
Bolt11Invoice invoice;
489489
};
490490

491-
dictionary OnchainPaymentInfo {
492-
PaymentState state;
493-
DateTime expires_at;
491+
dictionary LSPS1OnchainPaymentInfo {
492+
LSPS1PaymentState state;
493+
LSPSDateTime expires_at;
494494
u64 fee_total_sat;
495495
u64 order_total_sat;
496496
Address address;
@@ -499,13 +499,13 @@ dictionary OnchainPaymentInfo {
499499
Address? refund_onchain_address;
500500
};
501501

502-
dictionary ChannelOrderInfo {
503-
DateTime funded_at;
502+
dictionary LSPS1ChannelInfo {
503+
LSPSDateTime funded_at;
504504
OutPoint funding_outpoint;
505-
DateTime expires_at;
505+
LSPSDateTime expires_at;
506506
};
507507

508-
enum PaymentState {
508+
enum LSPS1PaymentState {
509509
"ExpectPayment",
510510
"Paid",
511511
"Refunded",
@@ -794,7 +794,7 @@ typedef string UntrustedString;
794794
typedef string NodeAlias;
795795

796796
[Custom]
797-
typedef string OrderId;
797+
typedef string LSPS1OrderId;
798798

799799
[Custom]
800-
typedef string DateTime;
800+
typedef string LSPSDateTime;

src/liquidity.rs

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ use lightning::routing::router::{RouteHint, RouteHintHop};
2121

2222
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, InvoiceBuilder, RoutingFees};
2323

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};
2626
use lightning_liquidity::lsps1::client::LSPS1ClientConfig as LdkLSPS1ClientConfig;
2727
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+
};
2931
use lightning_liquidity::lsps2::client::LSPS2ClientConfig as LdkLSPS2ClientConfig;
3032
use lightning_liquidity::lsps2::event::{LSPS2ClientEvent, LSPS2ServiceEvent};
31-
use lightning_liquidity::lsps2::msgs::{OpeningFeeParams, RawOpeningFeeParams};
33+
use lightning_liquidity::lsps2::msgs::{LSPS2OpeningFeeParams, LSPS2RawOpeningFeeParams};
3234
use lightning_liquidity::lsps2::service::LSPS2ServiceConfig as LdkLSPS2ServiceConfig;
3335
use lightning_liquidity::lsps2::utils::compute_opening_fee;
3436
use lightning_liquidity::{LiquidityClientConfig, LiquidityServiceConfig};
@@ -40,12 +42,13 @@ use bitcoin::secp256k1::{PublicKey, Secp256k1};
4042

4143
use tokio::sync::oneshot;
4244

43-
use chrono::{DateTime, Utc};
45+
use chrono::Utc;
4446

4547
use rand::Rng;
4648

4749
use std::collections::HashMap;
4850
use std::ops::Deref;
51+
use std::str::FromStr;
4952
use std::sync::{Arc, Mutex, RwLock};
5053
use std::time::Duration;
5154

@@ -61,10 +64,10 @@ struct LSPS1Client {
6164
token: Option<String>,
6265
ldk_client_config: LdkLSPS1ClientConfig,
6366
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>>>,
6669
pending_check_order_status_requests:
67-
Mutex<HashMap<RequestId, oneshot::Sender<LSPS1OrderStatus>>>,
70+
Mutex<HashMap<LSPSRequestId, oneshot::Sender<LSPS1OrderStatus>>>,
6871
}
6972

7073
#[derive(Debug, Clone)]
@@ -79,8 +82,8 @@ struct LSPS2Client {
7982
lsp_address: SocketAddress,
8083
token: Option<String>,
8184
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>>>,
8487
}
8588

8689
#[derive(Debug, Clone)]
@@ -293,7 +296,7 @@ where
293296

294297
pub(crate) async fn handle_next_event(&self) {
295298
match self.liquidity_manager.next_event_async().await {
296-
Event::LSPS1Client(LSPS1ClientEvent::SupportedOptionsReady {
299+
LiquidityEvent::LSPS1Client(LSPS1ClientEvent::SupportedOptionsReady {
297300
request_id,
298301
counterparty_node_id,
299302
supported_options,
@@ -346,7 +349,7 @@ where
346349
);
347350
}
348351
},
349-
Event::LSPS1Client(LSPS1ClientEvent::OrderCreated {
352+
LiquidityEvent::LSPS1Client(LSPS1ClientEvent::OrderCreated {
350353
request_id,
351354
counterparty_node_id,
352355
order_id,
@@ -404,7 +407,7 @@ where
404407
log_error!(self.logger, "Received unexpected LSPS1Client::OrderCreated event!");
405408
}
406409
},
407-
Event::LSPS1Client(LSPS1ClientEvent::OrderStatus {
410+
LiquidityEvent::LSPS1Client(LSPS1ClientEvent::OrderStatus {
408411
request_id,
409412
counterparty_node_id,
410413
order_id,
@@ -462,7 +465,7 @@ where
462465
log_error!(self.logger, "Received unexpected LSPS1Client::OrderStatus event!");
463466
}
464467
},
465-
Event::LSPS2Service(LSPS2ServiceEvent::GetInfo {
468+
LiquidityEvent::LSPS2Service(LSPS2ServiceEvent::GetInfo {
466469
request_id,
467470
counterparty_node_id,
468471
token,
@@ -501,10 +504,11 @@ where
501504
}
502505
}
503506

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");
506510

507-
let opening_fee_params = RawOpeningFeeParams {
511+
let opening_fee_params = LSPS2RawOpeningFeeParams {
508512
min_fee_msat: service_config.min_channel_opening_fee_msat,
509513
proportional: service_config.channel_opening_fee_ppm,
510514
valid_until,
@@ -532,7 +536,7 @@ where
532536
return;
533537
}
534538
},
535-
Event::LSPS2Service(LSPS2ServiceEvent::BuyRequest {
539+
LiquidityEvent::LSPS2Service(LSPS2ServiceEvent::BuyRequest {
536540
request_id,
537541
counterparty_node_id,
538542
opening_fee_params: _,
@@ -599,7 +603,7 @@ where
599603
return;
600604
}
601605
},
602-
Event::LSPS2Service(LSPS2ServiceEvent::OpenChannel {
606+
LiquidityEvent::LSPS2Service(LSPS2ServiceEvent::OpenChannel {
603607
their_network_key,
604608
amt_to_forward_msat,
605609
opening_fee_msat: _,
@@ -713,7 +717,7 @@ where
713717
},
714718
}
715719
},
716-
Event::LSPS2Client(LSPS2ClientEvent::OpeningParametersReady {
720+
LiquidityEvent::LSPS2Client(LSPS2ClientEvent::OpeningParametersReady {
717721
request_id,
718722
counterparty_node_id,
719723
opening_fee_params_menu,
@@ -763,7 +767,7 @@ where
763767
);
764768
}
765769
},
766-
Event::LSPS2Client(LSPS2ClientEvent::InvoiceParametersReady {
770+
LiquidityEvent::LSPS2Client(LSPS2ClientEvent::InvoiceParametersReady {
767771
request_id,
768772
counterparty_node_id,
769773
intercept_scid,
@@ -903,7 +907,7 @@ where
903907
return Err(Error::LiquidityRequestFailed);
904908
}
905909

906-
let order_params = OrderParameters {
910+
let order_params = LSPS1OrderParams {
907911
lsp_balance_sat,
908912
client_balance_sat,
909913
required_channel_confirmations: lsp_limits.min_required_channel_confirmations,
@@ -952,7 +956,7 @@ where
952956
}
953957

954958
pub(crate) async fn lsps1_check_order_status(
955-
&self, order_id: OrderId,
959+
&self, order_id: LSPS1OrderId,
956960
) -> Result<LSPS1OrderStatus, Error> {
957961
let lsps1_client = self.lsps1_client.as_ref().ok_or(Error::LiquiditySourceUnavailable)?;
958962
let client_handler = self.liquidity_manager.lsps1_client_handler().ok_or_else(|| {
@@ -1120,7 +1124,7 @@ where
11201124
}
11211125

11221126
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,
11241128
) -> Result<LSPS2BuyResponse, Error> {
11251129
let lsps2_client = self.lsps2_client.as_ref().ok_or(Error::LiquiditySourceUnavailable)?;
11261130

@@ -1291,32 +1295,32 @@ pub(crate) struct LSPS1OpeningParamsResponse {
12911295
#[derive(Debug, Clone)]
12921296
pub struct LSPS1OrderStatus {
12931297
/// The id of the channel order.
1294-
pub order_id: OrderId,
1298+
pub order_id: LSPS1OrderId,
12951299
/// The parameters of channel order.
1296-
pub order_params: OrderParameters,
1300+
pub order_params: LSPS1OrderParams,
12971301
/// Contains details about how to pay for the order.
1298-
pub payment_options: PaymentInfo,
1302+
pub payment_options: LSPS1PaymentInfo,
12991303
/// Contains information about the channel state.
1300-
pub channel_state: Option<ChannelInfo>,
1304+
pub channel_state: Option<LSPS1ChannelInfo>,
13011305
}
13021306

13031307
#[cfg(not(feature = "uniffi"))]
1304-
type PaymentInfo = lightning_liquidity::lsps1::msgs::PaymentInfo;
1308+
type LSPS1PaymentInfo = lightning_liquidity::lsps1::msgs::LSPS1PaymentInfo;
13051309

13061310
/// Details regarding how to pay for an order.
13071311
#[cfg(feature = "uniffi")]
13081312
#[derive(Clone, Debug, PartialEq, Eq)]
1309-
pub struct PaymentInfo {
1313+
pub struct LSPS1PaymentInfo {
13101314
/// A Lightning payment using BOLT 11.
1311-
pub bolt11: Option<crate::uniffi_types::Bolt11PaymentInfo>,
1315+
pub bolt11: Option<crate::uniffi_types::LSPS1Bolt11PaymentInfo>,
13121316
/// An onchain payment.
1313-
pub onchain: Option<OnchainPaymentInfo>,
1317+
pub onchain: Option<LSPS1OnchainPaymentInfo>,
13141318
}
13151319

13161320
#[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 {
13201324
bolt11: value.bolt11.map(|b| b.into()),
13211325
onchain: value.onchain.map(|o| o.into()),
13221326
}
@@ -1326,11 +1330,11 @@ impl From<lightning_liquidity::lsps1::msgs::PaymentInfo> for PaymentInfo {
13261330
/// An onchain payment.
13271331
#[cfg(feature = "uniffi")]
13281332
#[derive(Clone, Debug, PartialEq, Eq)]
1329-
pub struct OnchainPaymentInfo {
1333+
pub struct LSPS1OnchainPaymentInfo {
13301334
/// Indicates the current state of the payment.
1331-
pub state: lightning_liquidity::lsps1::msgs::PaymentState,
1335+
pub state: lightning_liquidity::lsps1::msgs::LSPS1PaymentState,
13321336
/// The datetime when the payment option expires.
1333-
pub expires_at: chrono::DateTime<chrono::Utc>,
1337+
pub expires_at: LSPSDateTime,
13341338
/// The total fee the LSP will charge to open this channel in satoshi.
13351339
pub fee_total_sat: u64,
13361340
/// The amount the client needs to pay to have the requested channel openend.
@@ -1349,8 +1353,8 @@ pub struct OnchainPaymentInfo {
13491353
}
13501354

13511355
#[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 {
13541358
Self {
13551359
state: value.state,
13561360
expires_at: value.expires_at,
@@ -1366,7 +1370,7 @@ impl From<lightning_liquidity::lsps1::msgs::OnchainPaymentInfo> for OnchainPayme
13661370

13671371
#[derive(Debug, Clone)]
13681372
pub(crate) struct LSPS2FeeResponse {
1369-
opening_fee_params_menu: Vec<OpeningFeeParams>,
1373+
opening_fee_params_menu: Vec<LSPS2OpeningFeeParams>,
13701374
}
13711375

13721376
#[derive(Debug, Clone)]
@@ -1456,7 +1460,7 @@ impl LSPS1Liquidity {
14561460
}
14571461

14581462
/// 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> {
14601464
let liquidity_source =
14611465
self.liquidity_source.as_ref().ok_or(Error::LiquiditySourceUnavailable)?;
14621466

0 commit comments

Comments
 (0)