Skip to content

Commit 82fc329

Browse files
committed
Add Uniffi bindings for LSPS1 API
1 parent 9837674 commit 82fc329

File tree

3 files changed

+125
-1
lines changed

3 files changed

+125
-1
lines changed

bindings/ldk_node.udl

+73
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ interface Builder {
3939
void set_chain_source_bitcoind_rpc(string rpc_host, u16 rpc_port, string rpc_user, string rpc_password);
4040
void set_gossip_source_p2p();
4141
void set_gossip_source_rgs(string rgs_server_url);
42+
void set_liquidity_source_lsps1(PublicKey node_id, SocketAddress address, string? token);
4243
void set_liquidity_source_lsps2(PublicKey node_id, SocketAddress address, string? token);
4344
void set_storage_dir_path(string storage_dir_path);
4445
void set_network(Network network);
@@ -78,6 +79,7 @@ interface Node {
7879
SpontaneousPayment spontaneous_payment();
7980
OnchainPayment onchain_payment();
8081
UnifiedQrPayment unified_qr_payment();
82+
Lsps1Liquidity lsps1_liquidity();
8183
[Throws=NodeError]
8284
void connect(PublicKey node_id, SocketAddress address, boolean persist);
8385
[Throws=NodeError]
@@ -173,6 +175,13 @@ interface UnifiedQrPayment {
173175
QrPaymentResult send([ByRef]string uri_str);
174176
};
175177

178+
interface Lsps1Liquidity {
179+
[Throws=NodeError]
180+
LSPS1OrderStatus request_channel(u64 lsp_balance_sat, u64 client_balance_sat, u32 channel_expiry_blocks, boolean announce_channel);
181+
[Throws=NodeError]
182+
LSPS1OrderStatus check_order_status(OrderId order_id);
183+
};
184+
176185
[Error]
177186
enum NodeError {
178187
"AlreadyRunning",
@@ -220,6 +229,8 @@ enum NodeError {
220229
"InvalidUri",
221230
"InvalidQuantity",
222231
"InvalidNodeAlias",
232+
"InvalidDateTime",
233+
"InvalidFeeRate",
223234
"DuplicatePayment",
224235
"UnsupportedCurrency",
225236
"InsufficientFunds",
@@ -372,6 +383,59 @@ dictionary CustomTlvRecord {
372383
sequence<u8> value;
373384
};
374385

386+
dictionary LSPS1OrderStatus {
387+
OrderId order_id;
388+
OrderParameters order_params;
389+
PaymentInfo payment_options;
390+
ChannelOrderInfo? channel_state;
391+
};
392+
393+
dictionary OrderParameters {
394+
u64 lsp_balance_sat;
395+
u64 client_balance_sat;
396+
u16 required_channel_confirmations;
397+
u16 funding_confirms_within_blocks;
398+
u32 channel_expiry_blocks;
399+
string? token;
400+
boolean announce_channel;
401+
};
402+
403+
dictionary PaymentInfo {
404+
Bolt11PaymentInfo? bolt11;
405+
OnchainPaymentInfo? onchain;
406+
};
407+
408+
dictionary Bolt11PaymentInfo {
409+
PaymentState state;
410+
DateTime expires_at;
411+
u64 fee_total_sat;
412+
u64 order_total_sat;
413+
Bolt11Invoice invoice;
414+
};
415+
416+
dictionary OnchainPaymentInfo {
417+
PaymentState state;
418+
DateTime expires_at;
419+
u64 fee_total_sat;
420+
u64 order_total_sat;
421+
Address address;
422+
u16? min_onchain_payment_confirmations;
423+
FeeRate min_fee_for_0conf;
424+
Address? refund_onchain_address;
425+
};
426+
427+
dictionary ChannelOrderInfo {
428+
DateTime funded_at;
429+
OutPoint funding_outpoint;
430+
DateTime expires_at;
431+
};
432+
433+
enum PaymentState {
434+
"ExpectPayment",
435+
"Paid",
436+
"Refunded",
437+
};
438+
375439
[Enum]
376440
interface MaxTotalRoutingFeeLimit {
377441
None ();
@@ -624,3 +688,12 @@ typedef string UntrustedString;
624688

625689
[Custom]
626690
typedef string NodeAlias;
691+
692+
[Custom]
693+
typedef string OrderId;
694+
695+
[Custom]
696+
typedef string DateTime;
697+
698+
[Custom]
699+
typedef string FeeRate;

src/error.rs

+6
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ pub enum Error {
106106
InvalidQuantity,
107107
/// The given node alias is invalid.
108108
InvalidNodeAlias,
109+
/// The given date time is invalid.
110+
InvalidDateTime,
111+
/// The given fee rate is invalid.
112+
InvalidFeeRate,
109113
/// A payment with the given hash has already been initiated.
110114
DuplicatePayment,
111115
/// The provided offer was denonminated in an unsupported currency.
@@ -172,6 +176,8 @@ impl fmt::Display for Error {
172176
Self::InvalidUri => write!(f, "The given URI is invalid."),
173177
Self::InvalidQuantity => write!(f, "The given quantity is invalid."),
174178
Self::InvalidNodeAlias => write!(f, "The given node alias is invalid."),
179+
Self::InvalidDateTime => write!(f, "The given date time is invalid."),
180+
Self::InvalidFeeRate => write!(f, "The given fee rate is invalid."),
175181
Self::DuplicatePayment => {
176182
write!(f, "A payment with the given hash has already been initiated.")
177183
},

src/uniffi_types.rs

+46-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub use crate::config::{
1414
default_config, AnchorChannelsConfig, EsploraSyncConfig, MaxDustHTLCExposure,
1515
};
1616
pub use crate::graph::{ChannelInfo, ChannelUpdateInfo, NodeAnnouncementInfo, NodeInfo};
17+
pub use crate::liquidity::LSPS1OrderStatus;
1718
pub use crate::payment::store::{LSPFeeLimits, PaymentDirection, PaymentKind, PaymentStatus};
1819
pub use crate::payment::{MaxTotalRoutingFeeLimit, QrPaymentResult, SendingParameters};
1920

@@ -30,12 +31,19 @@ pub use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
3031

3132
pub use lightning_invoice::Bolt11Invoice;
3233

33-
pub use bitcoin::{Address, BlockHash, Network, OutPoint, Txid};
34+
pub use lightning_liquidity::lsps1::msgs::ChannelInfo as ChannelOrderInfo;
35+
pub use lightning_liquidity::lsps1::msgs::{
36+
Bolt11PaymentInfo, OnchainPaymentInfo, OrderId, OrderParameters, PaymentInfo, PaymentState,
37+
};
38+
39+
pub use bitcoin::{Address, BlockHash, FeeRate, Network, OutPoint, Txid};
3440

3541
pub use bip39::Mnemonic;
3642

3743
pub use vss_client::headers::{VssHeaderProvider, VssHeaderProviderError};
3844

45+
pub type DateTime = chrono::DateTime<chrono::Utc>;
46+
3947
use crate::UniffiCustomTypeConverter;
4048

4149
use crate::builder::sanitize_alias;
@@ -345,3 +353,40 @@ impl UniffiCustomTypeConverter for NodeAlias {
345353
obj.to_string()
346354
}
347355
}
356+
357+
impl UniffiCustomTypeConverter for OrderId {
358+
type Builtin = String;
359+
360+
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
361+
Ok(Self(val))
362+
}
363+
364+
fn from_custom(obj: Self) -> Self::Builtin {
365+
obj.0
366+
}
367+
}
368+
369+
impl UniffiCustomTypeConverter for DateTime {
370+
type Builtin = String;
371+
372+
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
373+
Ok(DateTime::from_str(&val).map_err(|_| Error::InvalidDateTime)?)
374+
}
375+
376+
fn from_custom(obj: Self) -> Self::Builtin {
377+
obj.to_rfc3339()
378+
}
379+
}
380+
381+
/// FIXME TODO
382+
impl UniffiCustomTypeConverter for FeeRate {
383+
type Builtin = String;
384+
385+
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
386+
Ok(FeeRate::from_str(&val).map_err(|_| Error::InvalidFeeRate)?)
387+
}
388+
389+
fn from_custom(obj: Self) -> Self::Builtin {
390+
obj.to_string()
391+
}
392+
}

0 commit comments

Comments
 (0)