@@ -10,6 +10,8 @@ use bech32::{u5, FromBase32};
1010
1111use bitcoin_hashes:: Hash ;
1212use bitcoin_hashes:: sha256;
13+ use lightning:: routing:: network_graph:: RoutingFees ;
14+ use lightning:: routing:: router:: RouteHintHop ;
1315
1416use num_traits:: { CheckedAdd , CheckedMul } ;
1517
@@ -353,7 +355,7 @@ impl FromBase32 for Signature {
353355 }
354356}
355357
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 >
357359 where T : CheckedAdd + CheckedMul + From < u8 > + Default ,
358360 U : Into < u8 > + Copy
359361{
@@ -428,7 +430,7 @@ impl FromBase32 for TaggedField {
428430 constants:: TAG_FALLBACK =>
429431 Ok ( TaggedField :: Fallback ( Fallback :: from_base32 ( field_data) ?) ) ,
430432 constants:: TAG_ROUTE =>
431- Ok ( TaggedField :: Route ( Route :: from_base32 ( field_data) ?) ) ,
433+ Ok ( TaggedField :: Route ( RouteHint :: from_base32 ( field_data) ?) ) ,
432434 constants:: TAG_PAYMENT_SECRET =>
433435 Ok ( TaggedField :: PaymentSecret ( PaymentSecret :: from_base32 ( field_data) ?) ) ,
434436 _ => {
@@ -565,17 +567,17 @@ impl FromBase32 for Fallback {
565567 }
566568}
567569
568- impl FromBase32 for Route {
570+ impl FromBase32 for RouteHint {
569571 type Err = ParseError ;
570572
571- fn from_base32 ( field_data : & [ u5 ] ) -> Result < Route , ParseError > {
573+ fn from_base32 ( field_data : & [ u5 ] ) -> Result < RouteHint , ParseError > {
572574 let bytes = Vec :: < u8 > :: from_base32 ( field_data) ?;
573575
574576 if bytes. len ( ) % 51 != 0 {
575577 return Err ( ParseError :: UnexpectedEndOfTaggedFields ) ;
576578 }
577579
578- let mut route_hops = Vec :: < RouteHop > :: new ( ) ;
580+ let mut route_hops = Vec :: < RouteHintHop > :: new ( ) ;
579581
580582 let mut bytes = bytes. as_slice ( ) ;
581583 while !bytes. is_empty ( ) {
@@ -585,18 +587,22 @@ impl FromBase32 for Route {
585587 let mut channel_id: [ u8 ; 8 ] = Default :: default ( ) ;
586588 channel_id. copy_from_slice ( & hop_bytes[ 33 ..41 ] ) ;
587589
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 ,
594600 } ;
595601
596602 route_hops. push ( hop) ;
597603 }
598604
599- Ok ( Route ( route_hops) )
605+ Ok ( RouteHint ( route_hops) )
600606 }
601607}
602608
@@ -931,47 +937,57 @@ mod test {
931937
932938 #[ test]
933939 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 ;
936943 use bech32:: FromBase32 ;
944+ use de:: parse_int_be;
937945
938946 let input = from_bech32 (
939947 "q20q82gphp2nflc7jtzrcazrra7wwgzxqc8u7754cdlpfrmccae92qgzqvzq2ps8pqqqqqqpqqqqq9qqqvpeuqa\
940948 fqxu92d8lr6fvg0r5gv0heeeqgcrqlnm6jhphu9y00rrhy4grqszsvpcgpy9qqqqqqgqqqqq7qqzq". as_bytes ( )
941949 ) ;
942950
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 (
946954 & [
947955 0x02u8 , 0x9e , 0x03 , 0xa9 , 0x01 , 0xb8 , 0x55 , 0x34 , 0xff , 0x1e , 0x92 , 0xc4 , 0x3c ,
948956 0x74 , 0x43 , 0x1f , 0x7c , 0xe7 , 0x20 , 0x46 , 0x06 , 0x0f , 0xcf , 0x7a , 0x95 , 0xc3 ,
949957 0x7e , 0x14 , 0x8f , 0x78 , 0xc7 , 0x72 , 0x55
950958 ] [ ..]
951959 ) . 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
956968 } ) ;
957- expected. push ( RouteHop {
958- pubkey : PublicKey :: from_slice (
969+ expected. push ( RouteHintHop {
970+ src_node_id : PublicKey :: from_slice (
959971 & [
960972 0x03u8 , 0x9e , 0x03 , 0xa9 , 0x01 , 0xb8 , 0x55 , 0x34 , 0xff , 0x1e , 0x92 , 0xc4 , 0x3c ,
961973 0x74 , 0x43 , 0x1f , 0x7c , 0xe7 , 0x20 , 0x46 , 0x06 , 0x0f , 0xcf , 0x7a , 0x95 , 0xc3 ,
962974 0x7e , 0x14 , 0x8f , 0x78 , 0xc7 , 0x72 , 0x55
963975 ] [ ..]
964976 ) . 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
969985 } ) ;
970986
971- assert_eq ! ( Route :: from_base32( & input) , Ok ( Route ( expected) ) ) ;
987+ assert_eq ! ( RouteHint :: from_base32( & input) , Ok ( RouteHint ( expected) ) ) ;
972988
973989 assert_eq ! (
974- Route :: from_base32( & [ u5:: try_from_u8( 0 ) . unwrap( ) ; 40 ] [ ..] ) ,
990+ RouteHint :: from_base32( & [ u5:: try_from_u8( 0 ) . unwrap( ) ; 40 ] [ ..] ) ,
975991 Err ( ParseError :: UnexpectedEndOfTaggedFields )
976992 ) ;
977993 }
0 commit comments