@@ -23,7 +23,7 @@ use lightning::util::ser::{Readable, Writeable};
2323use lightning_types:: string:: UntrustedString ;
2424use rand:: RngCore ;
2525
26- use crate :: config:: { AsyncPaymentsRole , LDK_PAYMENT_RETRY_TIMEOUT } ;
26+ use crate :: config:: { AsyncPaymentsRole , Config , LDK_PAYMENT_RETRY_TIMEOUT } ;
2727use crate :: error:: Error ;
2828use crate :: ffi:: { maybe_deref, maybe_wrap} ;
2929use crate :: logger:: { log_error, log_info, LdkLogger , Logger } ;
@@ -54,6 +54,7 @@ type Refund = Arc<crate::ffi::Refund>;
5454pub struct Bolt12Payment {
5555 channel_manager : Arc < ChannelManager > ,
5656 payment_store : Arc < PaymentStore > ,
57+ config : Arc < Config > ,
5758 is_running : Arc < RwLock < bool > > ,
5859 logger : Arc < Logger > ,
5960 async_payments_role : Option < AsyncPaymentsRole > ,
@@ -62,10 +63,10 @@ pub struct Bolt12Payment {
6263impl Bolt12Payment {
6364 pub ( crate ) fn new (
6465 channel_manager : Arc < ChannelManager > , payment_store : Arc < PaymentStore > ,
65- is_running : Arc < RwLock < bool > > , logger : Arc < Logger > ,
66+ config : Arc < Config > , is_running : Arc < RwLock < bool > > , logger : Arc < Logger > ,
6667 async_payments_role : Option < AsyncPaymentsRole > ,
6768 ) -> Self {
68- Self { channel_manager, payment_store, is_running, logger, async_payments_role }
69+ Self { channel_manager, payment_store, config , is_running, logger, async_payments_role }
6970 }
7071
7172 /// Send a payment given an offer.
@@ -74,8 +75,12 @@ impl Bolt12Payment {
7475 /// response.
7576 ///
7677 /// If `quantity` is `Some` it represents the number of items requested.
78+ ///
79+ /// If `route_parameters` are provided they will override the default as well as the
80+ /// node-wide parameters configured via [`Config::route_parameters`] on a per-field basis.
7781 pub fn send (
7882 & self , offer : & Offer , quantity : Option < u64 > , payer_note : Option < String > ,
83+ route_parameters : Option < RouteParametersConfig > ,
7984 ) -> Result < PaymentId , Error > {
8085 if !* self . is_running . read ( ) . unwrap ( ) {
8186 return Err ( Error :: NotRunning ) ;
@@ -87,7 +92,8 @@ impl Bolt12Payment {
8792 rand:: rng ( ) . fill_bytes ( & mut random_bytes) ;
8893 let payment_id = PaymentId ( random_bytes) ;
8994 let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
90- let route_params_config = RouteParametersConfig :: default ( ) ;
95+ let route_parameters =
96+ route_parameters. or ( self . config . route_parameters ) . unwrap_or_default ( ) ;
9197
9298 let offer_amount_msat = match offer. amount ( ) {
9399 Some ( Amount :: Bitcoin { amount_msats } ) => amount_msats,
@@ -104,7 +110,7 @@ impl Bolt12Payment {
104110 let params = OptionalOfferPaymentParams {
105111 payer_note : payer_note. clone ( ) ,
106112 retry_strategy,
107- route_params_config,
113+ route_params_config : route_parameters ,
108114 } ;
109115 let res = if let Some ( quantity) = quantity {
110116 self . channel_manager
@@ -181,8 +187,12 @@ impl Bolt12Payment {
181187 ///
182188 /// If `payer_note` is `Some` it will be seen by the recipient and reflected back in the invoice
183189 /// response.
190+ ///
191+ /// If `route_parameters` are provided they will override the default as well as the
192+ /// node-wide parameters configured via [`Config::route_parameters`] on a per-field basis.
184193 pub fn send_using_amount (
185194 & self , offer : & Offer , amount_msat : u64 , quantity : Option < u64 > , payer_note : Option < String > ,
195+ route_parameters : Option < RouteParametersConfig > ,
186196 ) -> Result < PaymentId , Error > {
187197 if !* self . is_running . read ( ) . unwrap ( ) {
188198 return Err ( Error :: NotRunning ) ;
@@ -194,7 +204,8 @@ impl Bolt12Payment {
194204 rand:: rng ( ) . fill_bytes ( & mut random_bytes) ;
195205 let payment_id = PaymentId ( random_bytes) ;
196206 let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
197- let route_params_config = RouteParametersConfig :: default ( ) ;
207+ let route_parameters =
208+ route_parameters. or ( self . config . route_parameters ) . unwrap_or_default ( ) ;
198209
199210 let offer_amount_msat = match offer. amount ( ) {
200211 Some ( Amount :: Bitcoin { amount_msats } ) => amount_msats,
@@ -215,7 +226,7 @@ impl Bolt12Payment {
215226 let params = OptionalOfferPaymentParams {
216227 payer_note : payer_note. clone ( ) ,
217228 retry_strategy,
218- route_params_config,
229+ route_params_config : route_parameters ,
219230 } ;
220231 let res = if let Some ( quantity) = quantity {
221232 self . channel_manager . pay_for_offer_with_quantity (
@@ -402,10 +413,13 @@ impl Bolt12Payment {
402413
403414 /// Returns a [`Refund`] object that can be used to offer a refund payment of the amount given.
404415 ///
416+ /// If `route_parameters` are provided they will override the default as well as the
417+ /// node-wide parameters configured via [`Config::route_parameters`] on a per-field basis.
418+ ///
405419 /// [`Refund`]: lightning::offers::refund::Refund
406420 pub fn initiate_refund (
407421 & self , amount_msat : u64 , expiry_secs : u32 , quantity : Option < u64 > ,
408- payer_note : Option < String > ,
422+ payer_note : Option < String > , route_parameters : Option < RouteParametersConfig > ,
409423 ) -> Result < Refund , Error > {
410424 let mut random_bytes = [ 0u8 ; 32 ] ;
411425 rand:: rng ( ) . fill_bytes ( & mut random_bytes) ;
@@ -415,7 +429,8 @@ impl Bolt12Payment {
415429 . duration_since ( UNIX_EPOCH )
416430 . unwrap ( ) ;
417431 let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
418- let route_params_config = RouteParametersConfig :: default ( ) ;
432+ let route_parameters =
433+ route_parameters. or ( self . config . route_parameters ) . unwrap_or_default ( ) ;
419434
420435 let mut refund_builder = self
421436 . channel_manager
@@ -424,7 +439,7 @@ impl Bolt12Payment {
424439 absolute_expiry,
425440 payment_id,
426441 retry_strategy,
427- route_params_config ,
442+ route_parameters ,
428443 )
429444 . map_err ( |e| {
430445 log_error ! ( self . logger, "Failed to create refund builder: {:?}" , e) ;
0 commit comments