@@ -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+ Route ( Route ) ,
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 Route ( RouteHint ) ;
423423
424424/// Tag constants as specified in BOLT11
425425#[ allow( missing_docs) ]
@@ -509,8 +509,8 @@ 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) {
512+ pub fn route ( mut self , route : RouteHint ) -> Self {
513+ match Route :: new ( route) {
514514 Ok ( r) => self . tagged_fields . push ( TaggedField :: Route ( r) ) ,
515515 Err ( e) => self . error = Some ( e) ,
516516 }
@@ -892,11 +892,11 @@ impl RawInvoice {
892892 } ) . collect :: < Vec < & Fallback > > ( )
893893 }
894894
895- pub fn routes ( & self ) -> Vec < & RouteHint > {
895+ pub fn routes ( & self ) -> Vec < & Route > {
896896 self . known_tagged_fields ( ) . filter_map ( |tf| match tf {
897897 & TaggedField :: Route ( ref r) => Some ( r) ,
898898 _ => None ,
899- } ) . collect :: < Vec < & RouteHint > > ( )
899+ } ) . collect :: < Vec < & Route > > ( )
900900 }
901901
902902 pub fn amount_pico_btc ( & self ) -> Option < u64 > {
@@ -1145,10 +1145,15 @@ impl Invoice {
11451145 }
11461146
11471147 /// Returns a list of all routes included in the invoice
1148- pub fn routes ( & self ) -> Vec < & RouteHint > {
1148+ pub fn routes ( & self ) -> Vec < & Route > {
11491149 self . signed_invoice . routes ( )
11501150 }
11511151
1152+ /// Returns a list of all routes included in the invoice as the underlying type
1153+ pub fn route_hints ( & self ) -> Vec < & RouteHint > {
1154+ self . routes ( ) . into_iter ( ) . map ( |route| & * * route) . collect ( )
1155+ }
1156+
11521157 /// Returns the currency for which the invoice was issued
11531158 pub fn currency ( & self ) -> Currency {
11541159 self . signed_invoice . currency ( )
@@ -1268,32 +1273,32 @@ impl ExpiryTime {
12681273 }
12691274}
12701275
1271- impl RouteHint {
1272- /// Create a new (partial) route from a list of hops
1273- pub fn new ( hops : Vec < RouteHintHop > ) -> Result < RouteHint , CreationError > {
1274- if hops. len ( ) <= 12 {
1275- Ok ( RouteHint ( hops) )
1276+ impl Route {
1277+ /// Creates a new (partial) route from a list of hops
1278+ pub fn new ( hops : RouteHint ) -> Result < Route , CreationError > {
1279+ if hops. 0 . len ( ) <= 12 {
1280+ Ok ( Route ( hops) )
12761281 } else {
12771282 Err ( CreationError :: RouteTooLong )
12781283 }
12791284 }
12801285
1281- /// Returrn the underlying vector of hops
1282- pub fn into_inner ( self ) -> Vec < RouteHintHop > {
1286+ /// Returns the underlying list of hops
1287+ pub fn into_inner ( self ) -> RouteHint {
12831288 self . 0
12841289 }
12851290}
12861291
1287- impl Into < Vec < RouteHintHop > > for RouteHint {
1288- fn into ( self ) -> Vec < RouteHintHop > {
1292+ impl Into < RouteHint > for Route {
1293+ fn into ( self ) -> RouteHint {
12891294 self . into_inner ( )
12901295 }
12911296}
12921297
1293- impl Deref for RouteHint {
1294- type Target = Vec < RouteHintHop > ;
1298+ impl Deref for Route {
1299+ type Target = RouteHint ;
12951300
1296- fn deref ( & self ) -> & Vec < RouteHintHop > {
1301+ fn deref ( & self ) -> & RouteHint {
12971302 & self . 0
12981303 }
12991304}
@@ -1652,6 +1657,7 @@ mod test {
16521657 #[ test]
16531658 fn test_builder_fail ( ) {
16541659 use :: * ;
1660+ use lightning:: routing:: router:: RouteHintHop ;
16551661 use std:: iter:: FromIterator ;
16561662 use secp256k1:: key:: PublicKey ;
16571663
@@ -1686,7 +1692,7 @@ mod test {
16861692 htlc_minimum_msat : None ,
16871693 htlc_maximum_msat : None ,
16881694 } ;
1689- let too_long_route = vec ! [ route_hop; 13 ] ;
1695+ let too_long_route = RouteHint ( vec ! [ route_hop; 13 ] ) ;
16901696 let long_route_res = builder. clone ( )
16911697 . description ( "Test" . into ( ) )
16921698 . route ( too_long_route)
@@ -1704,6 +1710,7 @@ mod test {
17041710 #[ test]
17051711 fn test_builder_ok ( ) {
17061712 use :: * ;
1713+ use lightning:: routing:: router:: RouteHintHop ;
17071714 use secp256k1:: Secp256k1 ;
17081715 use secp256k1:: key:: { SecretKey , PublicKey } ;
17091716 use std:: time:: { UNIX_EPOCH , Duration } ;
@@ -1719,7 +1726,7 @@ mod test {
17191726 ) . unwrap ( ) ;
17201727 let public_key = PublicKey :: from_secret_key ( & secp_ctx, & private_key) ;
17211728
1722- let route_1 = vec ! [
1729+ let route_1 = RouteHint ( vec ! [
17231730 RouteHintHop {
17241731 src_node_id: public_key. clone( ) ,
17251732 short_channel_id: de:: parse_int_be( & [ 123 ; 8 ] , 256 ) . expect( "short chan ID slice too big?" ) ,
@@ -1742,9 +1749,9 @@ mod test {
17421749 htlc_minimum_msat: None ,
17431750 htlc_maximum_msat: None ,
17441751 }
1745- ] ;
1752+ ] ) ;
17461753
1747- let route_2 = vec ! [
1754+ let route_2 = RouteHint ( vec ! [
17481755 RouteHintHop {
17491756 src_node_id: public_key. clone( ) ,
17501757 short_channel_id: 0 ,
@@ -1767,7 +1774,7 @@ mod test {
17671774 htlc_minimum_msat: None ,
17681775 htlc_maximum_msat: None ,
17691776 }
1770- ] ;
1777+ ] ) ;
17711778
17721779 let builder = InvoiceBuilder :: new ( Currency :: BitcoinTestnet )
17731780 . amount_pico_btc ( 123 )
@@ -1800,7 +1807,7 @@ mod test {
18001807 assert_eq ! ( invoice. expiry_time( ) , Duration :: from_secs( 54321 ) ) ;
18011808 assert_eq ! ( invoice. min_final_cltv_expiry( ) , 144 ) ;
18021809 assert_eq ! ( invoice. fallbacks( ) , vec![ & Fallback :: PubKeyHash ( [ 0 ; 20 ] ) ] ) ;
1803- assert_eq ! ( invoice. routes( ) , vec![ & RouteHint ( route_1) , & RouteHint ( route_2) ] ) ;
1810+ assert_eq ! ( invoice. routes( ) , vec![ & Route ( route_1) , & Route ( route_2) ] ) ;
18041811 assert_eq ! (
18051812 invoice. description( ) ,
18061813 InvoiceDescription :: Hash ( & Sha256 ( sha256:: Hash :: from_slice( & [ 3 ; 32 ] [ ..] ) . unwrap( ) ) )
0 commit comments