@@ -22,11 +22,11 @@ use crate::payment::SendingParameters;
2222use crate :: peer_store:: { PeerInfo , PeerStore } ;
2323use crate :: types:: ChannelManager ;
2424
25- use lightning:: ln:: bolt11_payment;
2625use lightning:: ln:: channelmanager:: {
27- Bolt11InvoiceParameters , PaymentId , RecipientOnionFields , Retry , RetryableSendFailure ,
26+ Bolt11InvoiceParameters , Bolt11PaymentError , PaymentId , RecipientOnionFields , Retry ,
27+ RetryableSendFailure ,
2828} ;
29- use lightning:: routing:: router:: { PaymentParameters , RouteParameters } ;
29+ use lightning:: routing:: router:: { PaymentParameters , RouteParameters , RouteParametersConfig } ;
3030
3131use lightning_types:: payment:: { PaymentHash , PaymentPreimage } ;
3232
@@ -119,22 +119,17 @@ impl Bolt11Payment {
119119
120120 /// Send a payment given an invoice.
121121 ///
122- /// If `sending_parameters ` are provided they will override the default as well as the
123- /// node-wide parameters configured via [`Config::sending_parameters `] on a per-field basis.
122+ /// If `route_parameters ` are provided they will override the default as well as the
123+ /// node-wide parameters configured via [`Config::route_parameters `] on a per-field basis.
124124 pub fn send (
125- & self , invoice : & Bolt11Invoice , sending_parameters : Option < SendingParameters > ,
125+ & self , invoice : & Bolt11Invoice , route_parameters : Option < RouteParametersConfig > ,
126126 ) -> Result < PaymentId , Error > {
127127 let invoice = maybe_convert_invoice ( invoice) ;
128128 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
129129 if rt_lock. is_none ( ) {
130130 return Err ( Error :: NotRunning ) ;
131131 }
132132
133- let ( payment_hash, recipient_onion, mut route_params) = bolt11_payment:: payment_parameters_from_invoice ( & invoice) . map_err ( |_| {
134- log_error ! ( self . logger, "Failed to send payment due to the given invoice being \" zero-amount\" . Please use send_using_amount instead." ) ;
135- Error :: InvalidInvoice
136- } ) ?;
137-
138133 let payment_id = PaymentId ( invoice. payment_hash ( ) . to_byte_array ( ) ) ;
139134 if let Some ( payment) = self . payment_store . get ( & payment_id) {
140135 if payment. status == PaymentStatus :: Pending
@@ -145,29 +140,26 @@ impl Bolt11Payment {
145140 }
146141 }
147142
148- let override_params =
149- sending_parameters. as_ref ( ) . or ( self . config . sending_parameters . as_ref ( ) ) ;
150- if let Some ( override_params) = override_params {
151- override_params
152- . max_total_routing_fee_msat
153- . map ( |f| route_params. max_total_routing_fee_msat = f. into ( ) ) ;
154- override_params
155- . max_total_cltv_expiry_delta
156- . map ( |d| route_params. payment_params . max_total_cltv_expiry_delta = d) ;
157- override_params. max_path_count . map ( |p| route_params. payment_params . max_path_count = p) ;
158- override_params
159- . max_channel_saturation_power_of_half
160- . map ( |s| route_params. payment_params . max_channel_saturation_power_of_half = s) ;
161- } ;
143+ let payment_hash = PaymentHash ( invoice. payment_hash ( ) . to_byte_array ( ) ) ;
144+ let payment_id = PaymentId ( invoice. payment_hash ( ) . to_byte_array ( ) ) ;
145+ if let Some ( payment) = self . payment_store . get ( & payment_id) {
146+ if payment. status == PaymentStatus :: Pending
147+ || payment. status == PaymentStatus :: Succeeded
148+ {
149+ log_error ! ( self . logger, "Payment error: an invoice must not be paid twice." ) ;
150+ return Err ( Error :: DuplicatePayment ) ;
151+ }
152+ }
162153
163- let payment_secret = Some ( * invoice . payment_secret ( ) ) ;
154+ let route_parameters = route_parameters . or ( self . config . route_parameters ) . unwrap_or_default ( ) ;
164155 let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
156+ let payment_secret = Some ( * invoice. payment_secret ( ) ) ;
165157
166- match self . channel_manager . send_payment (
167- payment_hash,
168- recipient_onion,
158+ match self . channel_manager . pay_for_bolt11_invoice (
159+ invoice,
169160 payment_id,
170- route_params,
161+ None ,
162+ route_parameters,
171163 retry_strategy,
172164 ) {
173165 Ok ( ( ) ) => {
@@ -193,7 +185,11 @@ impl Bolt11Payment {
193185
194186 Ok ( payment_id)
195187 } ,
196- Err ( e) => {
188+ 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." ) ;
190+ return Err ( Error :: InvalidInvoice ) ;
191+ } ,
192+ Err ( Bolt11PaymentError :: SendingFailed ( e) ) => {
197193 log_error ! ( self . logger, "Failed to send payment: {:?}" , e) ;
198194 match e {
199195 RetryableSendFailure :: DuplicatePayment => Err ( Error :: DuplicatePayment ) ,
0 commit comments