@@ -2472,7 +2472,60 @@ fn fail_payment_along_path<'a, 'b, 'c>(expected_path: &[&Node<'a, 'b, 'c>]) {
2472
2472
}
2473
2473
}
2474
2474
2475
- 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 > {
2475
+ pub struct PassAlongPathArgs < ' a , ' b , ' c , ' d > {
2476
+ pub origin_node : & ' a Node < ' b , ' c , ' d > ,
2477
+ pub expected_path : & ' a [ & ' a Node < ' b , ' c , ' d > ] ,
2478
+ pub recv_value : u64 ,
2479
+ pub payment_hash : PaymentHash ,
2480
+ pub payment_secret : Option < PaymentSecret > ,
2481
+ pub event : MessageSendEvent ,
2482
+ pub payment_claimable_expected : bool ,
2483
+ pub clear_recipient_events : bool ,
2484
+ pub expected_preimage : Option < PaymentPreimage > ,
2485
+ pub is_probe : bool ,
2486
+ }
2487
+
2488
+ impl < ' a , ' b , ' c , ' d > PassAlongPathArgs < ' a , ' b , ' c , ' d > {
2489
+ pub fn new (
2490
+ origin_node : & ' a Node < ' b , ' c , ' d > , expected_path : & ' a [ & ' a Node < ' b , ' c , ' d > ] , recv_value : u64 ,
2491
+ payment_hash : PaymentHash , event : MessageSendEvent ,
2492
+ ) -> Self {
2493
+ Self {
2494
+ origin_node, expected_path, recv_value, payment_hash, payment_secret : None , event,
2495
+ payment_claimable_expected : true , clear_recipient_events : true , expected_preimage : None ,
2496
+ is_probe : false ,
2497
+ }
2498
+ }
2499
+ pub fn without_clearing_recipient_events ( mut self ) -> Self {
2500
+ self . clear_recipient_events = false ;
2501
+ self
2502
+ }
2503
+ pub fn is_probe ( mut self ) -> Self {
2504
+ self . payment_claimable_expected = false ;
2505
+ self . is_probe = true ;
2506
+ self
2507
+ }
2508
+ pub fn without_claimable_event ( mut self ) -> Self {
2509
+ self . payment_claimable_expected = false ;
2510
+ self
2511
+ }
2512
+ pub fn with_payment_secret ( mut self , payment_secret : PaymentSecret ) -> Self {
2513
+ self . payment_secret = Some ( payment_secret) ;
2514
+ self
2515
+ }
2516
+ pub fn with_payment_preimage ( mut self , payment_preimage : PaymentPreimage ) -> Self {
2517
+ self . expected_preimage = Some ( payment_preimage) ;
2518
+ self
2519
+ }
2520
+ }
2521
+
2522
+ pub fn do_pass_along_path < ' a , ' b , ' c > ( args : PassAlongPathArgs ) -> Option < Event > {
2523
+ let PassAlongPathArgs {
2524
+ origin_node, expected_path, recv_value, payment_hash : our_payment_hash,
2525
+ payment_secret : our_payment_secret, event : ev, payment_claimable_expected,
2526
+ clear_recipient_events, expected_preimage, is_probe
2527
+ } = args;
2528
+
2476
2529
let mut payment_event = SendEvent :: from_event ( ev) ;
2477
2530
let mut prev_node = origin_node;
2478
2531
let mut event = None ;
@@ -2539,7 +2592,17 @@ pub fn do_pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_p
2539
2592
}
2540
2593
2541
2594
pub 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 > {
2542
- do_pass_along_path ( origin_node, expected_path, recv_value, our_payment_hash, our_payment_secret, ev, payment_claimable_expected, true , expected_preimage, false )
2595
+ let mut args = PassAlongPathArgs :: new ( origin_node, expected_path, recv_value, our_payment_hash, ev) ;
2596
+ if !payment_claimable_expected {
2597
+ args = args. without_claimable_event ( ) ;
2598
+ }
2599
+ if let Some ( payment_secret) = our_payment_secret {
2600
+ args = args. with_payment_secret ( payment_secret) ;
2601
+ }
2602
+ if let Some ( payment_preimage) = expected_preimage {
2603
+ args = args. with_payment_preimage ( payment_preimage) ;
2604
+ }
2605
+ do_pass_along_path ( args)
2543
2606
}
2544
2607
2545
2608
pub fn send_probe_along_route < ' a , ' b , ' c > ( origin_node : & Node < ' a , ' b , ' c > , expected_route : & [ & [ & Node < ' a , ' b , ' c > ] ] ) {
@@ -2551,7 +2614,10 @@ pub fn send_probe_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expect
2551
2614
for path in expected_route. iter ( ) {
2552
2615
let ev = remove_first_msg_event_to_node ( & path[ 0 ] . node . get_our_node_id ( ) , & mut events) ;
2553
2616
2554
- do_pass_along_path ( origin_node, path, 0 , PaymentHash ( [ 0_u8 ; 32 ] ) , None , ev, false , false , None , true ) ;
2617
+ do_pass_along_path ( PassAlongPathArgs :: new ( origin_node, path, 0 , PaymentHash ( [ 0_u8 ; 32 ] ) , ev)
2618
+ . is_probe ( )
2619
+ . without_clearing_recipient_events ( ) ) ;
2620
+
2555
2621
let nodes_to_fail_payment: Vec < _ > = vec ! [ origin_node] . into_iter ( ) . chain ( path. iter ( ) . cloned ( ) ) . collect ( ) ;
2556
2622
2557
2623
fail_payment_along_path ( nodes_to_fail_payment. as_slice ( ) ) ;
0 commit comments