@@ -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,33 @@ 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
+ 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
+ . map ( |( ) | payment_hash)
465
+ . map_err ( |e| { self . remove_outbound_if_all_failed ( payment_id, & e) ; e } )
466
+ }
467
+
468
+ pub ( super ) fn send_spontaneous_payment_with_route < ES : Deref , NS : Deref , F > (
443
469
& self , route : & Route , payment_preimage : Option < PaymentPreimage > , payment_id : PaymentId ,
444
470
entropy_source : & ES , node_signer : & NS , best_block_height : u32 , send_payment_along_path : F
445
471
) -> Result < PaymentHash , PaymentSendFailure >
@@ -512,7 +538,7 @@ impl OutboundPayments {
512
538
513
539
fn pay_internal < R : Deref , NS : Deref , ES : Deref , F , L : Deref > (
514
540
& self , payment_id : PaymentId ,
515
- initial_send_info : Option < ( PaymentHash , & Option < PaymentSecret > , Retry ) > ,
541
+ initial_send_info : Option < ( PaymentHash , & Option < PaymentSecret > , Option < PaymentPreimage > , Retry ) > ,
516
542
route_params : RouteParameters , router : & R , first_hops : Vec < ChannelDetails > ,
517
543
inflight_htlcs : InFlightHtlcs , entropy_source : & ES , node_signer : & NS , best_block_height : u32 ,
518
544
logger : & L , send_payment_along_path : & F ,
@@ -540,8 +566,8 @@ impl OutboundPayments {
540
566
err : format ! ( "Failed to find a route for payment {}: {:?}" , log_bytes!( payment_id. 0 ) , e) , // TODO: add APIError::RouteNotFound
541
567
} ) ) ?;
542
568
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) ?;
569
+ let res = if let Some ( ( payment_hash, payment_secret, keysend_preimage , retry_strategy) ) = initial_send_info {
570
+ 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
571
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
572
} else {
547
573
self . retry_payment_with_route ( & route, payment_id, entropy_source, node_signer, best_block_height, send_payment_along_path)
@@ -597,21 +623,21 @@ impl OutboundPayments {
597
623
onion_session_privs. push ( entropy_source. get_secure_random_bytes ( ) ) ;
598
624
}
599
625
600
- let ( total_msat, payment_hash, payment_secret) = {
626
+ let ( total_msat, payment_hash, payment_secret, keysend_preimage ) = {
601
627
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
602
628
match outbounds. get_mut ( & payment_id) {
603
629
Some ( payment) => {
604
630
let res = match payment {
605
631
PendingOutboundPayment :: Retryable {
606
- total_msat, payment_hash, payment_secret, pending_amt_msat, ..
632
+ total_msat, payment_hash, keysend_preimage , payment_secret, pending_amt_msat, ..
607
633
} => {
608
634
let retry_amt_msat: u64 = route. paths . iter ( ) . map ( |path| path. last ( ) . unwrap ( ) . fee_msat ) . sum ( ) ;
609
635
if retry_amt_msat + * pending_amt_msat > * total_msat * ( 100 + RETRY_OVERFLOW_PERCENTAGE ) / 100 {
610
636
return Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError {
611
637
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
638
} ) )
613
639
}
614
- ( * total_msat, * payment_hash, * payment_secret)
640
+ ( * total_msat, * payment_hash, * payment_secret, * keysend_preimage )
615
641
} ,
616
642
PendingOutboundPayment :: Legacy { .. } => {
617
643
return Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError {
@@ -646,7 +672,7 @@ impl OutboundPayments {
646
672
} ) ) ,
647
673
}
648
674
} ;
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)
675
+ 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
676
}
651
677
652
678
pub ( super ) fn send_probe < ES : Deref , NS : Deref , F > (
0 commit comments