@@ -71,10 +71,8 @@ impl Bolt11Payment {
71
71
72
72
/// Send a payment given an invoice.
73
73
///
74
- /// If [`SendingParameters`] are provided they will override the node's default routing parameters
75
- /// on a per-field basis. Each field in `SendingParameters` that is set replaces the corresponding
76
- /// default value. Fields that are not set fall back to the node's configured defaults. If no
77
- /// `SendingParameters` are provided, the method fully relies on these defaults.
74
+ /// If `sending_parameters` are provided they will override the default as well as the
75
+ /// node-wide parameters configured via [`Config::sending_parameters`] on a per-field basis.
78
76
pub fn send (
79
77
& self , invoice : & Bolt11Invoice , sending_parameters : Option < SendingParameters > ,
80
78
) -> Result < PaymentId , Error > {
@@ -98,39 +96,20 @@ impl Bolt11Payment {
98
96
}
99
97
}
100
98
101
- if let Some ( user_set_params) = sending_parameters {
102
- if let Some ( mut default_params) =
103
- self . config . sending_parameters_config . as_ref ( ) . cloned ( )
104
- {
105
- default_params. max_total_routing_fee_msat = user_set_params
106
- . max_total_routing_fee_msat
107
- . or ( default_params. max_total_routing_fee_msat ) ;
108
- default_params. max_total_cltv_expiry_delta = user_set_params
109
- . max_total_cltv_expiry_delta
110
- . or ( default_params. max_total_cltv_expiry_delta ) ;
111
- default_params. max_path_count =
112
- user_set_params. max_path_count . or ( default_params. max_path_count ) ;
113
- default_params. max_channel_saturation_power_of_half = user_set_params
114
- . max_channel_saturation_power_of_half
115
- . or ( default_params. max_channel_saturation_power_of_half ) ;
116
-
117
- route_params. max_total_routing_fee_msat = default_params. max_total_routing_fee_msat ;
118
- route_params. payment_params . max_total_cltv_expiry_delta =
119
- default_params. max_total_cltv_expiry_delta . unwrap_or_default ( ) ;
120
- route_params. payment_params . max_path_count =
121
- default_params. max_path_count . unwrap_or_default ( ) ;
122
- route_params. payment_params . max_channel_saturation_power_of_half =
123
- default_params. max_channel_saturation_power_of_half . unwrap_or_default ( ) ;
124
- }
125
- } else if let Some ( default_params) = & self . config . sending_parameters_config {
126
- route_params. max_total_routing_fee_msat = default_params. max_total_routing_fee_msat ;
127
- route_params. payment_params . max_total_cltv_expiry_delta =
128
- default_params. max_total_cltv_expiry_delta . unwrap_or_default ( ) ;
129
- route_params. payment_params . max_path_count =
130
- default_params. max_path_count . unwrap_or_default ( ) ;
131
- route_params. payment_params . max_channel_saturation_power_of_half =
132
- default_params. max_channel_saturation_power_of_half . unwrap_or_default ( ) ;
133
- }
99
+ let override_params =
100
+ sending_parameters. as_ref ( ) . or ( self . config . sending_parameters . as_ref ( ) ) ;
101
+ if let Some ( override_params) = override_params {
102
+ override_params
103
+ . max_total_routing_fee_msat
104
+ . map ( |f| route_params. max_total_routing_fee_msat = f. into ( ) ) ;
105
+ override_params
106
+ . max_total_cltv_expiry_delta
107
+ . map ( |d| route_params. payment_params . max_total_cltv_expiry_delta = d) ;
108
+ override_params. max_path_count . map ( |p| route_params. payment_params . max_path_count = p) ;
109
+ override_params
110
+ . max_channel_saturation_power_of_half
111
+ . map ( |s| route_params. payment_params . max_channel_saturation_power_of_half = s) ;
112
+ } ;
134
113
135
114
let payment_secret = Some ( * invoice. payment_secret ( ) ) ;
136
115
let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
@@ -197,10 +176,8 @@ impl Bolt11Payment {
197
176
/// This can be used to pay a so-called "zero-amount" invoice, i.e., an invoice that leaves the
198
177
/// amount paid to be determined by the user.
199
178
///
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.
179
+ /// If `sending_parameters` are provided they will override the default as well as the
180
+ /// node-wide parameters configured via [`Config::sending_parameters`] on a per-field basis.
204
181
pub fn send_using_amount (
205
182
& self , invoice : & Bolt11Invoice , amount_msat : u64 ,
206
183
sending_parameters : Option < SendingParameters > ,
@@ -247,39 +224,20 @@ impl Bolt11Payment {
247
224
let mut route_params =
248
225
RouteParameters :: from_payment_params_and_value ( payment_params, amount_msat) ;
249
226
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
- }
227
+ let override_params =
228
+ sending_parameters. as_ref ( ) . or ( self . config . sending_parameters . as_ref ( ) ) ;
229
+ if let Some ( override_params) = override_params {
230
+ override_params
231
+ . max_total_routing_fee_msat
232
+ . map ( |f| route_params. max_total_routing_fee_msat = f. into ( ) ) ;
233
+ override_params
234
+ . max_total_cltv_expiry_delta
235
+ . map ( |d| route_params. payment_params . max_total_cltv_expiry_delta = d) ;
236
+ override_params. max_path_count . map ( |p| route_params. payment_params . max_path_count = p) ;
237
+ override_params
238
+ . max_channel_saturation_power_of_half
239
+ . map ( |s| route_params. payment_params . max_channel_saturation_power_of_half = s) ;
240
+ } ;
283
241
284
242
let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
285
243
let recipient_fields = RecipientOnionFields :: secret_only ( * payment_secret) ;
0 commit comments