Skip to content

Commit 46760c8

Browse files
committed
allow route_parameters in BOLT11 send API
1 parent 7aef8ee commit 46760c8

File tree

4 files changed

+55
-12
lines changed

4 files changed

+55
-12
lines changed

ldk-server-cli/src/main.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use ldk_server_client::ldk_server_protos::api::{
1010
ListChannelsRequest, ListPaymentsRequest, OnchainReceiveRequest, OnchainSendRequest,
1111
OpenChannelRequest,
1212
};
13+
use ldk_server_client::ldk_server_protos::types::RouteParametersConfig;
1314
use ldk_server_client::ldk_server_protos::types::{
1415
bolt11_invoice_description, Bolt11InvoiceDescription, PageToken, Payment,
1516
};
@@ -55,6 +56,14 @@ enum Commands {
5556
invoice: String,
5657
#[arg(long)]
5758
amount_msat: Option<u64>,
59+
#[arg(long)]
60+
max_total_routing_fee_msat: Option<u64>,
61+
#[arg(long)]
62+
max_total_cltv_expiry_delta: Option<u32>,
63+
#[arg(long)]
64+
max_path_count: Option<u32>,
65+
#[arg(long)]
66+
max_channel_saturation_power_of_half: Option<u32>,
5867
},
5968
Bolt12Receive {
6069
#[arg(short, long)]
@@ -161,9 +170,29 @@ async fn main() {
161170

162171
handle_response_result(client.bolt11_receive(request).await);
163172
},
164-
Commands::Bolt11Send { invoice, amount_msat } => {
173+
Commands::Bolt11Send {
174+
invoice,
175+
amount_msat,
176+
max_total_routing_fee_msat,
177+
max_total_cltv_expiry_delta,
178+
max_path_count,
179+
max_channel_saturation_power_of_half,
180+
} => {
181+
let route_parameters = RouteParametersConfig {
182+
max_total_routing_fee_msat,
183+
max_total_cltv_expiry_delta: max_total_cltv_expiry_delta.unwrap_or_default(),
184+
max_path_count: max_path_count.unwrap_or_default(),
185+
max_channel_saturation_power_of_half: max_channel_saturation_power_of_half
186+
.unwrap_or_default(),
187+
};
165188
handle_response_result(
166-
client.bolt11_send(Bolt11SendRequest { invoice, amount_msat }).await,
189+
client
190+
.bolt11_send(Bolt11SendRequest {
191+
invoice,
192+
amount_msat,
193+
route_parameters: Some(route_parameters),
194+
})
195+
.await,
167196
);
168197
},
169198
Commands::Bolt12Receive { description, amount_msat, expiry_secs, quantity } => {

ldk-server-protos/src/api.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,17 @@ pub struct Bolt11ReceiveResponse {
133133
#[allow(clippy::derive_partial_eq_without_eq)]
134134
#[derive(Clone, PartialEq, ::prost::Message)]
135135
pub struct Bolt11SendRequest {
136-
/// An invoice for a payment within the Lightning Network.
137-
#[prost(string, tag = "1")]
138-
pub invoice: ::prost::alloc::string::String,
139-
/// Set this field when paying a so-called "zero-amount" invoice, i.e., an invoice that leaves the
140-
/// amount paid to be determined by the user.
141-
/// This operation will fail if the amount specified is less than the value required by the given invoice.
142-
#[prost(uint64, optional, tag = "2")]
143-
pub amount_msat: ::core::option::Option<u64>,
136+
/// An invoice for a payment within the Lightning Network.
137+
#[prost(string, tag = "1")]
138+
pub invoice: ::prost::alloc::string::String,
139+
/// Set this field when paying a so-called "zero-amount" invoice, i.e., an invoice that leaves the
140+
/// amount paid to be determined by the user.
141+
/// This operation will fail if the amount specified is less than the value required by the given invoice.
142+
#[prost(uint64, optional, tag = "2")]
143+
pub amount_msat: ::core::option::Option<u64>,
144+
/// Configuration options for payment routing and pathfinding.
145+
#[prost(message, optional, tag = "3")]
146+
pub route_parameters: ::core::option::Option<super::types::RouteParametersConfig>,
144147
}
145148
/// The response `content` for the `Bolt11Send` API, when HttpStatusCode is OK (200).
146149
/// When HttpStatusCode is not OK (non-200), the response `content` contains a serialized `ErrorResponse`.

ldk-server-protos/src/proto/api.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ message Bolt11SendRequest {
138138
// amount paid to be determined by the user.
139139
// This operation will fail if the amount specified is less than the value required by the given invoice.
140140
optional uint64 amount_msat = 2;
141+
142+
// Configuration options for payment routing and pathfinding.
143+
optional types.RouteParametersConfig route_parameters = 3;
141144

142145
}
143146

ldk-server/src/api/bolt11_send.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::api::error::LdkServerError;
22
use crate::service::Context;
3+
use ldk_node::lightning::routing::router::RouteParametersConfig;
34
use ldk_node::lightning_invoice::Bolt11Invoice;
45
use ldk_server_protos::api::{Bolt11SendRequest, Bolt11SendResponse};
56
use std::str::FromStr;
@@ -12,10 +13,17 @@ pub(crate) fn handle_bolt11_send_request(
1213
let invoice = Bolt11Invoice::from_str(&request.invoice.as_str())
1314
.map_err(|_| ldk_node::NodeError::InvalidInvoice)?;
1415

16+
let route_parameters = request.route_parameters.map(|params| RouteParametersConfig {
17+
max_total_routing_fee_msat: params.max_total_routing_fee_msat,
18+
max_total_cltv_expiry_delta: params.max_total_cltv_expiry_delta,
19+
max_path_count: params.max_path_count as u8,
20+
max_channel_saturation_power_of_half: params.max_channel_saturation_power_of_half as u8,
21+
});
22+
1523
let payment_id = match request.amount_msat {
16-
None => context.node.bolt11_payment().send(&invoice, None),
24+
None => context.node.bolt11_payment().send(&invoice, route_parameters),
1725
Some(amount_msat) => {
18-
context.node.bolt11_payment().send_using_amount(&invoice, amount_msat, None)
26+
context.node.bolt11_payment().send_using_amount(&invoice, amount_msat, route_parameters)
1927
},
2028
}?;
2129

0 commit comments

Comments
 (0)