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+ #[ cfg( any( doc, test) ) ]
28+ use lightning:: routing:: network_graph:: RoutingFees ;
29+ use lightning:: routing:: router:: RouteHint ;
2630
2731use secp256k1:: key:: PublicKey ;
2832use secp256k1:: { Message , Secp256k1 } ;
@@ -383,26 +387,7 @@ pub struct Signature(pub RecoverableSignature);
383387/// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
384388///
385389#[ 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- }
390+ pub struct Route ( Vec < RouteHint > ) ;
406391
407392/// Tag constants as specified in BOLT11
408393#[ allow( missing_docs) ]
@@ -499,7 +484,7 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool> InvoiceBuilder<D, H, T> {
499484 }
500485
501486 /// Adds a private route.
502- pub fn route ( mut self , route : Vec < RouteHop > ) -> Self {
487+ pub fn route ( mut self , route : Vec < RouteHint > ) -> Self {
503488 match Route :: new ( route) {
504489 Ok ( r) => self . tagged_fields . push ( TaggedField :: Route ( r) ) ,
505490 Err ( e) => self . error = Some ( e) ,
@@ -1159,7 +1144,7 @@ impl ExpiryTime {
11591144
11601145impl Route {
11611146 /// Create a new (partial) route from a list of hops
1162- pub fn new ( hops : Vec < RouteHop > ) -> Result < Route , CreationError > {
1147+ pub fn new ( hops : Vec < RouteHint > ) -> Result < Route , CreationError > {
11631148 if hops. len ( ) <= 12 {
11641149 Ok ( Route ( hops) )
11651150 } else {
@@ -1168,21 +1153,21 @@ impl Route {
11681153 }
11691154
11701155 /// Returrn the underlying vector of hops
1171- pub fn into_inner ( self ) -> Vec < RouteHop > {
1156+ pub fn into_inner ( self ) -> Vec < RouteHint > {
11721157 self . 0
11731158 }
11741159}
11751160
1176- impl Into < Vec < RouteHop > > for Route {
1177- fn into ( self ) -> Vec < RouteHop > {
1161+ impl Into < Vec < RouteHint > > for Route {
1162+ fn into ( self ) -> Vec < RouteHint > {
11781163 self . into_inner ( )
11791164 }
11801165}
11811166
11821167impl Deref for Route {
1183- type Target = Vec < RouteHop > ;
1168+ type Target = Vec < RouteHint > ;
11841169
1185- fn deref ( & self ) -> & Vec < RouteHop > {
1170+ fn deref ( & self ) -> & Vec < RouteHint > {
11861171 & self . 0
11871172 }
11881173}
@@ -1458,18 +1443,22 @@ mod test {
14581443 . build_raw ( ) ;
14591444 assert_eq ! ( long_desc_res, Err ( CreationError :: DescriptionTooLong ) ) ;
14601445
1461- let route_hop = RouteHop {
1462- pubkey : PublicKey :: from_slice (
1446+ let route_hop = RouteHint {
1447+ src_node_id : PublicKey :: from_slice (
14631448 & [
14641449 0x03 , 0x9e , 0x03 , 0xa9 , 0x01 , 0xb8 , 0x55 , 0x34 , 0xff , 0x1e , 0x92 , 0xc4 ,
14651450 0x3c , 0x74 , 0x43 , 0x1f , 0x7c , 0xe7 , 0x20 , 0x46 , 0x06 , 0x0f , 0xcf , 0x7a ,
14661451 0x95 , 0xc3 , 0x7e , 0x14 , 0x8f , 0x78 , 0xc7 , 0x72 , 0x55
14671452 ] [ ..]
14681453 ) . unwrap ( ) ,
1469- short_channel_id : [ 0 ; 8 ] ,
1470- fee_base_msat : 0 ,
1471- fee_proportional_millionths : 0 ,
1454+ short_channel_id : 0 ,
1455+ fees : RoutingFees {
1456+ base_msat : 0 ,
1457+ proportional_millionths : 0 ,
1458+ } ,
14721459 cltv_expiry_delta : 0 ,
1460+ htlc_minimum_msat : None ,
1461+ htlc_maximum_msat : None ,
14731462 } ;
14741463 let too_long_route = vec ! [ route_hop; 13 ] ;
14751464 let long_route_res = builder. clone ( )
@@ -1505,36 +1494,52 @@ mod test {
15051494 let public_key = PublicKey :: from_secret_key ( & secp_ctx, & private_key) ;
15061495
15071496 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 ,
1497+ RouteHint {
1498+ src_node_id: public_key. clone( ) ,
1499+ short_channel_id: u64 :: from_be_bytes( [ 123 ; 8 ] ) ,
1500+ fees: RoutingFees {
1501+ base_msat: 2 ,
1502+ proportional_millionths: 1 ,
1503+ } ,
15131504 cltv_expiry_delta: 145 ,
1505+ htlc_minimum_msat: None ,
1506+ htlc_maximum_msat: None ,
15141507 } ,
1515- RouteHop {
1516- pubkey: public_key. clone( ) ,
1517- short_channel_id: [ 42 ; 8 ] ,
1518- fee_base_msat: 3 ,
1519- fee_proportional_millionths: 2 ,
1508+ RouteHint {
1509+ src_node_id: public_key. clone( ) ,
1510+ short_channel_id: u64 :: from_be_bytes( [ 42 ; 8 ] ) ,
1511+ fees: RoutingFees {
1512+ base_msat: 3 ,
1513+ proportional_millionths: 2 ,
1514+ } ,
15201515 cltv_expiry_delta: 146 ,
1516+ htlc_minimum_msat: None ,
1517+ htlc_maximum_msat: None ,
15211518 }
15221519 ] ;
15231520
15241521 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 ,
1522+ RouteHint {
1523+ src_node_id: public_key. clone( ) ,
1524+ short_channel_id: 0 ,
1525+ fees: RoutingFees {
1526+ base_msat: 4 ,
1527+ proportional_millionths: 3 ,
1528+ } ,
15301529 cltv_expiry_delta: 147 ,
1530+ htlc_minimum_msat: None ,
1531+ htlc_maximum_msat: None ,
15311532 } ,
1532- RouteHop {
1533- pubkey: public_key. clone( ) ,
1534- short_channel_id: [ 1 ; 8 ] ,
1535- fee_base_msat: 5 ,
1536- fee_proportional_millionths: 4 ,
1533+ RouteHint {
1534+ src_node_id: public_key. clone( ) ,
1535+ short_channel_id: u64 :: from_be_bytes( [ 1 ; 8 ] ) ,
1536+ fees: RoutingFees {
1537+ base_msat: 5 ,
1538+ proportional_millionths: 4 ,
1539+ } ,
15371540 cltv_expiry_delta: 148 ,
1541+ htlc_minimum_msat: None ,
1542+ htlc_maximum_msat: None ,
15381543 }
15391544 ] ;
15401545
0 commit comments