@@ -18,7 +18,6 @@ use crate::payment::store::{
1818 LSPFeeLimits , PaymentDetails , PaymentDetailsUpdate , PaymentDirection , PaymentKind ,
1919 PaymentStatus , PaymentStore , PaymentStoreUpdateResult ,
2020} ;
21- use crate :: payment:: SendingParameters ;
2221use crate :: peer_store:: { PeerInfo , PeerStore } ;
2322use crate :: types:: ChannelManager ;
2423
@@ -151,7 +150,8 @@ impl Bolt11Payment {
151150 }
152151 }
153152
154- let route_parameters = route_parameters. or ( self . config . route_parameters ) . unwrap_or_default ( ) ;
153+ let route_parameters =
154+ route_parameters. or ( self . config . route_parameters ) . unwrap_or_default ( ) ;
155155 let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
156156 let payment_secret = Some ( * invoice. payment_secret ( ) ) ;
157157
@@ -186,7 +186,9 @@ impl Bolt11Payment {
186186 Ok ( payment_id)
187187 } ,
188188 Err ( Bolt11PaymentError :: InvalidAmount ) => {
189- log_error ! ( self . logger, "Failed to send payment due to the given invoice being \" zero-amount\" . Please use send_using_amount instead." ) ;
189+ log_error ! ( self . logger,
190+ "Failed to send payment due to the given invoice being \" zero-amount\" . Please use send_using_amount instead."
191+ ) ;
190192 return Err ( Error :: InvalidInvoice ) ;
191193 } ,
192194 Err ( Bolt11PaymentError :: SendingFailed ( e) ) => {
@@ -223,11 +225,11 @@ impl Bolt11Payment {
223225 /// This can be used to pay a so-called "zero-amount" invoice, i.e., an invoice that leaves the
224226 /// amount paid to be determined by the user.
225227 ///
226- /// If `sending_parameters ` are provided they will override the default as well as the
227- /// node-wide parameters configured via [`Config::sending_parameters `] on a per-field basis.
228+ /// If `route_parameters ` are provided they will override the default as well as the
229+ /// node-wide parameters configured via [`Config::route_parameters `] on a per-field basis.
228230 pub fn send_using_amount (
229231 & self , invoice : & Bolt11Invoice , amount_msat : u64 ,
230- sending_parameters : Option < SendingParameters > ,
232+ route_parameters : Option < RouteParametersConfig > ,
231233 ) -> Result < PaymentId , Error > {
232234 let invoice = maybe_convert_invoice ( invoice) ;
233235 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
@@ -255,46 +257,16 @@ impl Bolt11Payment {
255257 }
256258 }
257259
258- let payment_secret = invoice. payment_secret ( ) ;
259- let expiry_time = invoice. duration_since_epoch ( ) . saturating_add ( invoice. expiry_time ( ) ) ;
260- let mut payment_params = PaymentParameters :: from_node_id (
261- invoice. recover_payee_pub_key ( ) ,
262- invoice. min_final_cltv_expiry_delta ( ) as u32 ,
263- )
264- . with_expiry_time ( expiry_time. as_secs ( ) )
265- . with_route_hints ( invoice. route_hints ( ) )
266- . map_err ( |_| Error :: InvalidInvoice ) ?;
267- if let Some ( features) = invoice. features ( ) {
268- payment_params = payment_params
269- . with_bolt11_features ( features. clone ( ) )
270- . map_err ( |_| Error :: InvalidInvoice ) ?;
271- }
272- let mut route_params =
273- RouteParameters :: from_payment_params_and_value ( payment_params, amount_msat) ;
274-
275- let override_params =
276- sending_parameters. as_ref ( ) . or ( self . config . sending_parameters . as_ref ( ) ) ;
277- if let Some ( override_params) = override_params {
278- override_params
279- . max_total_routing_fee_msat
280- . map ( |f| route_params. max_total_routing_fee_msat = f. into ( ) ) ;
281- override_params
282- . max_total_cltv_expiry_delta
283- . map ( |d| route_params. payment_params . max_total_cltv_expiry_delta = d) ;
284- override_params. max_path_count . map ( |p| route_params. payment_params . max_path_count = p) ;
285- override_params
286- . max_channel_saturation_power_of_half
287- . map ( |s| route_params. payment_params . max_channel_saturation_power_of_half = s) ;
288- } ;
289-
260+ let route_parameters =
261+ route_parameters. or ( self . config . route_parameters ) . unwrap_or_default ( ) ;
290262 let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
291- let recipient_fields = RecipientOnionFields :: secret_only ( * payment_secret) ;
263+ let payment_secret = Some ( * invoice . payment_secret ( ) ) ;
292264
293- match self . channel_manager . send_payment (
294- payment_hash,
295- recipient_fields,
265+ match self . channel_manager . pay_for_bolt11_invoice (
266+ invoice,
296267 payment_id,
297- route_params,
268+ Some ( amount_msat) ,
269+ route_parameters,
298270 retry_strategy,
299271 ) {
300272 Ok ( ( ) ) => {
@@ -309,7 +281,7 @@ impl Bolt11Payment {
309281 let kind = PaymentKind :: Bolt11 {
310282 hash : payment_hash,
311283 preimage : None ,
312- secret : Some ( * payment_secret) ,
284+ secret : payment_secret,
313285 } ;
314286
315287 let payment = PaymentDetails :: new (
@@ -324,16 +296,22 @@ impl Bolt11Payment {
324296
325297 Ok ( payment_id)
326298 } ,
327- Err ( e) => {
299+ Err ( Bolt11PaymentError :: InvalidAmount ) => {
300+ log_error ! (
301+ self . logger,
302+ "Failed to send payment due to amount given being insufficient."
303+ ) ;
304+ return Err ( Error :: InvalidInvoice ) ;
305+ } ,
306+ Err ( Bolt11PaymentError :: SendingFailed ( e) ) => {
328307 log_error ! ( self . logger, "Failed to send payment: {:?}" , e) ;
329-
330308 match e {
331309 RetryableSendFailure :: DuplicatePayment => Err ( Error :: DuplicatePayment ) ,
332310 _ => {
333311 let kind = PaymentKind :: Bolt11 {
334312 hash : payment_hash,
335313 preimage : None ,
336- secret : Some ( * payment_secret) ,
314+ secret : payment_secret,
337315 } ;
338316 let payment = PaymentDetails :: new (
339317 payment_id,
@@ -343,8 +321,8 @@ impl Bolt11Payment {
343321 PaymentDirection :: Outbound ,
344322 PaymentStatus :: Failed ,
345323 ) ;
346- self . payment_store . insert ( payment) ?;
347324
325+ self . payment_store . insert ( payment) ?;
348326 Err ( Error :: PaymentSendingFailed )
349327 } ,
350328 }
0 commit comments