@@ -2450,7 +2450,60 @@ fn fail_payment_along_path<'a, 'b, 'c>(expected_path: &[&Node<'a, 'b, 'c>]) {
24502450 }
24512451}
24522452
2453- pub fn do_pass_along_path < ' a , ' b , ' c > ( origin_node : & Node < ' a , ' b , ' c > , expected_path : & [ & Node < ' a , ' b , ' c > ] , recv_value : u64 , our_payment_hash : PaymentHash , our_payment_secret : Option < PaymentSecret > , ev : MessageSendEvent , payment_claimable_expected : bool , clear_recipient_events : bool , expected_preimage : Option < PaymentPreimage > , is_probe : bool ) -> Option < Event > {
2453+ pub struct PassAlongPathArgs < ' a , ' b , ' c , ' d > {
2454+ pub origin_node : & ' a Node < ' b , ' c , ' d > ,
2455+ pub expected_path : & ' a [ & ' a Node < ' b , ' c , ' d > ] ,
2456+ pub recv_value : u64 ,
2457+ pub payment_hash : PaymentHash ,
2458+ pub payment_secret : Option < PaymentSecret > ,
2459+ pub event : MessageSendEvent ,
2460+ pub payment_claimable_expected : bool ,
2461+ pub clear_recipient_events : bool ,
2462+ pub expected_preimage : Option < PaymentPreimage > ,
2463+ pub is_probe : bool ,
2464+ }
2465+
2466+ impl < ' a , ' b , ' c , ' d > PassAlongPathArgs < ' a , ' b , ' c , ' d > {
2467+ pub fn new (
2468+ origin_node : & ' a Node < ' b , ' c , ' d > , expected_path : & ' a [ & ' a Node < ' b , ' c , ' d > ] , recv_value : u64 ,
2469+ payment_hash : PaymentHash , event : MessageSendEvent ,
2470+ ) -> Self {
2471+ Self {
2472+ origin_node, expected_path, recv_value, payment_hash, payment_secret : None , event,
2473+ payment_claimable_expected : true , clear_recipient_events : true , expected_preimage : None ,
2474+ is_probe : false ,
2475+ }
2476+ }
2477+ pub fn clear_recipient_events ( mut self , clear_recipient_events : bool ) -> Self {
2478+ self . clear_recipient_events = clear_recipient_events;
2479+ self
2480+ }
2481+ pub fn is_probe ( mut self ) -> Self {
2482+ self . payment_claimable_expected = false ;
2483+ self . is_probe = true ;
2484+ self
2485+ }
2486+ pub fn expect_payment_claimable ( mut self , expect_payment_claimable : bool ) -> Self {
2487+ self . payment_claimable_expected = expect_payment_claimable;
2488+ self
2489+ }
2490+ pub fn with_payment_secret ( mut self , payment_secret : PaymentSecret ) -> Self {
2491+ self . payment_secret = Some ( payment_secret) ;
2492+ self
2493+ }
2494+ pub fn with_payment_preimage ( mut self , payment_preimage : PaymentPreimage ) -> Self {
2495+ self . expected_preimage = Some ( payment_preimage) ;
2496+ self
2497+ }
2498+ }
2499+
2500+ pub fn do_pass_along_path < ' a , ' b , ' c > ( args : PassAlongPathArgs ) -> Option < Event > {
2501+ let PassAlongPathArgs {
2502+ origin_node, expected_path, recv_value, payment_hash : our_payment_hash,
2503+ payment_secret : our_payment_secret, event : ev, payment_claimable_expected,
2504+ clear_recipient_events, expected_preimage, is_probe
2505+ } = args;
2506+
24542507 let mut payment_event = SendEvent :: from_event ( ev) ;
24552508 let mut prev_node = origin_node;
24562509 let mut event = None ;
@@ -2517,7 +2570,15 @@ pub fn do_pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_p
25172570}
25182571
25192572pub fn pass_along_path < ' a , ' b , ' c > ( origin_node : & Node < ' a , ' b , ' c > , expected_path : & [ & Node < ' a , ' b , ' c > ] , recv_value : u64 , our_payment_hash : PaymentHash , our_payment_secret : Option < PaymentSecret > , ev : MessageSendEvent , payment_claimable_expected : bool , expected_preimage : Option < PaymentPreimage > ) -> Option < Event > {
2520- do_pass_along_path ( origin_node, expected_path, recv_value, our_payment_hash, our_payment_secret, ev, payment_claimable_expected, true , expected_preimage, false )
2573+ let mut args = PassAlongPathArgs :: new ( origin_node, expected_path, recv_value, our_payment_hash, ev)
2574+ . expect_payment_claimable ( payment_claimable_expected) ;
2575+ if let Some ( payment_secret) = our_payment_secret {
2576+ args = args. with_payment_secret ( payment_secret) ;
2577+ }
2578+ if let Some ( payment_preimage) = expected_preimage {
2579+ args = args. with_payment_preimage ( payment_preimage) ;
2580+ }
2581+ do_pass_along_path ( args)
25212582}
25222583
25232584pub fn send_probe_along_route < ' a , ' b , ' c > ( origin_node : & Node < ' a , ' b , ' c > , expected_route : & [ & [ & Node < ' a , ' b , ' c > ] ] ) {
@@ -2529,7 +2590,10 @@ pub fn send_probe_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expect
25292590 for path in expected_route. iter ( ) {
25302591 let ev = remove_first_msg_event_to_node ( & path[ 0 ] . node . get_our_node_id ( ) , & mut events) ;
25312592
2532- do_pass_along_path ( origin_node, path, 0 , PaymentHash ( [ 0_u8 ; 32 ] ) , None , ev, false , false , None , true ) ;
2593+ do_pass_along_path ( PassAlongPathArgs :: new ( origin_node, path, 0 , PaymentHash ( [ 0_u8 ; 32 ] ) , ev)
2594+ . is_probe ( )
2595+ . clear_recipient_events ( false ) ) ;
2596+
25332597 let nodes_to_fail_payment: Vec < _ > = vec ! [ origin_node] . into_iter ( ) . chain ( path. iter ( ) . cloned ( ) ) . collect ( ) ;
25342598
25352599 fail_payment_along_path ( nodes_to_fail_payment. as_slice ( ) ) ;
0 commit comments