From 2ab00d207d36c452c5197820a3e21eb4e9d981da Mon Sep 17 00:00:00 2001 From: elnafateh Date: Sat, 5 Dec 2026 12:47:26 +0100 Subject: [PATCH] feat: expose LSPS1 channel purchase APIs Add channel request and order status operations across the server, client, CLI, and MCP layers. AI-assisted with OpenAI Codex. --- docs/api-guide.md | 22 ++- ldk-server-cli/src/main.rs | 69 ++++++- ldk-server-client/src/client.rs | 38 ++-- ldk-server-grpc/src/api.rs | 217 ++++++++++++++++++++++ ldk-server-grpc/src/endpoints.rs | 2 + ldk-server-grpc/src/permissions.rs | 11 +- ldk-server-grpc/src/proto/api.proto | 109 +++++++++++ ldk-server-mcp/src/tools/handlers.rs | 25 ++- ldk-server-mcp/src/tools/mod.rs | 21 ++- ldk-server-mcp/src/tools/schema.rs | 46 +++++ ldk-server-mcp/tests/integration.rs | 4 +- ldk-server/src/api/lsps1.rs | 140 ++++++++++++++ ldk-server/src/api/mod.rs | 1 + ldk-server/src/macaroons/authorization.rs | 2 + ldk-server/src/service.rs | 18 +- 15 files changed, 689 insertions(+), 36 deletions(-) create mode 100644 ldk-server/src/api/lsps1.rs diff --git a/docs/api-guide.md b/docs/api-guide.md index f9046c52..56e8dc5e 100644 --- a/docs/api-guide.md +++ b/docs/api-guide.md @@ -102,8 +102,8 @@ RPCs with no permission mapping return `UNIMPLEMENTED`, even for admin tokens. | `payments:read` | Read payments, forwarded payments, and forwarding statistics | | `payments:claim` | Claim or fail held BOLT11 payments | | `payments:send` | Send BOLT11, BOLT12, spontaneous and unified payments and probes; splice out | -| `channels:read` | List channels | -| `channels:manage` | Open, configure, cooperatively close, splice funds into channels, or bump pending splice fees. Opening a channel can push funds to the counterparty, so this permission can move funds out of the node | +| `channels:read` | List channels and check LSPS1 order status | +| `channels:manage` | Open, configure, cooperatively close, splice funds into channels, bump pending splice fees, or request an LSPS1 channel. Opening a channel can push funds to the counterparty, so this permission can move funds out of the node | | `channels:force_close` | Force-close channels | | `peers:read` | List peers | | `peers:manage` | Connect or disconnect peers | @@ -213,6 +213,22 @@ These RPCs support a manual claim/fail workflow for held payments. See | `Bolt11ClaimForId` | Claim a held payment by its payment ID and preimage | | `Bolt11FailForId` | Reject a held payment by its payment ID | +### LSPS1 Channel Orders + +Requires an LSPS1-capable LSP configured in `[[liquidity.lsps_client]]`. Request an inbound +channel with `Lsps1RequestChannel`, then pay one of the returned BOLT11, BOLT12, or on-chain +payment options. Use `Lsps1CheckOrderStatus` with the returned `order_id` to check the order again; +`channel_state` is populated once the LSP publishes the funding transaction. `Lsps1RequestChannel` +can take an optional `lsp_node_id` to select a configured provider; status checks require the +`lsp_node_id` of the provider that received the order. + +| RPC | Description | +| --- | --- | +| `Lsps1RequestChannel` | Place an order for an inbound channel from the configured LSP | +| `Lsps1CheckOrderStatus` | Check the status of a previously placed LSPS1 order | + +`Lsps1RequestChannel` requires `channels:manage`; `Lsps1CheckOrderStatus` requires `channels:read`. + ### BOLT11 JIT Channels (LSPS2) Requires at least one `[[liquidity.lsps_client]]` entry for an LSPS2-capable LSP. The LSP opens @@ -248,6 +264,8 @@ a channel just-in-time when the invoice is paid. | RPC | Description | | ----------------------- | ---------------------------------------------------------------------- | | `OpenChannel` | Open a new outbound channel (with optional push amount and fee config) | +| `Lsps1RequestChannel` | Request an inbound channel from the configured LSPS1 LSP | +| `Lsps1CheckOrderStatus` | Check the status of an LSPS1 channel order | | `CloseChannel` | Cooperatively close a channel | | `ForceCloseChannel` | Force-close a channel unilaterally | | `SpliceIn` | Add on-chain funds to an existing channel | diff --git a/ldk-server-cli/src/main.rs b/ldk-server-cli/src/main.rs index f5071e17..983b2f32 100644 --- a/ldk-server-cli/src/main.rs +++ b/ldk-server-cli/src/main.rs @@ -55,14 +55,15 @@ use ldk_server_client::ldk_server_grpc::api::{ GraphListNodesRequest, GraphListNodesResponse, ListChannelForwardingStatsRequest, ListChannelPairForwardingStatsRequest, ListChannelsRequest, ListChannelsResponse, ListForwardedPaymentsRequest, ListMacaroonsRequest, ListMacaroonsResponse, ListPaymentsRequest, - ListPeersRequest, ListPeersResponse, OnchainBumpFeeRequest, OnchainBumpFeeResponse, - OnchainReceiveRequest, OnchainReceiveResponse, OnchainSendRequest, OnchainSendResponse, - OpenChannelRequest, OpenChannelResponse, RevokeMacaroonRequest, RevokeMacaroonResponse, - SignMessageRequest, SignMessageResponse, SpliceInRequest, SpliceInResponse, SpliceOutRequest, - SpliceOutResponse, SpontaneousSendProbesRequest, SpontaneousSendProbesResponse, - SpontaneousSendRequest, SpontaneousSendResponse, UnifiedSendRequest, UnifiedSendResponse, - UpdateChannelConfigRequest, UpdateChannelConfigResponse, VerifySignatureRequest, - VerifySignatureResponse, + ListPeersRequest, ListPeersResponse, Lsps1CheckOrderStatusRequest, + Lsps1CheckOrderStatusResponse, Lsps1RequestChannelRequest, Lsps1RequestChannelResponse, + OnchainBumpFeeRequest, OnchainBumpFeeResponse, OnchainReceiveRequest, OnchainReceiveResponse, + OnchainSendRequest, OnchainSendResponse, OpenChannelRequest, OpenChannelResponse, + RevokeMacaroonRequest, RevokeMacaroonResponse, SignMessageRequest, SignMessageResponse, + SpliceInRequest, SpliceInResponse, SpliceOutRequest, SpliceOutResponse, + SpontaneousSendProbesRequest, SpontaneousSendProbesResponse, SpontaneousSendRequest, + SpontaneousSendResponse, UnifiedSendRequest, UnifiedSendResponse, UpdateChannelConfigRequest, + UpdateChannelConfigResponse, VerifySignatureRequest, VerifySignatureResponse, }; use ldk_server_client::ldk_server_grpc::permissions::MacaroonPreset; use ldk_server_client::ldk_server_grpc::types::{ @@ -647,6 +648,26 @@ enum Commands { )] wait_timeout: Option, }, + #[command(about = "Request an inbound channel from the configured LSPS1 LSP")] + Lsps1RequestChannel { + #[arg(long, help = "The balance in satoshis the LSP will contribute, e.g. 500000sat")] + lsp_balance: Amount, + #[arg(long, help = "The balance in satoshis the client will contribute, e.g. 100000sat")] + client_balance: Amount, + #[arg(long, help = "How long the channel should be leased, in blocks")] + channel_expiry_blocks: u32, + #[arg(long, help = "Whether the channel should be announced to the network")] + announce_channel: bool, + #[arg(long, help = "Hex-encoded node ID of the configured LSP to use")] + lsp_node_id: Option, + }, + #[command(about = "Check the status of a previously placed LSPS1 channel order")] + Lsps1CheckOrderStatus { + #[arg(help = "The order ID returned by lsps1-request-channel")] + order_id: String, + #[arg(long, help = "Hex-encoded node ID of the LSP that received the order")] + lsp_node_id: String, + }, #[command( about = "Increase the channel balance by the given amount, funds will come from the node's on-chain wallet" )] @@ -1470,6 +1491,38 @@ async fn main() { ); } }, + Commands::Lsps1RequestChannel { + lsp_balance, + client_balance, + channel_expiry_blocks, + announce_channel, + lsp_node_id, + } => { + let lsp_balance_sat = lsp_balance.to_sat().unwrap_or_else(|e| handle_error_msg(e)); + let client_balance_sat = + client_balance.to_sat().unwrap_or_else(|e| handle_error_msg(e)); + handle_response_result::<_, Lsps1RequestChannelResponse>( + client + .lsps1_request_channel(Lsps1RequestChannelRequest { + lsp_balance_sat, + client_balance_sat, + channel_expiry_blocks, + announce_channel, + lsp_node_id, + }) + .await, + ); + }, + Commands::Lsps1CheckOrderStatus { order_id, lsp_node_id } => { + handle_response_result::<_, Lsps1CheckOrderStatusResponse>( + client + .lsps1_check_order_status(Lsps1CheckOrderStatusRequest { + order_id, + lsp_node_id, + }) + .await, + ); + }, Commands::SpliceIn { user_channel_id, counterparty_node_id, splice_amount } => { let amount = match splice_amount.to_sat().unwrap_or_else(|e| handle_error_msg(e)) { Some(amount_sats) => splice_in_request::Amount::SpliceAmountSats(amount_sats), diff --git a/ldk-server-client/src/client.rs b/ldk-server-client/src/client.rs index 89074ef5..23824c8d 100644 --- a/ldk-server-client/src/client.rs +++ b/ldk-server-client/src/client.rs @@ -42,14 +42,15 @@ use ldk_server_grpc::api::{ ListChannelPairForwardingStatsResponse, ListChannelsRequest, ListChannelsResponse, ListForwardedPaymentsRequest, ListForwardedPaymentsResponse, ListMacaroonsRequest, ListMacaroonsResponse, ListPaymentsRequest, ListPaymentsResponse, ListPeersRequest, - ListPeersResponse, OnchainBumpFeeRequest, OnchainBumpFeeResponse, OnchainReceiveRequest, - OnchainReceiveResponse, OnchainSendRequest, OnchainSendResponse, OpenChannelRequest, - OpenChannelResponse, RevokeMacaroonRequest, RevokeMacaroonResponse, SignMessageRequest, - SignMessageResponse, SpliceInRequest, SpliceInResponse, SpliceOutRequest, SpliceOutResponse, - SpontaneousSendProbesRequest, SpontaneousSendProbesResponse, SpontaneousSendRequest, - SpontaneousSendResponse, SubscribeEventsRequest, UnifiedSendRequest, UnifiedSendResponse, - UpdateChannelConfigRequest, UpdateChannelConfigResponse, VerifySignatureRequest, - VerifySignatureResponse, + ListPeersResponse, Lsps1CheckOrderStatusRequest, Lsps1CheckOrderStatusResponse, + Lsps1RequestChannelRequest, Lsps1RequestChannelResponse, OnchainBumpFeeRequest, + OnchainBumpFeeResponse, OnchainReceiveRequest, OnchainReceiveResponse, OnchainSendRequest, + OnchainSendResponse, OpenChannelRequest, OpenChannelResponse, RevokeMacaroonRequest, + RevokeMacaroonResponse, SignMessageRequest, SignMessageResponse, SpliceInRequest, + SpliceInResponse, SpliceOutRequest, SpliceOutResponse, SpontaneousSendProbesRequest, + SpontaneousSendProbesResponse, SpontaneousSendRequest, SpontaneousSendResponse, + SubscribeEventsRequest, UnifiedSendRequest, UnifiedSendResponse, UpdateChannelConfigRequest, + UpdateChannelConfigResponse, VerifySignatureRequest, VerifySignatureResponse, }; use ldk_server_grpc::endpoints::{ BOLT11_CLAIM_FOR_ID_PATH, BOLT11_FAIL_FOR_ID_PATH, BOLT11_RECEIVE_FOR_HASH_PATH, @@ -67,9 +68,10 @@ use ldk_server_grpc::endpoints::{ GRAPH_LIST_CHANNELS_PATH, GRAPH_LIST_NODES_PATH, GRPC_SERVICE_PREFIX, LIST_CHANNELS_PATH, LIST_CHANNEL_FORWARDING_STATS_PATH, LIST_CHANNEL_PAIR_FORWARDING_STATS_PATH, LIST_FORWARDED_PAYMENTS_PATH, LIST_MACAROONS_PATH, LIST_PAYMENTS_PATH, LIST_PEERS_PATH, - ONCHAIN_BUMP_FEE_PATH, ONCHAIN_RECEIVE_PATH, ONCHAIN_SEND_PATH, OPEN_CHANNEL_PATH, - REVOKE_MACAROON_PATH, SIGN_MESSAGE_PATH, SPLICE_IN_PATH, SPLICE_OUT_PATH, - SPONTANEOUS_SEND_PATH, SPONTANEOUS_SEND_PROBES_PATH, SUBSCRIBE_EVENTS_PATH, UNIFIED_SEND_PATH, + LSPS1_CHECK_ORDER_STATUS_PATH, LSPS1_REQUEST_CHANNEL_PATH, ONCHAIN_BUMP_FEE_PATH, + ONCHAIN_RECEIVE_PATH, ONCHAIN_SEND_PATH, OPEN_CHANNEL_PATH, REVOKE_MACAROON_PATH, + SIGN_MESSAGE_PATH, SPLICE_IN_PATH, SPLICE_OUT_PATH, SPONTANEOUS_SEND_PATH, + SPONTANEOUS_SEND_PROBES_PATH, SUBSCRIBE_EVENTS_PATH, UNIFIED_SEND_PATH, UPDATE_CHANNEL_CONFIG_PATH, VERIFY_SIGNATURE_PATH, }; use ldk_server_grpc::events::EventEnvelope; @@ -333,6 +335,20 @@ impl LdkServerClient { self.grpc_unary(&request, OPEN_CHANNEL_PATH).await } + /// Place an LSPS1 order for an inbound channel from the configured LSP. + pub async fn lsps1_request_channel( + &self, request: Lsps1RequestChannelRequest, + ) -> Result { + self.grpc_unary(&request, LSPS1_REQUEST_CHANNEL_PATH).await + } + + /// Check the status of a previously placed LSPS1 channel order. + pub async fn lsps1_check_order_status( + &self, request: Lsps1CheckOrderStatusRequest, + ) -> Result { + self.grpc_unary(&request, LSPS1_CHECK_ORDER_STATUS_PATH).await + } + /// Splices funds into the channel specified by given request. pub async fn splice_in( &self, request: SpliceInRequest, diff --git a/ldk-server-grpc/src/api.rs b/ldk-server-grpc/src/api.rs index 03d44f73..d58b8d20 100644 --- a/ldk-server-grpc/src/api.rs +++ b/ldk-server-grpc/src/api.rs @@ -862,6 +862,186 @@ pub struct OpenChannelResponse { #[prost(string, tag = "1")] pub user_channel_id: ::prost::alloc::string::String, } +/// Place an order for an inbound channel from the configured LSPS1 LSP. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] +#[cfg_attr(feature = "serde", serde(default))] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Lsps1RequestChannelRequest { + /// The balance in satoshis the LSP will contribute to the channel. + #[prost(uint64, tag = "1")] + pub lsp_balance_sat: u64, + /// The balance in satoshis the client will contribute to the channel. + #[prost(uint64, tag = "2")] + pub client_balance_sat: u64, + /// How long the channel should be leased, in blocks. + #[prost(uint32, tag = "3")] + pub channel_expiry_blocks: u32, + /// Whether the channel should be announced to the network. + #[prost(bool, tag = "4")] + pub announce_channel: bool, + /// Optional hex-encoded LSP node ID. If unset, the first configured LSPS1 LSP is used. + #[prost(string, optional, tag = "5")] + pub lsp_node_id: ::core::option::Option<::prost::alloc::string::String>, +} +/// The response for `Lsps1RequestChannel`. The client must pay one of the returned payment +/// options before the LSP opens the channel. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] +#[cfg_attr(feature = "serde", serde(default))] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Lsps1RequestChannelResponse { + #[prost(message, optional, tag = "1")] + pub order_status: ::core::option::Option, +} +/// Check the status of an existing LSPS1 channel order with the configured LSP. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] +#[cfg_attr(feature = "serde", serde(default))] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Lsps1CheckOrderStatusRequest { + /// The order ID returned by `Lsps1RequestChannel`. + #[prost(string, tag = "1")] + pub order_id: ::prost::alloc::string::String, + /// The hex-encoded node ID of the LSP that received the order. + #[prost(string, tag = "2")] + pub lsp_node_id: ::prost::alloc::string::String, +} +/// The response for `Lsps1CheckOrderStatus`. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] +#[cfg_attr(feature = "serde", serde(default))] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Lsps1CheckOrderStatusResponse { + #[prost(message, optional, tag = "1")] + pub order_status: ::core::option::Option, +} +/// The status returned by LDK Node for an LSPS1 channel order. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] +#[cfg_attr(feature = "serde", serde(default))] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Lsps1OrderStatus { + #[prost(string, tag = "1")] + pub order_id: ::prost::alloc::string::String, + #[prost(message, optional, tag = "2")] + pub order_params: ::core::option::Option, + #[prost(message, optional, tag = "3")] + pub payment_options: ::core::option::Option, + /// Present after the LSP publishes the channel funding transaction. + #[prost(message, optional, tag = "4")] + pub channel_state: ::core::option::Option, +} +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] +#[cfg_attr(feature = "serde", serde(default))] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Lsps1OrderParams { + #[prost(uint64, tag = "1")] + pub lsp_balance_sat: u64, + #[prost(uint64, tag = "2")] + pub client_balance_sat: u64, + #[prost(uint32, tag = "3")] + pub required_channel_confirmations: u32, + #[prost(uint32, tag = "4")] + pub funding_confirms_within_blocks: u32, + #[prost(uint32, tag = "5")] + pub channel_expiry_blocks: u32, + #[prost(string, optional, tag = "6")] + pub token: ::core::option::Option<::prost::alloc::string::String>, + #[prost(bool, tag = "7")] + pub announce_channel: bool, +} +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] +#[cfg_attr(feature = "serde", serde(default))] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Lsps1PaymentOptions { + #[prost(message, optional, tag = "1")] + pub bolt11: ::core::option::Option, + #[prost(message, optional, tag = "2")] + pub bolt12: ::core::option::Option, + #[prost(message, optional, tag = "3")] + pub onchain: ::core::option::Option, +} +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] +#[cfg_attr(feature = "serde", serde(default))] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Lsps1Bolt11PaymentInfo { + #[prost(enumeration = "Lsps1PaymentState", tag = "1")] + pub state: i32, + #[prost(string, tag = "2")] + pub expires_at: ::prost::alloc::string::String, + #[prost(uint64, tag = "3")] + pub fee_total_sat: u64, + #[prost(uint64, tag = "4")] + pub order_total_sat: u64, + #[prost(string, tag = "5")] + pub invoice: ::prost::alloc::string::String, +} +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] +#[cfg_attr(feature = "serde", serde(default))] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Lsps1Bolt12PaymentInfo { + #[prost(enumeration = "Lsps1PaymentState", tag = "1")] + pub state: i32, + #[prost(string, tag = "2")] + pub expires_at: ::prost::alloc::string::String, + #[prost(uint64, tag = "3")] + pub fee_total_sat: u64, + #[prost(uint64, tag = "4")] + pub order_total_sat: u64, + #[prost(string, tag = "5")] + pub offer: ::prost::alloc::string::String, +} +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] +#[cfg_attr(feature = "serde", serde(default))] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Lsps1OnchainPaymentInfo { + #[prost(enumeration = "Lsps1PaymentState", tag = "1")] + pub state: i32, + #[prost(string, tag = "2")] + pub expires_at: ::prost::alloc::string::String, + #[prost(uint64, tag = "3")] + pub fee_total_sat: u64, + #[prost(uint64, tag = "4")] + pub order_total_sat: u64, + #[prost(string, tag = "5")] + pub address: ::prost::alloc::string::String, + #[prost(uint32, optional, tag = "6")] + pub min_onchain_payment_confirmations: ::core::option::Option, + /// The LSPS1 value is in satoshis per 1000 weight units (sat/kwu). + #[prost(uint32, tag = "7")] + pub min_fee_for_0conf_sat_kwu: u32, + #[prost(string, optional, tag = "8")] + pub refund_onchain_address: ::core::option::Option<::prost::alloc::string::String>, +} +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] +#[cfg_attr(feature = "serde", serde(default))] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Lsps1ChannelInfo { + #[prost(string, tag = "1")] + pub funded_at: ::prost::alloc::string::String, + #[prost(string, tag = "2")] + pub funding_outpoint: ::prost::alloc::string::String, + #[prost(string, tag = "3")] + pub expires_at: ::prost::alloc::string::String, +} /// Increases the channel balance by the given amount. /// See more: #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -1833,3 +2013,40 @@ pub struct GetPermissionsResponse { #[prost(message, optional, tag = "1")] pub macaroon: ::core::option::Option, } +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum Lsps1PaymentState { + Unspecified = 0, + ExpectPayment = 1, + Hold = 2, + Paid = 3, + Refunded = 4, +} +impl Lsps1PaymentState { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Lsps1PaymentState::Unspecified => "LSPS1_PAYMENT_STATE_UNSPECIFIED", + Lsps1PaymentState::ExpectPayment => "LSPS1_PAYMENT_STATE_EXPECT_PAYMENT", + Lsps1PaymentState::Hold => "LSPS1_PAYMENT_STATE_HOLD", + Lsps1PaymentState::Paid => "LSPS1_PAYMENT_STATE_PAID", + Lsps1PaymentState::Refunded => "LSPS1_PAYMENT_STATE_REFUNDED", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "LSPS1_PAYMENT_STATE_UNSPECIFIED" => Some(Self::Unspecified), + "LSPS1_PAYMENT_STATE_EXPECT_PAYMENT" => Some(Self::ExpectPayment), + "LSPS1_PAYMENT_STATE_HOLD" => Some(Self::Hold), + "LSPS1_PAYMENT_STATE_PAID" => Some(Self::Paid), + "LSPS1_PAYMENT_STATE_REFUNDED" => Some(Self::Refunded), + _ => None, + } + } +} diff --git a/ldk-server-grpc/src/endpoints.rs b/ldk-server-grpc/src/endpoints.rs index eaad6c47..90aad6d2 100644 --- a/ldk-server-grpc/src/endpoints.rs +++ b/ldk-server-grpc/src/endpoints.rs @@ -34,6 +34,8 @@ pub const BOLT12_SEND_REFUND_PATH: &str = "Bolt12SendRefund"; pub const BOLT12_RECEIVE_REFUND_PATH: &str = "Bolt12ReceiveRefund"; pub const BOLT12_CREATE_PAYER_PROOF_PATH: &str = "Bolt12CreatePayerProof"; pub const OPEN_CHANNEL_PATH: &str = "OpenChannel"; +pub const LSPS1_REQUEST_CHANNEL_PATH: &str = "Lsps1RequestChannel"; +pub const LSPS1_CHECK_ORDER_STATUS_PATH: &str = "Lsps1CheckOrderStatus"; pub const SPLICE_IN_PATH: &str = "SpliceIn"; pub const SPLICE_OUT_PATH: &str = "SpliceOut"; pub const BUMP_CHANNEL_FUNDING_FEE_PATH: &str = "BumpChannelFundingFee"; diff --git a/ldk-server-grpc/src/permissions.rs b/ldk-server-grpc/src/permissions.rs index ee7059c7..c1d323cc 100644 --- a/ldk-server-grpc/src/permissions.rs +++ b/ldk-server-grpc/src/permissions.rs @@ -22,10 +22,11 @@ use crate::endpoints::{ GET_PERMISSIONS_PATH, GRAPH_GET_CHANNEL_PATH, GRAPH_GET_NODE_PATH, GRAPH_LIST_CHANNELS_PATH, GRAPH_LIST_NODES_PATH, LIST_CHANNELS_PATH, LIST_CHANNEL_FORWARDING_STATS_PATH, LIST_CHANNEL_PAIR_FORWARDING_STATS_PATH, LIST_FORWARDED_PAYMENTS_PATH, LIST_MACAROONS_PATH, - LIST_PAYMENTS_PATH, LIST_PEERS_PATH, ONCHAIN_BUMP_FEE_PATH, ONCHAIN_RECEIVE_PATH, - ONCHAIN_SEND_PATH, OPEN_CHANNEL_PATH, REVOKE_MACAROON_PATH, SIGN_MESSAGE_PATH, SPLICE_IN_PATH, - SPLICE_OUT_PATH, SPONTANEOUS_SEND_PATH, SPONTANEOUS_SEND_PROBES_PATH, SUBSCRIBE_EVENTS_PATH, - UNIFIED_SEND_PATH, UPDATE_CHANNEL_CONFIG_PATH, VERIFY_SIGNATURE_PATH, + LIST_PAYMENTS_PATH, LIST_PEERS_PATH, LSPS1_CHECK_ORDER_STATUS_PATH, LSPS1_REQUEST_CHANNEL_PATH, + ONCHAIN_BUMP_FEE_PATH, ONCHAIN_RECEIVE_PATH, ONCHAIN_SEND_PATH, OPEN_CHANNEL_PATH, + REVOKE_MACAROON_PATH, SIGN_MESSAGE_PATH, SPLICE_IN_PATH, SPLICE_OUT_PATH, + SPONTANEOUS_SEND_PATH, SPONTANEOUS_SEND_PROBES_PATH, SUBSCRIBE_EVENTS_PATH, UNIFIED_SEND_PATH, + UPDATE_CHANNEL_CONFIG_PATH, VERIFY_SIGNATURE_PATH, }; pub const ADMIN_PERMISSION: &str = "admin"; @@ -194,7 +195,9 @@ pub fn method_authorization(method: &str) -> MethodAuthorization { MethodAuthorization::Permission(PAYMENTS_READ_PERMISSION) }, LIST_CHANNELS_PATH => MethodAuthorization::Permission(CHANNELS_READ_PERMISSION), + LSPS1_CHECK_ORDER_STATUS_PATH => MethodAuthorization::Permission(CHANNELS_READ_PERMISSION), OPEN_CHANNEL_PATH + | LSPS1_REQUEST_CHANNEL_PATH | UPDATE_CHANNEL_CONFIG_PATH | CLOSE_CHANNEL_PATH | SPLICE_IN_PATH diff --git a/ldk-server-grpc/src/proto/api.proto b/ldk-server-grpc/src/proto/api.proto index f1b8491d..ab2bbc3f 100644 --- a/ldk-server-grpc/src/proto/api.proto +++ b/ldk-server-grpc/src/proto/api.proto @@ -642,6 +642,111 @@ message OpenChannelResponse { string user_channel_id = 1; } +// Place an order for an inbound channel from the configured LSPS1 LSP. +message Lsps1RequestChannelRequest { + // The balance in satoshis the LSP will contribute to the channel. + uint64 lsp_balance_sat = 1; + + // The balance in satoshis the client will contribute to the channel. + uint64 client_balance_sat = 2; + + // How long the channel should be leased, in blocks. + uint32 channel_expiry_blocks = 3; + + // Whether the channel should be announced to the network. + bool announce_channel = 4; + + // Optional hex-encoded LSP node ID. If unset, the first configured LSPS1 LSP is used. + optional string lsp_node_id = 5; +} + +// The response for `Lsps1RequestChannel`. The client must pay one of the returned payment +// options before the LSP opens the channel. +message Lsps1RequestChannelResponse { + Lsps1OrderStatus order_status = 1; +} + +// Check the status of an existing LSPS1 channel order with the configured LSP. +message Lsps1CheckOrderStatusRequest { + // The order ID returned by `Lsps1RequestChannel`. + string order_id = 1; + + // The hex-encoded node ID of the LSP that received the order. + string lsp_node_id = 2; +} + +// The response for `Lsps1CheckOrderStatus`. +message Lsps1CheckOrderStatusResponse { + Lsps1OrderStatus order_status = 1; +} + +// The status returned by LDK Node for an LSPS1 channel order. +message Lsps1OrderStatus { + string order_id = 1; + Lsps1OrderParams order_params = 2; + Lsps1PaymentOptions payment_options = 3; + // Present after the LSP publishes the channel funding transaction. + Lsps1ChannelInfo channel_state = 4; +} + +message Lsps1OrderParams { + uint64 lsp_balance_sat = 1; + uint64 client_balance_sat = 2; + uint32 required_channel_confirmations = 3; + uint32 funding_confirms_within_blocks = 4; + uint32 channel_expiry_blocks = 5; + optional string token = 6; + bool announce_channel = 7; +} + +message Lsps1PaymentOptions { + Lsps1Bolt11PaymentInfo bolt11 = 1; + Lsps1Bolt12PaymentInfo bolt12 = 2; + Lsps1OnchainPaymentInfo onchain = 3; +} + +enum Lsps1PaymentState { + LSPS1_PAYMENT_STATE_UNSPECIFIED = 0; + LSPS1_PAYMENT_STATE_EXPECT_PAYMENT = 1; + LSPS1_PAYMENT_STATE_HOLD = 2; + LSPS1_PAYMENT_STATE_PAID = 3; + LSPS1_PAYMENT_STATE_REFUNDED = 4; +} + +message Lsps1Bolt11PaymentInfo { + Lsps1PaymentState state = 1; + string expires_at = 2; + uint64 fee_total_sat = 3; + uint64 order_total_sat = 4; + string invoice = 5; +} + +message Lsps1Bolt12PaymentInfo { + Lsps1PaymentState state = 1; + string expires_at = 2; + uint64 fee_total_sat = 3; + uint64 order_total_sat = 4; + string offer = 5; +} + +message Lsps1OnchainPaymentInfo { + Lsps1PaymentState state = 1; + string expires_at = 2; + uint64 fee_total_sat = 3; + uint64 order_total_sat = 4; + string address = 5; + optional uint32 min_onchain_payment_confirmations = 6; + // The LSPS1 value is in satoshis per 1000 weight units (sat/kwu). + uint32 min_fee_for_0conf_sat_kwu = 7; + optional string refund_onchain_address = 8; +} + +message Lsps1ChannelInfo { + string funded_at = 1; + string funding_outpoint = 2; + string expires_at = 3; +} + // Increases the channel balance by the given amount. // See more: https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.splice_in message SpliceInRequest { @@ -1323,6 +1428,10 @@ service LightningNode { rpc SpontaneousSendProbes(SpontaneousSendProbesRequest) returns (SpontaneousSendProbesResponse); // Create a new outbound channel. rpc OpenChannel(OpenChannelRequest) returns (OpenChannelResponse); + // Place an LSPS1 order for an inbound channel from the configured LSP. + rpc Lsps1RequestChannel(Lsps1RequestChannelRequest) returns (Lsps1RequestChannelResponse); + // Check the status of a previously placed LSPS1 channel order. + rpc Lsps1CheckOrderStatus(Lsps1CheckOrderStatusRequest) returns (Lsps1CheckOrderStatusResponse); // Splice funds into a channel. rpc SpliceIn(SpliceInRequest) returns (SpliceInResponse); // Splice funds out of a channel. diff --git a/ldk-server-mcp/src/tools/handlers.rs b/ldk-server-mcp/src/tools/handlers.rs index 3e90f15c..400f1f7c 100644 --- a/ldk-server-mcp/src/tools/handlers.rs +++ b/ldk-server-mcp/src/tools/handlers.rs @@ -23,10 +23,11 @@ use ldk_server_client::ldk_server_grpc::api::{ GetPaymentDetailsRequest, GetPermissionsRequest, GraphGetChannelRequest, GraphGetNodeRequest, GraphListChannelsRequest, GraphListNodesRequest, ListChannelForwardingStatsRequest, ListChannelPairForwardingStatsRequest, ListChannelsRequest, ListForwardedPaymentsRequest, - ListMacaroonsRequest, ListPaymentsRequest, ListPeersRequest, OnchainBumpFeeRequest, - OnchainReceiveRequest, OnchainSendRequest, OpenChannelRequest, RevokeMacaroonRequest, - SignMessageRequest, SpliceInRequest, SpliceOutRequest, SpontaneousSendProbesRequest, - SpontaneousSendRequest, UnifiedSendRequest, UpdateChannelConfigRequest, VerifySignatureRequest, + ListMacaroonsRequest, ListPaymentsRequest, ListPeersRequest, Lsps1CheckOrderStatusRequest, + Lsps1RequestChannelRequest, OnchainBumpFeeRequest, OnchainReceiveRequest, OnchainSendRequest, + OpenChannelRequest, RevokeMacaroonRequest, SignMessageRequest, SpliceInRequest, + SpliceOutRequest, SpontaneousSendProbesRequest, SpontaneousSendRequest, UnifiedSendRequest, + UpdateChannelConfigRequest, VerifySignatureRequest, }; use ldk_server_client::ldk_server_grpc::types::RouteParametersConfig; use ldk_server_client::{ @@ -394,6 +395,22 @@ pub async fn handle_open_channel(client: &LdkServerClient, args: Value) -> Resul serialize_response(response) } +pub async fn handle_lsps1_request_channel( + client: &LdkServerClient, args: Value, +) -> Result { + let request: Lsps1RequestChannelRequest = parse_request(args)?; + let response = client.lsps1_request_channel(request).await.map_err(McpError::from)?; + serialize_response(response) +} + +pub async fn handle_lsps1_check_order_status( + client: &LdkServerClient, args: Value, +) -> Result { + let request: Lsps1CheckOrderStatusRequest = parse_request(args)?; + let response = client.lsps1_check_order_status(request).await.map_err(McpError::from)?; + serialize_response(response) +} + pub async fn handle_splice_in(client: &LdkServerClient, args: Value) -> Result { let request: SpliceInRequest = parse_request_with_amount(args, "splice_amount_sats")?; let response = client.splice_in(request).await.map_err(McpError::from)?; diff --git a/ldk-server-mcp/src/tools/mod.rs b/ldk-server-mcp/src/tools/mod.rs index f2b5deb9..59130f70 100644 --- a/ldk-server-mcp/src/tools/mod.rs +++ b/ldk-server-mcp/src/tools/mod.rs @@ -31,9 +31,10 @@ use ldk_server_client::ldk_server_grpc::endpoints::{ GET_PERMISSIONS_PATH, GRAPH_GET_CHANNEL_PATH, GRAPH_GET_NODE_PATH, GRAPH_LIST_CHANNELS_PATH, GRAPH_LIST_NODES_PATH, LIST_CHANNELS_PATH, LIST_CHANNEL_FORWARDING_STATS_PATH, LIST_CHANNEL_PAIR_FORWARDING_STATS_PATH, LIST_FORWARDED_PAYMENTS_PATH, LIST_MACAROONS_PATH, - LIST_PAYMENTS_PATH, LIST_PEERS_PATH, ONCHAIN_BUMP_FEE_PATH, ONCHAIN_RECEIVE_PATH, - ONCHAIN_SEND_PATH, OPEN_CHANNEL_PATH, REVOKE_MACAROON_PATH, SIGN_MESSAGE_PATH, SPLICE_IN_PATH, - SPLICE_OUT_PATH, SPONTANEOUS_SEND_PATH, SPONTANEOUS_SEND_PROBES_PATH, UNIFIED_SEND_PATH, + LIST_PAYMENTS_PATH, LIST_PEERS_PATH, LSPS1_CHECK_ORDER_STATUS_PATH, LSPS1_REQUEST_CHANNEL_PATH, + ONCHAIN_BUMP_FEE_PATH, ONCHAIN_RECEIVE_PATH, ONCHAIN_SEND_PATH, OPEN_CHANNEL_PATH, + REVOKE_MACAROON_PATH, SIGN_MESSAGE_PATH, SPLICE_IN_PATH, SPLICE_OUT_PATH, + SPONTANEOUS_SEND_PATH, SPONTANEOUS_SEND_PROBES_PATH, UNIFIED_SEND_PATH, UPDATE_CHANNEL_CONFIG_PATH, VERIFY_SIGNATURE_PATH, }; use ldk_server_client::ldk_server_grpc::permissions::{ @@ -339,6 +340,20 @@ pub fn build_tool_registry() -> ToolRegistry { schema::open_channel_schema, |client, args| Box::pin(handlers::handle_open_channel(client, args)), ), + tool_spec( + "lsps1_request_channel", + LSPS1_REQUEST_CHANNEL_PATH, + "Place an LSPS1 order for an inbound channel from the configured LSP", + schema::lsps1_request_channel_schema, + |client, args| Box::pin(handlers::handle_lsps1_request_channel(client, args)), + ), + tool_spec( + "lsps1_check_order_status", + LSPS1_CHECK_ORDER_STATUS_PATH, + "Check the status of a previously placed LSPS1 channel order", + schema::lsps1_check_order_status_schema, + |client, args| Box::pin(handlers::handle_lsps1_check_order_status(client, args)), + ), tool_spec( "splice_in", SPLICE_IN_PATH, diff --git a/ldk-server-mcp/src/tools/schema.rs b/ldk-server-mcp/src/tools/schema.rs index 223f4dc0..f110d311 100644 --- a/ldk-server-mcp/src/tools/schema.rs +++ b/ldk-server-mcp/src/tools/schema.rs @@ -673,6 +673,52 @@ pub fn open_channel_schema() -> Value { }) } +pub fn lsps1_request_channel_schema() -> Value { + json!({ + "type": "object", + "properties": { + "lsp_balance_sat": { + "type": "integer", + "description": "The balance in satoshis the LSP will contribute to the channel" + }, + "client_balance_sat": { + "type": "integer", + "description": "The balance in satoshis the client will contribute to the channel" + }, + "channel_expiry_blocks": { + "type": "integer", + "description": "How long the channel should be leased, in blocks" + }, + "announce_channel": { + "type": "boolean", + "description": "Whether the channel should be announced to the network" + }, + "lsp_node_id": { + "type": "string", + "description": "Optional hex-encoded node ID of the configured LSP to use" + } + }, + "required": ["lsp_balance_sat", "client_balance_sat", "channel_expiry_blocks"] + }) +} + +pub fn lsps1_check_order_status_schema() -> Value { + json!({ + "type": "object", + "properties": { + "order_id": { + "type": "string", + "description": "The order ID returned by lsps1_request_channel" + }, + "lsp_node_id": { + "type": "string", + "description": "Hex-encoded node ID of the LSP that received the order" + } + }, + "required": ["order_id", "lsp_node_id"] + }) +} + pub fn splice_in_schema() -> Value { json!({ "type": "object", diff --git a/ldk-server-mcp/tests/integration.rs b/ldk-server-mcp/tests/integration.rs index 48c4bc5c..329e7cb5 100644 --- a/ldk-server-mcp/tests/integration.rs +++ b/ldk-server-mcp/tests/integration.rs @@ -11,7 +11,7 @@ use std::io::{BufRead, BufReader, Write}; use serde_json::{json, Value}; -const NUM_TOOLS: usize = 56; +const NUM_TOOLS: usize = 58; const EXPECTED_TOOLS: [&str; NUM_TOOLS] = [ "bolt11_claim_for_id", "bolt11_fail_for_id", @@ -56,6 +56,8 @@ const EXPECTED_TOOLS: [&str; NUM_TOOLS] = [ "list_forwarded_payments", "list_payments", "list_peers", + "lsps1_check_order_status", + "lsps1_request_channel", "onchain_bump_fee", "onchain_receive", "onchain_send", diff --git a/ldk-server/src/api/lsps1.rs b/ldk-server/src/api/lsps1.rs new file mode 100644 index 00000000..1bba0503 --- /dev/null +++ b/ldk-server/src/api/lsps1.rs @@ -0,0 +1,140 @@ +// This file is Copyright its original authors, visible in version control +// history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license +// , at your option. +// You may not use this file except in compliance with one or both of these +// licenses. + +use std::str::FromStr; + +use ldk_node::lightning_liquidity::lsps1::msgs::{ + LSPS1Bolt11PaymentInfo, LSPS1Bolt12PaymentInfo, LSPS1ChannelInfo, LSPS1OnchainPaymentInfo, + LSPS1OrderParams, LSPS1PaymentState, +}; +use ldk_node::liquidity::LSPS1OrderStatus; +use ldk_server_grpc::api::{ + Lsps1Bolt11PaymentInfo as ProtoBolt11PaymentInfo, + Lsps1Bolt12PaymentInfo as ProtoBolt12PaymentInfo, Lsps1ChannelInfo as ProtoChannelInfo, + Lsps1CheckOrderStatusRequest, Lsps1CheckOrderStatusResponse, + Lsps1OnchainPaymentInfo as ProtoOnchainPaymentInfo, Lsps1OrderParams as ProtoOrderParams, + Lsps1OrderStatus as ProtoOrderStatus, Lsps1PaymentOptions as ProtoPaymentOptions, + Lsps1PaymentState as ProtoPaymentState, Lsps1RequestChannelRequest, + Lsps1RequestChannelResponse, +}; + +use crate::api::error::LdkServerError; +use crate::service::Context; + +pub(crate) async fn handle_lsps1_request_channel_request( + context: std::sync::Arc, request: Lsps1RequestChannelRequest, +) -> Result { + let lsp_node_id = request + .lsp_node_id + .as_deref() + .map(ldk_node::bitcoin::secp256k1::PublicKey::from_str) + .transpose() + .map_err(|_| ldk_node::NodeError::InvalidPublicKey)?; + let order_status = context.node.liquidity().lsps1().request_channel( + request.lsp_balance_sat, + request.client_balance_sat, + request.channel_expiry_blocks, + request.announce_channel, + lsp_node_id, + )?; + Ok(Lsps1RequestChannelResponse { order_status: Some(order_status_to_proto(order_status)) }) +} + +pub(crate) async fn handle_lsps1_check_order_status_request( + context: std::sync::Arc, request: Lsps1CheckOrderStatusRequest, +) -> Result { + let lsp_node_id = ldk_node::bitcoin::secp256k1::PublicKey::from_str(&request.lsp_node_id) + .map_err(|_| ldk_node::NodeError::InvalidPublicKey)?; + let order_status = context.node.liquidity().lsps1().check_order_status( + ldk_node::lightning_liquidity::lsps1::msgs::LSPS1OrderId(request.order_id), + lsp_node_id, + )?; + Ok(Lsps1CheckOrderStatusResponse { order_status: Some(order_status_to_proto(order_status)) }) +} + +fn order_status_to_proto(status: LSPS1OrderStatus) -> ProtoOrderStatus { + ProtoOrderStatus { + order_id: status.order_id.0, + order_params: Some(order_params_to_proto(status.order_params)), + payment_options: Some(payment_options_to_proto(status.payment_options)), + channel_state: status.channel_state.map(channel_info_to_proto), + } +} + +fn order_params_to_proto(params: LSPS1OrderParams) -> ProtoOrderParams { + ProtoOrderParams { + lsp_balance_sat: params.lsp_balance_sat, + client_balance_sat: params.client_balance_sat, + required_channel_confirmations: u32::from(params.required_channel_confirmations), + funding_confirms_within_blocks: u32::from(params.funding_confirms_within_blocks), + channel_expiry_blocks: params.channel_expiry_blocks, + token: params.token, + announce_channel: params.announce_channel, + } +} + +fn payment_options_to_proto( + options: ldk_node::lightning_liquidity::lsps1::msgs::LSPS1PaymentInfo, +) -> ProtoPaymentOptions { + ProtoPaymentOptions { + bolt11: options.bolt11.map(bolt11_payment_to_proto), + bolt12: options.bolt12.map(bolt12_payment_to_proto), + onchain: options.onchain.map(onchain_payment_to_proto), + } +} + +fn payment_state_to_proto(state: LSPS1PaymentState) -> i32 { + match state { + LSPS1PaymentState::ExpectPayment => ProtoPaymentState::ExpectPayment as i32, + LSPS1PaymentState::Hold => ProtoPaymentState::Hold as i32, + LSPS1PaymentState::Paid => ProtoPaymentState::Paid as i32, + LSPS1PaymentState::Refunded => ProtoPaymentState::Refunded as i32, + } +} + +fn bolt11_payment_to_proto(payment: LSPS1Bolt11PaymentInfo) -> ProtoBolt11PaymentInfo { + ProtoBolt11PaymentInfo { + state: payment_state_to_proto(payment.state), + expires_at: payment.expires_at.to_rfc3339(), + fee_total_sat: payment.fee_total_sat, + order_total_sat: payment.order_total_sat, + invoice: payment.invoice.to_string(), + } +} + +fn bolt12_payment_to_proto(payment: LSPS1Bolt12PaymentInfo) -> ProtoBolt12PaymentInfo { + ProtoBolt12PaymentInfo { + state: payment_state_to_proto(payment.state), + expires_at: payment.expires_at.to_rfc3339(), + fee_total_sat: payment.fee_total_sat, + order_total_sat: payment.order_total_sat, + offer: payment.offer.to_string(), + } +} + +fn onchain_payment_to_proto(payment: LSPS1OnchainPaymentInfo) -> ProtoOnchainPaymentInfo { + ProtoOnchainPaymentInfo { + state: payment_state_to_proto(payment.state), + expires_at: payment.expires_at.to_rfc3339(), + fee_total_sat: payment.fee_total_sat, + order_total_sat: payment.order_total_sat, + address: payment.address.to_string(), + min_onchain_payment_confirmations: payment.min_onchain_payment_confirmations.map(u32::from), + min_fee_for_0conf_sat_kwu: payment.min_fee_for_0conf.to_sat_per_kwu() as u32, + refund_onchain_address: payment.refund_onchain_address.map(|address| address.to_string()), + } +} + +fn channel_info_to_proto(channel: LSPS1ChannelInfo) -> ProtoChannelInfo { + ProtoChannelInfo { + funded_at: channel.funded_at.to_rfc3339(), + funding_outpoint: channel.funding_outpoint.to_string(), + expires_at: channel.expires_at.to_rfc3339(), + } +} diff --git a/ldk-server/src/api/mod.rs b/ldk-server/src/api/mod.rs index 04a92c87..3b4f21ea 100644 --- a/ldk-server/src/api/mod.rs +++ b/ldk-server/src/api/mod.rs @@ -52,6 +52,7 @@ pub(crate) mod list_channels; pub(crate) mod list_forwarded_payments; pub(crate) mod list_payments; pub(crate) mod list_peers; +pub(crate) mod lsps1; pub(crate) mod macaroons; pub(crate) mod onchain_bump_fee; pub(crate) mod onchain_receive; diff --git a/ldk-server/src/macaroons/authorization.rs b/ldk-server/src/macaroons/authorization.rs index b8b222be..0604840a 100644 --- a/ldk-server/src/macaroons/authorization.rs +++ b/ldk-server/src/macaroons/authorization.rs @@ -49,6 +49,8 @@ mod tests { ("SpontaneousSend", Some("payments:send")), ("SpontaneousSendProbes", Some("payments:send")), ("OpenChannel", Some("channels:manage")), + ("Lsps1RequestChannel", Some("channels:manage")), + ("Lsps1CheckOrderStatus", Some("channels:read")), ("SpliceIn", Some("channels:manage")), ("SpliceOut", Some("payments:send")), ("BumpChannelFundingFee", Some("channels:manage")), diff --git a/ldk-server/src/service.rs b/ldk-server/src/service.rs index 79c642e8..1027f1e3 100644 --- a/ldk-server/src/service.rs +++ b/ldk-server/src/service.rs @@ -32,9 +32,10 @@ use ldk_server_grpc::endpoints::{ GRAPH_LIST_CHANNELS_PATH, GRAPH_LIST_NODES_PATH, LIST_CHANNELS_PATH, LIST_CHANNEL_FORWARDING_STATS_PATH, LIST_CHANNEL_PAIR_FORWARDING_STATS_PATH, LIST_FORWARDED_PAYMENTS_PATH, LIST_MACAROONS_PATH, LIST_PAYMENTS_PATH, LIST_PEERS_PATH, - ONCHAIN_BUMP_FEE_PATH, ONCHAIN_RECEIVE_PATH, ONCHAIN_SEND_PATH, OPEN_CHANNEL_PATH, - REVOKE_MACAROON_PATH, SIGN_MESSAGE_PATH, SPLICE_IN_PATH, SPLICE_OUT_PATH, - SPONTANEOUS_SEND_PATH, SPONTANEOUS_SEND_PROBES_PATH, SUBSCRIBE_EVENTS_PATH, UNIFIED_SEND_PATH, + LSPS1_CHECK_ORDER_STATUS_PATH, LSPS1_REQUEST_CHANNEL_PATH, ONCHAIN_BUMP_FEE_PATH, + ONCHAIN_RECEIVE_PATH, ONCHAIN_SEND_PATH, OPEN_CHANNEL_PATH, REVOKE_MACAROON_PATH, + SIGN_MESSAGE_PATH, SPLICE_IN_PATH, SPLICE_OUT_PATH, SPONTANEOUS_SEND_PATH, + SPONTANEOUS_SEND_PROBES_PATH, SUBSCRIBE_EVENTS_PATH, UNIFIED_SEND_PATH, UPDATE_CHANNEL_CONFIG_PATH, VERIFY_SIGNATURE_PATH, }; use ldk_server_grpc::events::EventEnvelope; @@ -88,6 +89,9 @@ use crate::api::list_channels::handle_list_channels_request; use crate::api::list_forwarded_payments::handle_list_forwarded_payments_request; use crate::api::list_payments::handle_list_payments_request; use crate::api::list_peers::handle_list_peers_request; +use crate::api::lsps1::{ + handle_lsps1_check_order_status_request, handle_lsps1_request_channel_request, +}; use crate::api::macaroons::{ handle_create_macaroon_request, handle_get_permissions_request, handle_list_macaroons_request, handle_revoke_macaroon_request, @@ -334,6 +338,14 @@ impl Service> for NodeService { OPEN_CHANNEL_PATH => { handle_grpc_unary(context, body_bytes, handle_open_channel).await }, + LSPS1_REQUEST_CHANNEL_PATH => { + handle_grpc_unary(context, body_bytes, handle_lsps1_request_channel_request) + .await + }, + LSPS1_CHECK_ORDER_STATUS_PATH => { + handle_grpc_unary(context, body_bytes, handle_lsps1_check_order_status_request) + .await + }, SPLICE_IN_PATH => { handle_grpc_unary(context, body_bytes, handle_splice_in_request).await },