@@ -30,7 +30,7 @@ use lightning::ln::PaymentSecret;
3030use lightning:: ln:: features:: InvoiceFeatures ;
3131#[ cfg( any( doc, test) ) ]
3232use lightning:: routing:: network_graph:: RoutingFees ;
33- use lightning:: routing:: router:: RouteHintHop ;
33+ use lightning:: routing:: router:: RouteHint ;
3434
3535use secp256k1:: key:: PublicKey ;
3636use secp256k1:: { Message , Secp256k1 } ;
@@ -362,7 +362,7 @@ pub enum TaggedField {
362362 ExpiryTime ( ExpiryTime ) ,
363363 MinFinalCltvExpiry ( MinFinalCltvExpiry ) ,
364364 Fallback ( Fallback ) ,
365- Route ( RouteHint ) ,
365+ PrivateRoute ( PrivateRoute ) ,
366366 PaymentSecret ( PaymentSecret ) ,
367367 Features ( InvoiceFeatures ) ,
368368}
@@ -419,7 +419,7 @@ pub struct InvoiceSignature(pub RecoverableSignature);
419419/// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
420420///
421421#[ derive( Eq , PartialEq , Debug , Clone ) ]
422- pub struct RouteHint ( Vec < RouteHintHop > ) ;
422+ pub struct PrivateRoute ( RouteHint ) ;
423423
424424/// Tag constants as specified in BOLT11
425425#[ allow( missing_docs) ]
@@ -431,7 +431,7 @@ pub mod constants {
431431 pub const TAG_EXPIRY_TIME : u8 = 6 ;
432432 pub const TAG_MIN_FINAL_CLTV_EXPIRY : u8 = 24 ;
433433 pub const TAG_FALLBACK : u8 = 9 ;
434- pub const TAG_ROUTE : u8 = 3 ;
434+ pub const TAG_PRIVATE_ROUTE : u8 = 3 ;
435435 pub const TAG_PAYMENT_SECRET : u8 = 16 ;
436436 pub const TAG_FEATURES : u8 = 5 ;
437437}
@@ -509,9 +509,9 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool> InvoiceBui
509509 }
510510
511511 /// Adds a private route.
512- pub fn route ( mut self , route : Vec < RouteHintHop > ) -> Self {
513- match RouteHint :: new ( route ) {
514- Ok ( r) => self . tagged_fields . push ( TaggedField :: Route ( r) ) ,
512+ pub fn private_route ( mut self , hint : RouteHint ) -> Self {
513+ match PrivateRoute :: new ( hint ) {
514+ Ok ( r) => self . tagged_fields . push ( TaggedField :: PrivateRoute ( r) ) ,
515515 Err ( e) => self . error = Some ( e) ,
516516 }
517517 self
@@ -913,8 +913,8 @@ impl RawInvoice {
913913 find_all_extract ! ( self . known_tagged_fields( ) , TaggedField :: Fallback ( ref x) , x) . collect ( )
914914 }
915915
916- pub fn routes ( & self ) -> Vec < & RouteHint > {
917- find_all_extract ! ( self . known_tagged_fields( ) , TaggedField :: Route ( ref x) , x) . collect ( )
916+ pub fn private_routes ( & self ) -> Vec < & PrivateRoute > {
917+ find_all_extract ! ( self . known_tagged_fields( ) , TaggedField :: PrivateRoute ( ref x) , x) . collect ( )
918918 }
919919
920920 pub fn amount_pico_btc ( & self ) -> Option < u64 > {
@@ -1163,8 +1163,15 @@ impl Invoice {
11631163 }
11641164
11651165 /// Returns a list of all routes included in the invoice
1166- pub fn routes ( & self ) -> Vec < & RouteHint > {
1167- self . signed_invoice . routes ( )
1166+ pub fn private_routes ( & self ) -> Vec < & PrivateRoute > {
1167+ self . signed_invoice . private_routes ( )
1168+ }
1169+
1170+ /// Returns a list of all routes included in the invoice as the underlying hints
1171+ pub fn route_hints ( & self ) -> Vec < & RouteHint > {
1172+ find_all_extract ! (
1173+ self . signed_invoice. known_tagged_fields( ) , TaggedField :: PrivateRoute ( ref x) , x
1174+ ) . map ( |route| & * * route) . collect ( )
11681175 }
11691176
11701177 /// Returns the currency for which the invoice was issued
@@ -1195,7 +1202,7 @@ impl TaggedField {
11951202 TaggedField :: ExpiryTime ( _) => constants:: TAG_EXPIRY_TIME ,
11961203 TaggedField :: MinFinalCltvExpiry ( _) => constants:: TAG_MIN_FINAL_CLTV_EXPIRY ,
11971204 TaggedField :: Fallback ( _) => constants:: TAG_FALLBACK ,
1198- TaggedField :: Route ( _) => constants:: TAG_ROUTE ,
1205+ TaggedField :: PrivateRoute ( _) => constants:: TAG_PRIVATE_ROUTE ,
11991206 TaggedField :: PaymentSecret ( _) => constants:: TAG_PAYMENT_SECRET ,
12001207 TaggedField :: Features ( _) => constants:: TAG_FEATURES ,
12011208 } ;
@@ -1286,32 +1293,32 @@ impl ExpiryTime {
12861293 }
12871294}
12881295
1289- impl RouteHint {
1290- /// Create a new (partial) route from a list of hops
1291- pub fn new ( hops : Vec < RouteHintHop > ) -> Result < RouteHint , CreationError > {
1292- if hops. len ( ) <= 12 {
1293- Ok ( RouteHint ( hops) )
1296+ impl PrivateRoute {
1297+ /// Creates a new (partial) route from a list of hops
1298+ pub fn new ( hops : RouteHint ) -> Result < PrivateRoute , CreationError > {
1299+ if hops. 0 . len ( ) <= 12 {
1300+ Ok ( PrivateRoute ( hops) )
12941301 } else {
12951302 Err ( CreationError :: RouteTooLong )
12961303 }
12971304 }
12981305
1299- /// Returrn the underlying vector of hops
1300- pub fn into_inner ( self ) -> Vec < RouteHintHop > {
1306+ /// Returns the underlying list of hops
1307+ pub fn into_inner ( self ) -> RouteHint {
13011308 self . 0
13021309 }
13031310}
13041311
1305- impl Into < Vec < RouteHintHop > > for RouteHint {
1306- fn into ( self ) -> Vec < RouteHintHop > {
1312+ impl Into < RouteHint > for PrivateRoute {
1313+ fn into ( self ) -> RouteHint {
13071314 self . into_inner ( )
13081315 }
13091316}
13101317
1311- impl Deref for RouteHint {
1312- type Target = Vec < RouteHintHop > ;
1318+ impl Deref for PrivateRoute {
1319+ type Target = RouteHint ;
13131320
1314- fn deref ( & self ) -> & Vec < RouteHintHop > {
1321+ fn deref ( & self ) -> & RouteHint {
13151322 & self . 0
13161323 }
13171324}
@@ -1670,6 +1677,7 @@ mod test {
16701677 #[ test]
16711678 fn test_builder_fail ( ) {
16721679 use :: * ;
1680+ use lightning:: routing:: router:: RouteHintHop ;
16731681 use std:: iter:: FromIterator ;
16741682 use secp256k1:: key:: PublicKey ;
16751683
@@ -1704,10 +1712,10 @@ mod test {
17041712 htlc_minimum_msat : None ,
17051713 htlc_maximum_msat : None ,
17061714 } ;
1707- let too_long_route = vec ! [ route_hop; 13 ] ;
1715+ let too_long_route = RouteHint ( vec ! [ route_hop; 13 ] ) ;
17081716 let long_route_res = builder. clone ( )
17091717 . description ( "Test" . into ( ) )
1710- . route ( too_long_route)
1718+ . private_route ( too_long_route)
17111719 . build_raw ( ) ;
17121720 assert_eq ! ( long_route_res, Err ( CreationError :: RouteTooLong ) ) ;
17131721
@@ -1722,6 +1730,7 @@ mod test {
17221730 #[ test]
17231731 fn test_builder_ok ( ) {
17241732 use :: * ;
1733+ use lightning:: routing:: router:: RouteHintHop ;
17251734 use secp256k1:: Secp256k1 ;
17261735 use secp256k1:: key:: { SecretKey , PublicKey } ;
17271736 use std:: time:: { UNIX_EPOCH , Duration } ;
@@ -1737,7 +1746,7 @@ mod test {
17371746 ) . unwrap ( ) ;
17381747 let public_key = PublicKey :: from_secret_key ( & secp_ctx, & private_key) ;
17391748
1740- let route_1 = vec ! [
1749+ let route_1 = RouteHint ( vec ! [
17411750 RouteHintHop {
17421751 src_node_id: public_key. clone( ) ,
17431752 short_channel_id: de:: parse_int_be( & [ 123 ; 8 ] , 256 ) . expect( "short chan ID slice too big?" ) ,
@@ -1760,9 +1769,9 @@ mod test {
17601769 htlc_minimum_msat: None ,
17611770 htlc_maximum_msat: None ,
17621771 }
1763- ] ;
1772+ ] ) ;
17641773
1765- let route_2 = vec ! [
1774+ let route_2 = RouteHint ( vec ! [
17661775 RouteHintHop {
17671776 src_node_id: public_key. clone( ) ,
17681777 short_channel_id: 0 ,
@@ -1785,7 +1794,7 @@ mod test {
17851794 htlc_minimum_msat: None ,
17861795 htlc_maximum_msat: None ,
17871796 }
1788- ] ;
1797+ ] ) ;
17891798
17901799 let builder = InvoiceBuilder :: new ( Currency :: BitcoinTestnet )
17911800 . amount_pico_btc ( 123 )
@@ -1794,8 +1803,8 @@ mod test {
17941803 . expiry_time ( Duration :: from_secs ( 54321 ) )
17951804 . min_final_cltv_expiry ( 144 )
17961805 . fallback ( Fallback :: PubKeyHash ( [ 0 ; 20 ] ) )
1797- . route ( route_1. clone ( ) )
1798- . route ( route_2. clone ( ) )
1806+ . private_route ( route_1. clone ( ) )
1807+ . private_route ( route_2. clone ( ) )
17991808 . description_hash ( sha256:: Hash :: from_slice ( & [ 3 ; 32 ] [ ..] ) . unwrap ( ) )
18001809 . payment_hash ( sha256:: Hash :: from_slice ( & [ 21 ; 32 ] [ ..] ) . unwrap ( ) )
18011810 . payment_secret ( PaymentSecret ( [ 42 ; 32 ] ) )
@@ -1818,7 +1827,7 @@ mod test {
18181827 assert_eq ! ( invoice. expiry_time( ) , Duration :: from_secs( 54321 ) ) ;
18191828 assert_eq ! ( invoice. min_final_cltv_expiry( ) , 144 ) ;
18201829 assert_eq ! ( invoice. fallbacks( ) , vec![ & Fallback :: PubKeyHash ( [ 0 ; 20 ] ) ] ) ;
1821- assert_eq ! ( invoice. routes ( ) , vec![ & RouteHint ( route_1) , & RouteHint ( route_2) ] ) ;
1830+ assert_eq ! ( invoice. private_routes ( ) , vec![ & PrivateRoute ( route_1) , & PrivateRoute ( route_2) ] ) ;
18221831 assert_eq ! (
18231832 invoice. description( ) ,
18241833 InvoiceDescription :: Hash ( & Sha256 ( sha256:: Hash :: from_slice( & [ 3 ; 32 ] [ ..] ) . unwrap( ) ) )
0 commit comments