@@ -10,6 +10,8 @@ use bech32::{u5, FromBase32};
10
10
11
11
use bitcoin_hashes:: Hash ;
12
12
use bitcoin_hashes:: sha256;
13
+ use lightning:: routing:: network_graph:: RoutingFees ;
14
+ use lightning:: routing:: router:: RouteHintHop ;
13
15
14
16
use num_traits:: { CheckedAdd , CheckedMul } ;
15
17
@@ -353,7 +355,7 @@ impl FromBase32 for Signature {
353
355
}
354
356
}
355
357
356
- fn parse_int_be < T , U > ( digits : & [ U ] , base : T ) -> Option < T >
358
+ pub ( crate ) fn parse_int_be < T , U > ( digits : & [ U ] , base : T ) -> Option < T >
357
359
where T : CheckedAdd + CheckedMul + From < u8 > + Default ,
358
360
U : Into < u8 > + Copy
359
361
{
@@ -428,7 +430,7 @@ impl FromBase32 for TaggedField {
428
430
constants:: TAG_FALLBACK =>
429
431
Ok ( TaggedField :: Fallback ( Fallback :: from_base32 ( field_data) ?) ) ,
430
432
constants:: TAG_ROUTE =>
431
- Ok ( TaggedField :: Route ( Route :: from_base32 ( field_data) ?) ) ,
433
+ Ok ( TaggedField :: Route ( RouteHint :: from_base32 ( field_data) ?) ) ,
432
434
constants:: TAG_PAYMENT_SECRET =>
433
435
Ok ( TaggedField :: PaymentSecret ( PaymentSecret :: from_base32 ( field_data) ?) ) ,
434
436
_ => {
@@ -565,17 +567,17 @@ impl FromBase32 for Fallback {
565
567
}
566
568
}
567
569
568
- impl FromBase32 for Route {
570
+ impl FromBase32 for RouteHint {
569
571
type Err = ParseError ;
570
572
571
- fn from_base32 ( field_data : & [ u5 ] ) -> Result < Route , ParseError > {
573
+ fn from_base32 ( field_data : & [ u5 ] ) -> Result < RouteHint , ParseError > {
572
574
let bytes = Vec :: < u8 > :: from_base32 ( field_data) ?;
573
575
574
576
if bytes. len ( ) % 51 != 0 {
575
577
return Err ( ParseError :: UnexpectedEndOfTaggedFields ) ;
576
578
}
577
579
578
- let mut route_hops = Vec :: < RouteHop > :: new ( ) ;
580
+ let mut route_hops = Vec :: < RouteHintHop > :: new ( ) ;
579
581
580
582
let mut bytes = bytes. as_slice ( ) ;
581
583
while !bytes. is_empty ( ) {
@@ -585,18 +587,22 @@ impl FromBase32 for Route {
585
587
let mut channel_id: [ u8 ; 8 ] = Default :: default ( ) ;
586
588
channel_id. copy_from_slice ( & hop_bytes[ 33 ..41 ] ) ;
587
589
588
- let hop = RouteHop {
589
- pubkey : PublicKey :: from_slice ( & hop_bytes[ 0 ..33 ] ) ?,
590
- short_channel_id : channel_id,
591
- fee_base_msat : parse_int_be ( & hop_bytes[ 41 ..45 ] , 256 ) . expect ( "slice too big?" ) ,
592
- fee_proportional_millionths : parse_int_be ( & hop_bytes[ 45 ..49 ] , 256 ) . expect ( "slice too big?" ) ,
593
- cltv_expiry_delta : parse_int_be ( & hop_bytes[ 49 ..51 ] , 256 ) . expect ( "slice too big?" )
590
+ let hop = RouteHintHop {
591
+ src_node_id : PublicKey :: from_slice ( & hop_bytes[ 0 ..33 ] ) ?,
592
+ short_channel_id : parse_int_be ( & channel_id, 256 ) . expect ( "short chan ID slice too big?" ) ,
593
+ fees : RoutingFees {
594
+ base_msat : parse_int_be ( & hop_bytes[ 41 ..45 ] , 256 ) . expect ( "slice too big?" ) ,
595
+ proportional_millionths : parse_int_be ( & hop_bytes[ 45 ..49 ] , 256 ) . expect ( "slice too big?" ) ,
596
+ } ,
597
+ cltv_expiry_delta : parse_int_be ( & hop_bytes[ 49 ..51 ] , 256 ) . expect ( "slice too big?" ) ,
598
+ htlc_minimum_msat : None ,
599
+ htlc_maximum_msat : None ,
594
600
} ;
595
601
596
602
route_hops. push ( hop) ;
597
603
}
598
604
599
- Ok ( Route ( route_hops) )
605
+ Ok ( RouteHint ( route_hops) )
600
606
}
601
607
}
602
608
@@ -931,47 +937,57 @@ mod test {
931
937
932
938
#[ test]
933
939
fn test_parse_route ( ) {
934
- use RouteHop ;
935
- use :: Route ;
940
+ use lightning:: routing:: network_graph:: RoutingFees ;
941
+ use lightning:: routing:: router:: RouteHintHop ;
942
+ use :: RouteHint ;
936
943
use bech32:: FromBase32 ;
944
+ use de:: parse_int_be;
937
945
938
946
let input = from_bech32 (
939
947
"q20q82gphp2nflc7jtzrcazrra7wwgzxqc8u7754cdlpfrmccae92qgzqvzq2ps8pqqqqqqpqqqqq9qqqvpeuqa\
940
948
fqxu92d8lr6fvg0r5gv0heeeqgcrqlnm6jhphu9y00rrhy4grqszsvpcgpy9qqqqqqgqqqqq7qqzq". as_bytes ( )
941
949
) ;
942
950
943
- let mut expected = Vec :: < RouteHop > :: new ( ) ;
944
- expected. push ( RouteHop {
945
- pubkey : PublicKey :: from_slice (
951
+ let mut expected = Vec :: < RouteHintHop > :: new ( ) ;
952
+ expected. push ( RouteHintHop {
953
+ src_node_id : PublicKey :: from_slice (
946
954
& [
947
955
0x02u8 , 0x9e , 0x03 , 0xa9 , 0x01 , 0xb8 , 0x55 , 0x34 , 0xff , 0x1e , 0x92 , 0xc4 , 0x3c ,
948
956
0x74 , 0x43 , 0x1f , 0x7c , 0xe7 , 0x20 , 0x46 , 0x06 , 0x0f , 0xcf , 0x7a , 0x95 , 0xc3 ,
949
957
0x7e , 0x14 , 0x8f , 0x78 , 0xc7 , 0x72 , 0x55
950
958
] [ ..]
951
959
) . unwrap ( ) ,
952
- short_channel_id : [ 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 ] ,
953
- fee_base_msat : 1 ,
954
- fee_proportional_millionths : 20 ,
955
- cltv_expiry_delta : 3
960
+ short_channel_id : parse_int_be ( & [ 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 ] , 256 ) . expect ( "short chan ID slice too big?" ) ,
961
+ fees : RoutingFees {
962
+ base_msat : 1 ,
963
+ proportional_millionths : 20 ,
964
+ } ,
965
+ cltv_expiry_delta : 3 ,
966
+ htlc_minimum_msat : None ,
967
+ htlc_maximum_msat : None
956
968
} ) ;
957
- expected. push ( RouteHop {
958
- pubkey : PublicKey :: from_slice (
969
+ expected. push ( RouteHintHop {
970
+ src_node_id : PublicKey :: from_slice (
959
971
& [
960
972
0x03u8 , 0x9e , 0x03 , 0xa9 , 0x01 , 0xb8 , 0x55 , 0x34 , 0xff , 0x1e , 0x92 , 0xc4 , 0x3c ,
961
973
0x74 , 0x43 , 0x1f , 0x7c , 0xe7 , 0x20 , 0x46 , 0x06 , 0x0f , 0xcf , 0x7a , 0x95 , 0xc3 ,
962
974
0x7e , 0x14 , 0x8f , 0x78 , 0xc7 , 0x72 , 0x55
963
975
] [ ..]
964
976
) . unwrap ( ) ,
965
- short_channel_id : [ 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0a ] ,
966
- fee_base_msat : 2 ,
967
- fee_proportional_millionths : 30 ,
968
- cltv_expiry_delta : 4
977
+ short_channel_id : parse_int_be ( & [ 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0a ] , 256 ) . expect ( "short chan ID slice too big?" ) ,
978
+ fees : RoutingFees {
979
+ base_msat : 2 ,
980
+ proportional_millionths : 30 ,
981
+ } ,
982
+ cltv_expiry_delta : 4 ,
983
+ htlc_minimum_msat : None ,
984
+ htlc_maximum_msat : None
969
985
} ) ;
970
986
971
- assert_eq ! ( Route :: from_base32( & input) , Ok ( Route ( expected) ) ) ;
987
+ assert_eq ! ( RouteHint :: from_base32( & input) , Ok ( RouteHint ( expected) ) ) ;
972
988
973
989
assert_eq ! (
974
- Route :: from_base32( & [ u5:: try_from_u8( 0 ) . unwrap( ) ; 40 ] [ ..] ) ,
990
+ RouteHint :: from_base32( & [ u5:: try_from_u8( 0 ) . unwrap( ) ; 40 ] [ ..] ) ,
975
991
Err ( ParseError :: UnexpectedEndOfTaggedFields )
976
992
) ;
977
993
}
0 commit comments