diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index b0dd39874..e03baf204 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -39,6 +39,7 @@ interface Builder { void set_chain_source_bitcoind_rpc(string rpc_host, u16 rpc_port, string rpc_user, string rpc_password); void set_gossip_source_p2p(); void set_gossip_source_rgs(string rgs_server_url); + void set_liquidity_source_lsps1(PublicKey node_id, SocketAddress address, string? token); void set_liquidity_source_lsps2(PublicKey node_id, SocketAddress address, string? token); void set_storage_dir_path(string storage_dir_path); void set_network(Network network); @@ -78,6 +79,7 @@ interface Node { SpontaneousPayment spontaneous_payment(); OnchainPayment onchain_payment(); UnifiedQrPayment unified_qr_payment(); + Lsps1Liquidity lsps1_liquidity(); [Throws=NodeError] void connect(PublicKey node_id, SocketAddress address, boolean persist); [Throws=NodeError] @@ -171,6 +173,13 @@ interface UnifiedQrPayment { QrPaymentResult send([ByRef]string uri_str); }; +interface Lsps1Liquidity { + [Throws=NodeError] + LSPS1OrderStatus request_channel(u64 lsp_balance_sat, u64 client_balance_sat, u32 channel_expiry_blocks, boolean announce_channel); + [Throws=NodeError] + LSPS1OrderStatus check_order_status(OrderId order_id); +}; + [Error] enum NodeError { "AlreadyRunning", @@ -217,6 +226,8 @@ enum NodeError { "InvalidUri", "InvalidQuantity", "InvalidNodeAlias", + "InvalidTimestamp", + "InvalidFeeRate", "DuplicatePayment", "UnsupportedCurrency", "InsufficientFunds", @@ -362,6 +373,59 @@ dictionary SendingParameters { u8? max_channel_saturation_power_of_half; }; +dictionary LSPS1OrderStatus { + OrderId order_id; + OrderParameters order_params; + PaymentInfo payment_options; + ChannelOrderInfo? channel_state; +}; + +dictionary OrderParameters { + u64 lsp_balance_sat; + u64 client_balance_sat; + u16 required_channel_confirmations; + u16 funding_confirms_within_blocks; + u32 channel_expiry_blocks; + string? token; + boolean announce_channel; +}; + +dictionary PaymentInfo { + Bolt11PaymentInfo? bolt11; + OnchainPaymentInfo? onchain; +}; + +dictionary Bolt11PaymentInfo { + PaymentState state; + DateTime expires_at; + u64 fee_total_sat; + u64 order_total_sat; + Bolt11Invoice invoice; +}; + +dictionary OnchainPaymentInfo { + PaymentState state; + DateTime expires_at; + u64 fee_total_sat; + u64 order_total_sat; + Address address; + u16? min_onchain_payment_confirmations; + FeeRate min_fee_for_0conf; + Address? refund_onchain_address; +}; + +dictionary ChannelOrderInfo { + DateTime funded_at; + OutPoint funding_outpoint; + DateTime expires_at; +}; + +enum PaymentState { + "ExpectPayment", + "Paid", + "Refunded", +}; + [Enum] interface MaxTotalRoutingFeeLimit { None (); @@ -614,3 +678,12 @@ typedef string UntrustedString; [Custom] typedef string NodeAlias; + +[Custom] +typedef string OrderId; + +[Custom] +typedef i64 DateTime; + +[Custom] +typedef string FeeRate; diff --git a/src/error.rs b/src/error.rs index d1fd848b1..bba29b9bb 100644 --- a/src/error.rs +++ b/src/error.rs @@ -104,6 +104,10 @@ pub enum Error { InvalidQuantity, /// The given node alias is invalid. InvalidNodeAlias, + /// The given timestamp is invalid. + InvalidTimestamp, + /// The given fee rate is invalid. + InvalidFeeRate, /// A payment with the given hash has already been initiated. DuplicatePayment, /// The provided offer was denonminated in an unsupported currency. @@ -169,6 +173,8 @@ impl fmt::Display for Error { Self::InvalidUri => write!(f, "The given URI is invalid."), Self::InvalidQuantity => write!(f, "The given quantity is invalid."), Self::InvalidNodeAlias => write!(f, "The given node alias is invalid."), + Self::InvalidTimestamp => write!(f, "The given timestamp is invalid."), + Self::InvalidFeeRate => write!(f, "The given fee rate is invalid."), Self::DuplicatePayment => { write!(f, "A payment with the given hash has already been initiated.") }, diff --git a/src/uniffi_types.rs b/src/uniffi_types.rs index c8c84dbed..8e5d33e6e 100644 --- a/src/uniffi_types.rs +++ b/src/uniffi_types.rs @@ -14,6 +14,7 @@ pub use crate::config::{ default_config, AnchorChannelsConfig, EsploraSyncConfig, MaxDustHTLCExposure, }; pub use crate::graph::{ChannelInfo, ChannelUpdateInfo, NodeAnnouncementInfo, NodeInfo}; +pub use crate::liquidity::LSPS1OrderStatus; pub use crate::payment::store::{LSPFeeLimits, PaymentDirection, PaymentKind, PaymentStatus}; pub use crate::payment::{MaxTotalRoutingFeeLimit, QrPaymentResult, SendingParameters}; @@ -28,12 +29,19 @@ pub use lightning::util::string::UntrustedString; pub use lightning_invoice::Bolt11Invoice; -pub use bitcoin::{Address, BlockHash, Network, OutPoint, Txid}; +pub use lightning_liquidity::lsps1::msgs::ChannelInfo as ChannelOrderInfo; +pub use lightning_liquidity::lsps1::msgs::{ + Bolt11PaymentInfo, OnchainPaymentInfo, OrderId, OrderParameters, PaymentInfo, PaymentState, +}; + +pub use bitcoin::{Address, BlockHash, FeeRate, Network, OutPoint, Txid}; pub use bip39::Mnemonic; pub use vss_client::headers::{VssHeaderProvider, VssHeaderProviderError}; +pub type DateTime = chrono::DateTime; + use crate::UniffiCustomTypeConverter; use crate::builder::sanitize_alias; @@ -343,3 +351,40 @@ impl UniffiCustomTypeConverter for NodeAlias { obj.to_string() } } + +impl UniffiCustomTypeConverter for OrderId { + type Builtin = String; + + fn into_custom(val: Self::Builtin) -> uniffi::Result { + Ok(Self(val)) + } + + fn from_custom(obj: Self) -> Self::Builtin { + obj.0 + } +} + +impl UniffiCustomTypeConverter for DateTime { + type Builtin = i64; + + fn into_custom(val: Self::Builtin) -> uniffi::Result { + DateTime::from_timestamp(val, 0).ok_or(Error::InvalidTimestamp.into()) + } + + fn from_custom(obj: Self) -> Self::Builtin { + obj.timestamp() + } +} + +/// FIXME TODO +impl UniffiCustomTypeConverter for FeeRate { + type Builtin = String; + + fn into_custom(val: Self::Builtin) -> uniffi::Result { + Ok(FeeRate::from_str(&val).map_err(|_| Error::InvalidFeeRate)?) + } + + fn from_custom(obj: Self) -> Self::Builtin { + obj.to_string() + } +}