@@ -34,12 +34,13 @@ use core::time::Duration;
34
34
///
35
35
/// If you wish to use a different payment idempotency token, see [`pay_invoice_with_id`].
36
36
pub fn pay_invoice < C : Deref > (
37
- invoice : & Bolt11Invoice , retry_strategy : Retry , channelmanager : C
37
+ invoice : & Bolt11Invoice , retry_strategy : Retry , max_total_routing_fee_msat : Option < u64 > ,
38
+ channelmanager : C
38
39
) -> Result < PaymentId , PaymentError >
39
40
where C :: Target : AChannelManager ,
40
41
{
41
42
let payment_id = PaymentId ( invoice. payment_hash ( ) . into_inner ( ) ) ;
42
- pay_invoice_with_id ( invoice, payment_id, retry_strategy, channelmanager. get_cm ( ) )
43
+ pay_invoice_with_id ( invoice, payment_id, retry_strategy, max_total_routing_fee_msat , channelmanager. get_cm ( ) )
43
44
. map ( |( ) | payment_id)
44
45
}
45
46
@@ -54,12 +55,13 @@ where C::Target: AChannelManager,
54
55
///
55
56
/// See [`pay_invoice`] for a variant which uses the [`PaymentHash`] for the idempotency token.
56
57
pub fn pay_invoice_with_id < C : Deref > (
57
- invoice : & Bolt11Invoice , payment_id : PaymentId , retry_strategy : Retry , channelmanager : C
58
+ invoice : & Bolt11Invoice , payment_id : PaymentId , retry_strategy : Retry ,
59
+ max_total_routing_fee_msat : Option < u64 > , channelmanager : C
58
60
) -> Result < ( ) , PaymentError >
59
61
where C :: Target : AChannelManager ,
60
62
{
61
63
let amt_msat = invoice. amount_milli_satoshis ( ) . ok_or ( PaymentError :: Invoice ( "amount missing" ) ) ?;
62
- pay_invoice_using_amount ( invoice, amt_msat, payment_id, retry_strategy, channelmanager. get_cm ( ) )
64
+ pay_invoice_using_amount ( invoice, amt_msat, payment_id, retry_strategy, max_total_routing_fee_msat , channelmanager. get_cm ( ) )
63
65
}
64
66
65
67
/// Pays the given zero-value [`Bolt11Invoice`] using the given amount, retrying if needed based on
@@ -72,13 +74,13 @@ where C::Target: AChannelManager,
72
74
/// If you wish to use a different payment idempotency token, see
73
75
/// [`pay_zero_value_invoice_with_id`].
74
76
pub fn pay_zero_value_invoice < C : Deref > (
75
- invoice : & Bolt11Invoice , amount_msats : u64 , retry_strategy : Retry , channelmanager : C
77
+ invoice : & Bolt11Invoice , amount_msats : u64 , retry_strategy : Retry ,
78
+ max_total_routing_fee_msat : Option < u64 > , channelmanager : C
76
79
) -> Result < PaymentId , PaymentError >
77
80
where C :: Target : AChannelManager ,
78
81
{
79
82
let payment_id = PaymentId ( invoice. payment_hash ( ) . into_inner ( ) ) ;
80
- pay_zero_value_invoice_with_id ( invoice, amount_msats, payment_id, retry_strategy,
81
- channelmanager)
83
+ pay_zero_value_invoice_with_id ( invoice, amount_msats, payment_id, retry_strategy, max_total_routing_fee_msat, channelmanager)
82
84
. map ( |( ) | payment_id)
83
85
}
84
86
@@ -95,21 +97,20 @@ where C::Target: AChannelManager,
95
97
/// idempotency token.
96
98
pub fn pay_zero_value_invoice_with_id < C : Deref > (
97
99
invoice : & Bolt11Invoice , amount_msats : u64 , payment_id : PaymentId , retry_strategy : Retry ,
98
- channelmanager : C
100
+ max_total_routing_fee_msat : Option < u64 > , channelmanager : C
99
101
) -> Result < ( ) , PaymentError >
100
102
where C :: Target : AChannelManager ,
101
103
{
102
104
if invoice. amount_milli_satoshis ( ) . is_some ( ) {
103
105
Err ( PaymentError :: Invoice ( "amount unexpected" ) )
104
106
} else {
105
- pay_invoice_using_amount ( invoice, amount_msats, payment_id, retry_strategy,
106
- channelmanager. get_cm ( ) )
107
+ pay_invoice_using_amount ( invoice, amount_msats, payment_id, retry_strategy, max_total_routing_fee_msat, channelmanager. get_cm ( ) )
107
108
}
108
109
}
109
110
110
111
fn pay_invoice_using_amount < P : Deref > (
111
112
invoice : & Bolt11Invoice , amount_msats : u64 , payment_id : PaymentId , retry_strategy : Retry ,
112
- payer : P
113
+ max_total_routing_fee_msat : Option < u64 > , payer : P
113
114
) -> Result < ( ) , PaymentError > where P :: Target : Payer {
114
115
let payment_hash = PaymentHash ( ( * invoice. payment_hash ( ) ) . into_inner ( ) ) ;
115
116
let mut recipient_onion = RecipientOnionFields :: secret_only ( * invoice. payment_secret ( ) ) ;
@@ -121,7 +122,11 @@ fn pay_invoice_using_amount<P: Deref>(
121
122
if let Some ( features) = invoice. features ( ) {
122
123
payment_params = payment_params. with_bolt11_features ( features. clone ( ) ) . unwrap ( ) ;
123
124
}
124
- let route_params = RouteParameters :: from_payment_params_and_value ( payment_params, amount_msats) ;
125
+ let route_params = RouteParameters {
126
+ payment_params,
127
+ final_value_msat : amount_msats,
128
+ max_total_routing_fee_msat,
129
+ } ;
125
130
126
131
payer. send_payment ( payment_hash, recipient_onion, payment_id, route_params, retry_strategy)
127
132
}
@@ -357,7 +362,7 @@ mod tests {
357
362
let final_value_msat = invoice. amount_milli_satoshis ( ) . unwrap ( ) ;
358
363
359
364
let payer = TestPayer :: new ( ) . expect_send ( Amount ( final_value_msat) ) ;
360
- pay_invoice_using_amount ( & invoice, final_value_msat, payment_id, Retry :: Attempts ( 0 ) , & payer) . unwrap ( ) ;
365
+ pay_invoice_using_amount ( & invoice, final_value_msat, payment_id, Retry :: Attempts ( 0 ) , None , & payer) . unwrap ( ) ;
361
366
}
362
367
363
368
#[ test]
@@ -368,7 +373,7 @@ mod tests {
368
373
let amt_msat = 10_000 ;
369
374
370
375
let payer = TestPayer :: new ( ) . expect_send ( Amount ( amt_msat) ) ;
371
- pay_invoice_using_amount ( & invoice, amt_msat, payment_id, Retry :: Attempts ( 0 ) , & payer) . unwrap ( ) ;
376
+ pay_invoice_using_amount ( & invoice, amt_msat, payment_id, Retry :: Attempts ( 0 ) , None , & payer) . unwrap ( ) ;
372
377
}
373
378
374
379
#[ test]
@@ -382,7 +387,7 @@ mod tests {
382
387
let invoice = invoice ( payment_preimage) ;
383
388
let amt_msat = 10_000 ;
384
389
385
- match pay_zero_value_invoice ( & invoice, amt_msat, Retry :: Attempts ( 0 ) , nodes[ 0 ] . node ) {
390
+ match pay_zero_value_invoice ( & invoice, amt_msat, Retry :: Attempts ( 0 ) , None , nodes[ 0 ] . node ) {
386
391
Err ( PaymentError :: Invoice ( "amount unexpected" ) ) => { } ,
387
392
_ => panic ! ( )
388
393
}
@@ -418,7 +423,7 @@ mod tests {
418
423
} )
419
424
. unwrap ( ) ;
420
425
421
- pay_invoice ( & invoice, Retry :: Attempts ( 0 ) , nodes[ 0 ] . node ) . unwrap ( ) ;
426
+ pay_invoice ( & invoice, Retry :: Attempts ( 0 ) , None , nodes[ 0 ] . node ) . unwrap ( ) ;
422
427
check_added_monitors ( & nodes[ 0 ] , 1 ) ;
423
428
let send_event = SendEvent :: from_node ( & nodes[ 0 ] ) ;
424
429
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & send_event. msgs [ 0 ] ) ;
0 commit comments