@@ -416,7 +416,7 @@ impl OutboundPayments {
416
416
F : Fn ( & Vec < RouteHop > , & Option < PaymentParameters > , & PaymentHash , & Option < PaymentSecret > , u64 ,
417
417
u32 , PaymentId , & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError > ,
418
418
{
419
- self . pay_internal ( payment_id, Some ( ( payment_hash, payment_secret, retry_strategy) ) ,
419
+ self . pay_internal ( payment_id, Some ( ( payment_hash, payment_secret, None , retry_strategy) ) ,
420
420
route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer,
421
421
best_block_height, logger, & send_payment_along_path)
422
422
. map_err ( |e| { self . remove_outbound_if_all_failed ( payment_id, & e) ; e } )
@@ -439,7 +439,38 @@ impl OutboundPayments {
439
439
. map_err ( |e| { self . remove_outbound_if_all_failed ( payment_id, & e) ; e } )
440
440
}
441
441
442
- pub ( super ) fn send_spontaneous_payment < ES : Deref , NS : Deref , F > (
442
+ pub ( super ) fn send_spontaneous_payment < R : Deref , ES : Deref , NS : Deref , F , L : Deref > (
443
+ & self , payment_preimage : Option < PaymentPreimage > , payment_id : PaymentId ,
444
+ retry_strategy : Retry , route_params : RouteParameters , router : & R ,
445
+ first_hops : Vec < ChannelDetails > , inflight_htlcs : InFlightHtlcs , entropy_source : & ES ,
446
+ node_signer : & NS , best_block_height : u32 , logger : & L , send_payment_along_path : F
447
+ ) -> Result < PaymentHash , PaymentSendFailure >
448
+ where
449
+ R :: Target : Router ,
450
+ ES :: Target : EntropySource ,
451
+ NS :: Target : NodeSigner ,
452
+ L :: Target : Logger ,
453
+ F : Fn ( & Vec < RouteHop > , & Option < PaymentParameters > , & PaymentHash , & Option < PaymentSecret > , u64 ,
454
+ u32 , PaymentId , & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError > ,
455
+ {
456
+ let preimage = match payment_preimage {
457
+ Some ( p) => p,
458
+ None => PaymentPreimage ( entropy_source. get_secure_random_bytes ( ) ) ,
459
+ } ;
460
+ let payment_hash = PaymentHash ( Sha256 :: hash ( & preimage. 0 ) . into_inner ( ) ) ;
461
+ match self . pay_internal ( payment_id, Some ( ( payment_hash, & None , Some ( preimage) , retry_strategy) ) ,
462
+ route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer,
463
+ best_block_height, logger, & send_payment_along_path)
464
+ {
465
+ Ok ( ( ) ) => Ok ( payment_hash) ,
466
+ Err ( e) => {
467
+ self . remove_outbound_if_all_failed ( payment_id, & e) ;
468
+ Err ( e)
469
+ }
470
+ }
471
+ }
472
+
473
+ pub ( super ) fn send_spontaneous_payment_with_route < ES : Deref , NS : Deref , F > (
443
474
& self , route : & Route , payment_preimage : Option < PaymentPreimage > , payment_id : PaymentId ,
444
475
entropy_source : & ES , node_signer : & NS , best_block_height : u32 , send_payment_along_path : F
445
476
) -> Result < PaymentHash , PaymentSendFailure >
@@ -512,7 +543,7 @@ impl OutboundPayments {
512
543
513
544
fn pay_internal < R : Deref , NS : Deref , ES : Deref , F , L : Deref > (
514
545
& self , payment_id : PaymentId ,
515
- initial_send_info : Option < ( PaymentHash , & Option < PaymentSecret > , Retry ) > ,
546
+ initial_send_info : Option < ( PaymentHash , & Option < PaymentSecret > , Option < PaymentPreimage > , Retry ) > ,
516
547
route_params : RouteParameters , router : & R , first_hops : Vec < ChannelDetails > ,
517
548
inflight_htlcs : InFlightHtlcs , entropy_source : & ES , node_signer : & NS , best_block_height : u32 ,
518
549
logger : & L , send_payment_along_path : & F ,
@@ -540,8 +571,8 @@ impl OutboundPayments {
540
571
err : format ! ( "Failed to find a route for payment {}: {:?}" , log_bytes!( payment_id. 0 ) , e) , // TODO: add APIError::RouteNotFound
541
572
} ) ) ?;
542
573
543
- let res = if let Some ( ( payment_hash, payment_secret, retry_strategy) ) = initial_send_info {
544
- let onion_session_privs = self . add_new_pending_payment ( payment_hash, * payment_secret, payment_id, None , & route, Some ( retry_strategy) , Some ( route_params. payment_params . clone ( ) ) , entropy_source, best_block_height) ?;
574
+ let res = if let Some ( ( payment_hash, payment_secret, keysend_preimage , retry_strategy) ) = initial_send_info {
575
+ let onion_session_privs = self . add_new_pending_payment ( payment_hash, * payment_secret, payment_id, keysend_preimage , & route, Some ( retry_strategy) , Some ( route_params. payment_params . clone ( ) ) , entropy_source, best_block_height) ?;
545
576
self . pay_route_internal ( & route, payment_hash, payment_secret, None , payment_id, None , onion_session_privs, node_signer, best_block_height, send_payment_along_path)
546
577
} else {
547
578
self . retry_payment_with_route ( & route, payment_id, entropy_source, node_signer, best_block_height, send_payment_along_path)
@@ -597,21 +628,21 @@ impl OutboundPayments {
597
628
onion_session_privs. push ( entropy_source. get_secure_random_bytes ( ) ) ;
598
629
}
599
630
600
- let ( total_msat, payment_hash, payment_secret) = {
631
+ let ( total_msat, payment_hash, payment_secret, keysend_preimage ) = {
601
632
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
602
633
match outbounds. get_mut ( & payment_id) {
603
634
Some ( payment) => {
604
635
let res = match payment {
605
636
PendingOutboundPayment :: Retryable {
606
- total_msat, payment_hash, payment_secret, pending_amt_msat, ..
637
+ total_msat, payment_hash, keysend_preimage , payment_secret, pending_amt_msat, ..
607
638
} => {
608
639
let retry_amt_msat: u64 = route. paths . iter ( ) . map ( |path| path. last ( ) . unwrap ( ) . fee_msat ) . sum ( ) ;
609
640
if retry_amt_msat + * pending_amt_msat > * total_msat * ( 100 + RETRY_OVERFLOW_PERCENTAGE ) / 100 {
610
641
return Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError {
611
642
err : format ! ( "retry_amt_msat of {} will put pending_amt_msat (currently: {}) more than 10% over total_payment_amt_msat of {}" , retry_amt_msat, pending_amt_msat, total_msat) . to_string ( )
612
643
} ) )
613
644
}
614
- ( * total_msat, * payment_hash, * payment_secret)
645
+ ( * total_msat, * payment_hash, * payment_secret, * keysend_preimage )
615
646
} ,
616
647
PendingOutboundPayment :: Legacy { .. } => {
617
648
return Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError {
@@ -646,7 +677,7 @@ impl OutboundPayments {
646
677
} ) ) ,
647
678
}
648
679
} ;
649
- self . pay_route_internal ( route, payment_hash, & payment_secret, None , payment_id, Some ( total_msat) , onion_session_privs, node_signer, best_block_height, & send_payment_along_path)
680
+ self . pay_route_internal ( route, payment_hash, & payment_secret, keysend_preimage , payment_id, Some ( total_msat) , onion_session_privs, node_signer, best_block_height, & send_payment_along_path)
650
681
}
651
682
652
683
pub ( super ) fn send_probe < ES : Deref , NS : Deref , F > (
0 commit comments