@@ -2393,7 +2393,60 @@ fn fail_payment_along_path<'a, 'b, 'c>(expected_path: &[&Node<'a, 'b, 'c>]) {
23932393 }
23942394}
23952395
2396- 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 > {
2396+ pub struct PassAlongPathArgs < ' a , ' b , ' c , ' d > {
2397+ pub origin_node : & ' a Node < ' b , ' c , ' d > ,
2398+ pub expected_path : & ' a [ & ' a Node < ' b , ' c , ' d > ] ,
2399+ pub recv_value : u64 ,
2400+ pub payment_hash : PaymentHash ,
2401+ pub payment_secret : Option < PaymentSecret > ,
2402+ pub event : MessageSendEvent ,
2403+ pub payment_claimable_expected : bool ,
2404+ pub clear_recipient_events : bool ,
2405+ pub expected_preimage : Option < PaymentPreimage > ,
2406+ pub is_probe : bool ,
2407+ }
2408+
2409+ impl < ' a , ' b , ' c , ' d > PassAlongPathArgs < ' a , ' b , ' c , ' d > {
2410+ pub fn new (
2411+ origin_node : & ' a Node < ' b , ' c , ' d > , expected_path : & ' a [ & ' a Node < ' b , ' c , ' d > ] , recv_value : u64 ,
2412+ payment_hash : PaymentHash , event : MessageSendEvent ,
2413+ ) -> Self {
2414+ Self {
2415+ origin_node, expected_path, recv_value, payment_hash, payment_secret : None , event,
2416+ payment_claimable_expected : true , clear_recipient_events : true , expected_preimage : None ,
2417+ is_probe : false ,
2418+ }
2419+ }
2420+ pub fn clear_recipient_events ( mut self , clear_recipient_events : bool ) -> Self {
2421+ self . clear_recipient_events = clear_recipient_events;
2422+ self
2423+ }
2424+ pub fn is_probe ( mut self ) -> Self {
2425+ self . payment_claimable_expected = false ;
2426+ self . is_probe = true ;
2427+ self
2428+ }
2429+ pub fn expect_payment_claimable ( mut self , expect_payment_claimable : bool ) -> Self {
2430+ self . payment_claimable_expected = expect_payment_claimable;
2431+ self
2432+ }
2433+ pub fn with_payment_secret ( mut self , payment_secret : PaymentSecret ) -> Self {
2434+ self . payment_secret = Some ( payment_secret) ;
2435+ self
2436+ }
2437+ pub fn with_payment_preimage ( mut self , payment_preimage : PaymentPreimage ) -> Self {
2438+ self . expected_preimage = Some ( payment_preimage) ;
2439+ self
2440+ }
2441+ }
2442+
2443+ pub fn do_pass_along_path < ' a , ' b , ' c > ( args : PassAlongPathArgs ) -> Option < Event > {
2444+ let PassAlongPathArgs {
2445+ origin_node, expected_path, recv_value, payment_hash : our_payment_hash,
2446+ payment_secret : our_payment_secret, event : ev, payment_claimable_expected,
2447+ clear_recipient_events, expected_preimage, is_probe
2448+ } = args;
2449+
23972450 let mut payment_event = SendEvent :: from_event ( ev) ;
23982451 let mut prev_node = origin_node;
23992452 let mut event = None ;
@@ -2460,7 +2513,15 @@ pub fn do_pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_p
24602513}
24612514
24622515pub 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 > {
2463- do_pass_along_path ( origin_node, expected_path, recv_value, our_payment_hash, our_payment_secret, ev, payment_claimable_expected, true , expected_preimage, false )
2516+ let mut args = PassAlongPathArgs :: new ( origin_node, expected_path, recv_value, our_payment_hash, ev)
2517+ . expect_payment_claimable ( payment_claimable_expected) ;
2518+ if let Some ( payment_secret) = our_payment_secret {
2519+ args = args. with_payment_secret ( payment_secret) ;
2520+ }
2521+ if let Some ( payment_preimage) = expected_preimage {
2522+ args = args. with_payment_preimage ( payment_preimage) ;
2523+ }
2524+ do_pass_along_path ( args)
24642525}
24652526
24662527pub fn send_probe_along_route < ' a , ' b , ' c > ( origin_node : & Node < ' a , ' b , ' c > , expected_route : & [ & [ & Node < ' a , ' b , ' c > ] ] ) {
@@ -2472,7 +2533,10 @@ pub fn send_probe_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expect
24722533 for path in expected_route. iter ( ) {
24732534 let ev = remove_first_msg_event_to_node ( & path[ 0 ] . node . get_our_node_id ( ) , & mut events) ;
24742535
2475- do_pass_along_path ( origin_node, path, 0 , PaymentHash ( [ 0_u8 ; 32 ] ) , None , ev, false , false , None , true ) ;
2536+ do_pass_along_path ( PassAlongPathArgs :: new ( origin_node, path, 0 , PaymentHash ( [ 0_u8 ; 32 ] ) , ev)
2537+ . is_probe ( )
2538+ . clear_recipient_events ( false ) ) ;
2539+
24762540 let nodes_to_fail_payment: Vec < _ > = vec ! [ origin_node] . into_iter ( ) . chain ( path. iter ( ) . cloned ( ) ) . collect ( ) ;
24772541
24782542 fail_payment_along_path ( nodes_to_fail_payment. as_slice ( ) ) ;
0 commit comments