@@ -2716,18 +2716,12 @@ pub fn send_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route
27162716 ( our_payment_preimage, our_payment_hash, our_payment_secret, payment_id)
27172717}
27182718
2719- pub fn do_claim_payment_along_route < ' a , ' b , ' c > (
2720- origin_node : & Node < ' a , ' b , ' c > , expected_paths : & [ & [ & Node < ' a , ' b , ' c > ] ] , skip_last : bool ,
2721- our_payment_preimage : PaymentPreimage
2722- ) -> u64 {
2723- for path in expected_paths. iter ( ) {
2724- assert_eq ! ( path. last( ) . unwrap( ) . node. get_our_node_id( ) , expected_paths[ 0 ] . last( ) . unwrap( ) . node. get_our_node_id( ) ) ;
2719+ pub fn do_claim_payment_along_route ( args : ClaimAlongRouteArgs ) -> u64 {
2720+ for path in args. expected_paths . iter ( ) {
2721+ assert_eq ! ( path. last( ) . unwrap( ) . node. get_our_node_id( ) , args. expected_paths[ 0 ] . last( ) . unwrap( ) . node. get_our_node_id( ) ) ;
27252722 }
2726- expected_paths[ 0 ] . last ( ) . unwrap ( ) . node . claim_funds ( our_payment_preimage) ;
2727- pass_claimed_payment_along_route (
2728- ClaimAlongRouteArgs :: new ( origin_node, expected_paths, our_payment_preimage)
2729- . skip_last ( skip_last)
2730- )
2723+ args. expected_paths [ 0 ] . last ( ) . unwrap ( ) . node . claim_funds ( args. payment_preimage ) ;
2724+ pass_claimed_payment_along_route ( args)
27312725}
27322726
27332727pub struct ClaimAlongRouteArgs < ' a , ' b , ' c , ' d > {
@@ -2737,6 +2731,7 @@ pub struct ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
27372731 pub expected_min_htlc_overpay : Vec < u32 > ,
27382732 pub skip_last : bool ,
27392733 pub payment_preimage : PaymentPreimage ,
2734+ pub custom_tlvs : Vec < ( u64 , Vec < u8 > ) > ,
27402735 // Allow forwarding nodes to have taken 1 msat more fee than expected based on the downstream
27412736 // fulfill amount.
27422737 //
@@ -2755,7 +2750,7 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
27552750 Self {
27562751 origin_node, expected_paths, expected_extra_fees : vec ! [ 0 ; expected_paths. len( ) ] ,
27572752 expected_min_htlc_overpay : vec ! [ 0 ; expected_paths. len( ) ] , skip_last : false , payment_preimage,
2758- allow_1_msat_fee_overpay : false ,
2753+ allow_1_msat_fee_overpay : false , custom_tlvs : vec ! [ ] ,
27592754 }
27602755 }
27612756 pub fn skip_last ( mut self , skip_last : bool ) -> Self {
@@ -2774,12 +2769,16 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
27742769 self . allow_1_msat_fee_overpay = true ;
27752770 self
27762771 }
2772+ pub fn with_custom_tlvs ( mut self , custom_tlvs : Vec < ( u64 , Vec < u8 > ) > ) -> Self {
2773+ self . custom_tlvs = custom_tlvs;
2774+ self
2775+ }
27772776}
27782777
2779- pub fn pass_claimed_payment_along_route < ' a , ' b , ' c , ' d > ( args : ClaimAlongRouteArgs ) -> u64 {
2778+ pub fn pass_claimed_payment_along_route ( args : ClaimAlongRouteArgs ) -> u64 {
27802779 let ClaimAlongRouteArgs {
27812780 origin_node, expected_paths, expected_extra_fees, expected_min_htlc_overpay, skip_last,
2782- payment_preimage : our_payment_preimage, allow_1_msat_fee_overpay,
2781+ payment_preimage : our_payment_preimage, allow_1_msat_fee_overpay, custom_tlvs ,
27832782 } = args;
27842783 let claim_event = expected_paths[ 0 ] . last ( ) . unwrap ( ) . node . get_and_clear_pending_events ( ) ;
27852784 assert_eq ! ( claim_event. len( ) , 1 ) ;
@@ -2793,11 +2792,13 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArg
27932792 | PaymentPurpose :: Bolt12RefundPayment { payment_preimage : Some ( preimage) , .. } ,
27942793 amount_msat,
27952794 ref htlcs,
2795+ ref onion_fields,
27962796 ..
27972797 } => {
27982798 assert_eq ! ( preimage, our_payment_preimage) ;
27992799 assert_eq ! ( htlcs. len( ) , expected_paths. len( ) ) ; // One per path.
28002800 assert_eq ! ( htlcs. iter( ) . map( |h| h. value_msat) . sum:: <u64 >( ) , amount_msat) ;
2801+ assert_eq ! ( onion_fields. as_ref( ) . unwrap( ) . custom_tlvs, custom_tlvs) ;
28012802 expected_paths. iter ( ) . zip ( htlcs) . for_each ( |( path, htlc) | check_claimed_htlc_channel ( origin_node, path, htlc) ) ;
28022803 fwd_amt_msat = amount_msat;
28032804 } ,
@@ -2808,11 +2809,13 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArg
28082809 payment_hash,
28092810 amount_msat,
28102811 ref htlcs,
2812+ ref onion_fields,
28112813 ..
28122814 } => {
28132815 assert_eq ! ( & payment_hash. 0 , & Sha256 :: hash( & our_payment_preimage. 0 ) [ ..] ) ;
28142816 assert_eq ! ( htlcs. len( ) , expected_paths. len( ) ) ; // One per path.
28152817 assert_eq ! ( htlcs. iter( ) . map( |h| h. value_msat) . sum:: <u64 >( ) , amount_msat) ;
2818+ assert_eq ! ( onion_fields. as_ref( ) . unwrap( ) . custom_tlvs, custom_tlvs) ;
28162819 expected_paths. iter ( ) . zip ( htlcs) . for_each ( |( path, htlc) | check_claimed_htlc_channel ( origin_node, path, htlc) ) ;
28172820 fwd_amt_msat = amount_msat;
28182821 }
@@ -2956,15 +2959,20 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArg
29562959
29572960 expected_total_fee_msat
29582961}
2959- pub fn claim_payment_along_route < ' a , ' b , ' c > ( origin_node : & Node < ' a , ' b , ' c > , expected_paths : & [ & [ & Node < ' a , ' b , ' c > ] ] , skip_last : bool , our_payment_preimage : PaymentPreimage ) {
2960- let expected_total_fee_msat = do_claim_payment_along_route ( origin_node, expected_paths, skip_last, our_payment_preimage) ;
2962+ pub fn claim_payment_along_route ( args : ClaimAlongRouteArgs ) {
2963+ let origin_node = args. origin_node ;
2964+ let payment_preimage = args. payment_preimage ;
2965+ let skip_last = args. skip_last ;
2966+ let expected_total_fee_msat = do_claim_payment_along_route ( args) ;
29612967 if !skip_last {
2962- expect_payment_sent ! ( origin_node, our_payment_preimage , Some ( expected_total_fee_msat) ) ;
2968+ expect_payment_sent ! ( origin_node, payment_preimage , Some ( expected_total_fee_msat) ) ;
29632969 }
29642970}
29652971
29662972pub fn claim_payment < ' a , ' b , ' c > ( origin_node : & Node < ' a , ' b , ' c > , expected_route : & [ & Node < ' a , ' b , ' c > ] , our_payment_preimage : PaymentPreimage ) {
2967- claim_payment_along_route ( origin_node, & [ expected_route] , false , our_payment_preimage) ;
2973+ claim_payment_along_route (
2974+ ClaimAlongRouteArgs :: new ( origin_node, & [ expected_route] , our_payment_preimage)
2975+ ) ;
29682976}
29692977
29702978pub const TEST_FINAL_CLTV : u32 = 70 ;
0 commit comments