@@ -190,14 +190,20 @@ impl Bolt11Payment {
190
190
}
191
191
}
192
192
193
- /// Send a payment given an invoice and an amount in millisatoshi .
193
+ /// Send a payment given an invoice and an amount in millisatoshis .
194
194
///
195
195
/// This will fail if the amount given is less than the value required by the given invoice.
196
196
///
197
197
/// This can be used to pay a so-called "zero-amount" invoice, i.e., an invoice that leaves the
198
198
/// amount paid to be determined by the user.
199
+ ///
200
+ /// If [`SendingParameters`] are provided they will override the node's default routing parameters
201
+ /// on a per-field basis. Each field in `SendingParameters` that is set replaces the corresponding
202
+ /// default value. Fields that are not set fall back to the node's configured defaults. If no
203
+ /// `SendingParameters` are provided, the method fully relies on these defaults.
199
204
pub fn send_using_amount (
200
205
& self , invoice : & Bolt11Invoice , amount_msat : u64 ,
206
+ sending_parameters : Option < SendingParameters > ,
201
207
) -> Result < PaymentId , Error > {
202
208
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
203
209
if rt_lock. is_none ( ) {
@@ -238,9 +244,43 @@ impl Bolt11Payment {
238
244
. with_bolt11_features ( features. clone ( ) )
239
245
. map_err ( |_| Error :: InvalidInvoice ) ?;
240
246
}
241
- let route_params =
247
+ let mut route_params =
242
248
RouteParameters :: from_payment_params_and_value ( payment_params, amount_msat) ;
243
249
250
+ if let Some ( user_set_params) = sending_parameters {
251
+ if let Some ( mut default_params) =
252
+ self . config . sending_parameters_config . as_ref ( ) . cloned ( )
253
+ {
254
+ default_params. max_total_routing_fee_msat = user_set_params
255
+ . max_total_routing_fee_msat
256
+ . or ( default_params. max_total_routing_fee_msat ) ;
257
+ default_params. max_total_cltv_expiry_delta = user_set_params
258
+ . max_total_cltv_expiry_delta
259
+ . or ( default_params. max_total_cltv_expiry_delta ) ;
260
+ default_params. max_path_count =
261
+ user_set_params. max_path_count . or ( default_params. max_path_count ) ;
262
+ default_params. max_channel_saturation_power_of_half = user_set_params
263
+ . max_channel_saturation_power_of_half
264
+ . or ( default_params. max_channel_saturation_power_of_half ) ;
265
+
266
+ route_params. max_total_routing_fee_msat = default_params. max_total_routing_fee_msat ;
267
+ route_params. payment_params . max_total_cltv_expiry_delta =
268
+ default_params. max_total_cltv_expiry_delta . unwrap_or_default ( ) ;
269
+ route_params. payment_params . max_path_count =
270
+ default_params. max_path_count . unwrap_or_default ( ) ;
271
+ route_params. payment_params . max_channel_saturation_power_of_half =
272
+ default_params. max_channel_saturation_power_of_half . unwrap_or_default ( ) ;
273
+ }
274
+ } else if let Some ( default_params) = & self . config . sending_parameters_config {
275
+ route_params. max_total_routing_fee_msat = default_params. max_total_routing_fee_msat ;
276
+ route_params. payment_params . max_total_cltv_expiry_delta =
277
+ default_params. max_total_cltv_expiry_delta . unwrap_or_default ( ) ;
278
+ route_params. payment_params . max_path_count =
279
+ default_params. max_path_count . unwrap_or_default ( ) ;
280
+ route_params. payment_params . max_channel_saturation_power_of_half =
281
+ default_params. max_channel_saturation_power_of_half . unwrap_or_default ( ) ;
282
+ }
283
+
244
284
let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
245
285
let recipient_fields = RecipientOnionFields :: secret_only ( * payment_secret) ;
246
286
0 commit comments