1717
1818extern crate bech32;
1919extern crate bitcoin_hashes;
20+ extern crate lightning;
2021extern crate num_traits;
2122extern crate secp256k1;
2223
2324use bech32:: u5;
2425use bitcoin_hashes:: Hash ;
2526use bitcoin_hashes:: sha256;
27+ use lightning:: routing:: network_graph:: RoutingFees ;
28+ use lightning:: routing:: router:: RouteHint ;
2629
2730use secp256k1:: key:: PublicKey ;
2831use secp256k1:: { Message , Secp256k1 } ;
@@ -383,26 +386,7 @@ pub struct Signature(pub RecoverableSignature);
383386/// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
384387///
385388#[ derive( Eq , PartialEq , Debug , Clone ) ]
386- pub struct Route ( Vec < RouteHop > ) ;
387-
388- /// Node on a private route
389- #[ derive( Eq , PartialEq , Debug , Clone ) ]
390- pub struct RouteHop {
391- /// Node's public key
392- pub pubkey : PublicKey ,
393-
394- /// Which channel of this node we would be using
395- pub short_channel_id : [ u8 ; 8 ] ,
396-
397- /// Fee charged by this node per transaction
398- pub fee_base_msat : u32 ,
399-
400- /// Fee charged by this node proportional to the amount routed
401- pub fee_proportional_millionths : u32 ,
402-
403- /// Delta substracted by this node from incoming cltv_expiry value
404- pub cltv_expiry_delta : u16 ,
405- }
389+ pub struct Route ( Vec < RouteHint > ) ;
406390
407391/// Tag constants as specified in BOLT11
408392#[ allow( missing_docs) ]
@@ -499,7 +483,7 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool> InvoiceBuilder<D, H, T> {
499483 }
500484
501485 /// Adds a private route.
502- pub fn route ( mut self , route : Vec < RouteHop > ) -> Self {
486+ pub fn route ( mut self , route : Vec < RouteHint > ) -> Self {
503487 match Route :: new ( route) {
504488 Ok ( r) => self . tagged_fields . push ( TaggedField :: Route ( r) ) ,
505489 Err ( e) => self . error = Some ( e) ,
@@ -1159,7 +1143,7 @@ impl ExpiryTime {
11591143
11601144impl Route {
11611145 /// Create a new (partial) route from a list of hops
1162- pub fn new ( hops : Vec < RouteHop > ) -> Result < Route , CreationError > {
1146+ pub fn new ( hops : Vec < RouteHint > ) -> Result < Route , CreationError > {
11631147 if hops. len ( ) <= 12 {
11641148 Ok ( Route ( hops) )
11651149 } else {
@@ -1168,21 +1152,21 @@ impl Route {
11681152 }
11691153
11701154 /// Returrn the underlying vector of hops
1171- pub fn into_inner ( self ) -> Vec < RouteHop > {
1155+ pub fn into_inner ( self ) -> Vec < RouteHint > {
11721156 self . 0
11731157 }
11741158}
11751159
1176- impl Into < Vec < RouteHop > > for Route {
1177- fn into ( self ) -> Vec < RouteHop > {
1160+ impl Into < Vec < RouteHint > > for Route {
1161+ fn into ( self ) -> Vec < RouteHint > {
11781162 self . into_inner ( )
11791163 }
11801164}
11811165
11821166impl Deref for Route {
1183- type Target = Vec < RouteHop > ;
1167+ type Target = Vec < RouteHint > ;
11841168
1185- fn deref ( & self ) -> & Vec < RouteHop > {
1169+ fn deref ( & self ) -> & Vec < RouteHint > {
11861170 & self . 0
11871171 }
11881172}
@@ -1458,18 +1442,22 @@ mod test {
14581442 . build_raw ( ) ;
14591443 assert_eq ! ( long_desc_res, Err ( CreationError :: DescriptionTooLong ) ) ;
14601444
1461- let route_hop = RouteHop {
1462- pubkey : PublicKey :: from_slice (
1445+ let route_hop = RouteHint {
1446+ src_node_id : PublicKey :: from_slice (
14631447 & [
14641448 0x03 , 0x9e , 0x03 , 0xa9 , 0x01 , 0xb8 , 0x55 , 0x34 , 0xff , 0x1e , 0x92 , 0xc4 ,
14651449 0x3c , 0x74 , 0x43 , 0x1f , 0x7c , 0xe7 , 0x20 , 0x46 , 0x06 , 0x0f , 0xcf , 0x7a ,
14661450 0x95 , 0xc3 , 0x7e , 0x14 , 0x8f , 0x78 , 0xc7 , 0x72 , 0x55
14671451 ] [ ..]
14681452 ) . unwrap ( ) ,
1469- short_channel_id : [ 0 ; 8 ] ,
1470- fee_base_msat : 0 ,
1471- fee_proportional_millionths : 0 ,
1453+ short_channel_id : 0 ,
1454+ fees : RoutingFees {
1455+ base_msat : 0 ,
1456+ proportional_millionths : 0 ,
1457+ } ,
14721458 cltv_expiry_delta : 0 ,
1459+ htlc_minimum_msat : None ,
1460+ htlc_maximum_msat : None ,
14731461 } ;
14741462 let too_long_route = vec ! [ route_hop; 13 ] ;
14751463 let long_route_res = builder. clone ( )
@@ -1505,36 +1493,52 @@ mod test {
15051493 let public_key = PublicKey :: from_secret_key ( & secp_ctx, & private_key) ;
15061494
15071495 let route_1 = vec ! [
1508- RouteHop {
1509- pubkey: public_key. clone( ) ,
1510- short_channel_id: [ 123 ; 8 ] ,
1511- fee_base_msat: 2 ,
1512- fee_proportional_millionths: 1 ,
1496+ RouteHint {
1497+ src_node_id: public_key. clone( ) ,
1498+ short_channel_id: u64 :: from_be_bytes( [ 123 ; 8 ] ) ,
1499+ fees: RoutingFees {
1500+ base_msat: 2 ,
1501+ proportional_millionths: 1 ,
1502+ } ,
15131503 cltv_expiry_delta: 145 ,
1504+ htlc_minimum_msat: None ,
1505+ htlc_maximum_msat: None ,
15141506 } ,
1515- RouteHop {
1516- pubkey: public_key. clone( ) ,
1517- short_channel_id: [ 42 ; 8 ] ,
1518- fee_base_msat: 3 ,
1519- fee_proportional_millionths: 2 ,
1507+ RouteHint {
1508+ src_node_id: public_key. clone( ) ,
1509+ short_channel_id: u64 :: from_be_bytes( [ 42 ; 8 ] ) ,
1510+ fees: RoutingFees {
1511+ base_msat: 3 ,
1512+ proportional_millionths: 2 ,
1513+ } ,
15201514 cltv_expiry_delta: 146 ,
1515+ htlc_minimum_msat: None ,
1516+ htlc_maximum_msat: None ,
15211517 }
15221518 ] ;
15231519
15241520 let route_2 = vec ! [
1525- RouteHop {
1526- pubkey: public_key. clone( ) ,
1527- short_channel_id: [ 0 ; 8 ] ,
1528- fee_base_msat: 4 ,
1529- fee_proportional_millionths: 3 ,
1521+ RouteHint {
1522+ src_node_id: public_key. clone( ) ,
1523+ short_channel_id: 0 ,
1524+ fees: RoutingFees {
1525+ base_msat: 4 ,
1526+ proportional_millionths: 3 ,
1527+ } ,
15301528 cltv_expiry_delta: 147 ,
1529+ htlc_minimum_msat: None ,
1530+ htlc_maximum_msat: None ,
15311531 } ,
1532- RouteHop {
1533- pubkey: public_key. clone( ) ,
1534- short_channel_id: [ 1 ; 8 ] ,
1535- fee_base_msat: 5 ,
1536- fee_proportional_millionths: 4 ,
1532+ RouteHint {
1533+ src_node_id: public_key. clone( ) ,
1534+ short_channel_id: u64 :: from_be_bytes( [ 1 ; 8 ] ) ,
1535+ fees: RoutingFees {
1536+ base_msat: 5 ,
1537+ proportional_millionths: 4 ,
1538+ } ,
15371539 cltv_expiry_delta: 148 ,
1540+ htlc_minimum_msat: None ,
1541+ htlc_maximum_msat: None ,
15381542 }
15391543 ] ;
15401544
0 commit comments