Skip to content

Commit 96842d2

Browse files
committed
allow route_parameters in BOLT12 send API
1 parent 46760c8 commit 96842d2

File tree

5 files changed

+82
-34
lines changed

5 files changed

+82
-34
lines changed

ldk-server-cli/src/main.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ enum Commands {
8484
quantity: Option<u64>,
8585
#[arg(short, long)]
8686
payer_note: Option<String>,
87+
#[arg(long)]
88+
max_total_routing_fee_msat: Option<u64>,
89+
#[arg(long)]
90+
max_total_cltv_expiry_delta: Option<u32>,
91+
#[arg(long)]
92+
max_path_count: Option<u32>,
93+
#[arg(long)]
94+
max_channel_saturation_power_of_half: Option<u32>,
8795
},
8896
CloseChannel {
8997
#[arg(short, long)]
@@ -207,10 +215,33 @@ async fn main() {
207215
.await,
208216
);
209217
},
210-
Commands::Bolt12Send { offer, amount_msat, quantity, payer_note } => {
218+
Commands::Bolt12Send {
219+
offer,
220+
amount_msat,
221+
quantity,
222+
payer_note,
223+
max_total_routing_fee_msat,
224+
max_total_cltv_expiry_delta,
225+
max_path_count,
226+
max_channel_saturation_power_of_half,
227+
} => {
228+
let route_parameters = RouteParametersConfig {
229+
max_total_routing_fee_msat,
230+
max_total_cltv_expiry_delta: max_total_cltv_expiry_delta.unwrap_or_default(),
231+
max_path_count: max_path_count.unwrap_or_default(),
232+
max_channel_saturation_power_of_half: max_channel_saturation_power_of_half
233+
.unwrap_or_default(),
234+
};
235+
211236
handle_response_result(
212237
client
213-
.bolt12_send(Bolt12SendRequest { offer, amount_msat, quantity, payer_note })
238+
.bolt12_send(Bolt12SendRequest {
239+
offer,
240+
amount_msat,
241+
quantity,
242+
payer_note,
243+
route_parameters: Some(route_parameters),
244+
})
214245
.await,
215246
);
216247
},

ldk-server-protos/src/api.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +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>,
144-
/// Configuration options for payment routing and pathfinding.
145-
#[prost(message, optional, tag = "3")]
146-
pub route_parameters: ::core::option::Option<super::types::RouteParametersConfig>,
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>,
147147
}
148148
/// The response `content` for the `Bolt11Send` API, when HttpStatusCode is OK (200).
149149
/// When HttpStatusCode is not OK (non-200), the response `content` contains a serialized `ErrorResponse`.
@@ -208,6 +208,9 @@ pub struct Bolt12SendRequest {
208208
/// If set, it will be seen by the recipient and reflected back in the invoice.
209209
#[prost(string, optional, tag = "4")]
210210
pub payer_note: ::core::option::Option<::prost::alloc::string::String>,
211+
/// Configuration options for payment routing and pathfinding.
212+
#[prost(message, optional, tag = "5")]
213+
pub route_parameters: ::core::option::Option<super::types::RouteParametersConfig>,
211214
}
212215
/// The response `content` for the `Bolt12Send` API, when HttpStatusCode is OK (200).
213216
/// 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
@@ -202,6 +202,9 @@ message Bolt12SendRequest {
202202

203203
// If set, it will be seen by the recipient and reflected back in the invoice.
204204
optional string payer_note = 4;
205+
206+
// Configuration options for payment routing and pathfinding.
207+
optional types.RouteParametersConfig route_parameters = 5;
205208
}
206209

207210
// The response `content` for the `Bolt12Send` API, when HttpStatusCode is OK (200).

ldk-server-protos/src/types.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -784,23 +784,23 @@ pub mod bolt11_invoice_description {
784784
#[allow(clippy::derive_partial_eq_without_eq)]
785785
#[derive(Clone, PartialEq, ::prost::Message)]
786786
pub struct RouteParametersConfig {
787-
/// The maximum total fees, in millisatoshi, that may accrue during route finding.
788-
/// Defaults to 1% of the payment amount + 50 sats
789-
#[prost(uint64, optional, tag = "1")]
790-
pub max_total_routing_fee_msat: ::core::option::Option<u64>,
791-
/// The maximum total CLTV delta we accept for the route.
792-
/// Defaults to \[`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`\].
793-
#[prost(uint32, tag = "2")]
794-
pub max_total_cltv_expiry_delta: u32,
795-
/// The maximum number of paths that may be used by (MPP) payments.
796-
/// Defaults to \[`DEFAULT_MAX_PATH_COUNT`\].
797-
#[prost(uint32, tag = "3")]
798-
pub max_path_count: u32,
799-
/// Selects the maximum share of a channel's total capacity which will be
800-
/// sent over a channel, as a power of 1/2.
801-
/// Default value: 2
802-
#[prost(uint32, tag = "4")]
803-
pub max_channel_saturation_power_of_half: u32,
787+
/// The maximum total fees, in millisatoshi, that may accrue during route finding.
788+
/// Defaults to 1% of the payment amount + 50 sats
789+
#[prost(uint64, optional, tag = "1")]
790+
pub max_total_routing_fee_msat: ::core::option::Option<u64>,
791+
/// The maximum total CLTV delta we accept for the route.
792+
/// Defaults to \[`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`\].
793+
#[prost(uint32, tag = "2")]
794+
pub max_total_cltv_expiry_delta: u32,
795+
/// The maximum number of paths that may be used by (MPP) payments.
796+
/// Defaults to \[`DEFAULT_MAX_PATH_COUNT`\].
797+
#[prost(uint32, tag = "3")]
798+
pub max_path_count: u32,
799+
/// Selects the maximum share of a channel's total capacity which will be
800+
/// sent over a channel, as a power of 1/2.
801+
/// Default value: 2
802+
#[prost(uint32, tag = "4")]
803+
pub max_channel_saturation_power_of_half: u32,
804804
}
805805
/// Represents the direction of a payment.
806806
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]

ldk-server/src/api/bolt12_send.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::api::error::LdkServerError;
22
use crate::service::Context;
33
use ldk_node::lightning::offers::offer::Offer;
4+
use ldk_node::lightning::routing::router::RouteParametersConfig;
45
use ldk_server_protos::api::{Bolt12SendRequest, Bolt12SendResponse};
56
use std::str::FromStr;
67

@@ -12,16 +13,26 @@ pub(crate) fn handle_bolt12_send_request(
1213
let offer =
1314
Offer::from_str(&request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;
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 => {
17-
context.node.bolt12_payment().send(&offer, request.quantity, request.payer_note, None)
18-
},
24+
None => context.node.bolt12_payment().send(
25+
&offer,
26+
request.quantity,
27+
request.payer_note,
28+
route_parameters,
29+
),
1930
Some(amount_msat) => context.node.bolt12_payment().send_using_amount(
2031
&offer,
2132
amount_msat,
2233
request.quantity,
2334
request.payer_note,
24-
None,
35+
route_parameters,
2536
),
2637
}?;
2738

0 commit comments

Comments
 (0)