@@ -30,7 +30,7 @@ use lightning::ln::PaymentSecret;
30
30
use lightning:: ln:: features:: InvoiceFeatures ;
31
31
#[ cfg( any( doc, test) ) ]
32
32
use lightning:: routing:: network_graph:: RoutingFees ;
33
- use lightning:: routing:: router:: RouteHintHop ;
33
+ use lightning:: routing:: router:: RouteHint ;
34
34
35
35
use secp256k1:: key:: PublicKey ;
36
36
use secp256k1:: { Message , Secp256k1 } ;
@@ -362,7 +362,7 @@ pub enum TaggedField {
362
362
ExpiryTime ( ExpiryTime ) ,
363
363
MinFinalCltvExpiry ( MinFinalCltvExpiry ) ,
364
364
Fallback ( Fallback ) ,
365
- Route ( RouteHint ) ,
365
+ PrivateRoute ( PrivateRoute ) ,
366
366
PaymentSecret ( PaymentSecret ) ,
367
367
Features ( InvoiceFeatures ) ,
368
368
}
@@ -419,7 +419,7 @@ pub struct InvoiceSignature(pub RecoverableSignature);
419
419
/// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
420
420
///
421
421
#[ derive( Eq , PartialEq , Debug , Clone ) ]
422
- pub struct RouteHint ( Vec < RouteHintHop > ) ;
422
+ pub struct PrivateRoute ( RouteHint ) ;
423
423
424
424
/// Tag constants as specified in BOLT11
425
425
#[ allow( missing_docs) ]
@@ -431,7 +431,7 @@ pub mod constants {
431
431
pub const TAG_EXPIRY_TIME : u8 = 6 ;
432
432
pub const TAG_MIN_FINAL_CLTV_EXPIRY : u8 = 24 ;
433
433
pub const TAG_FALLBACK : u8 = 9 ;
434
- pub const TAG_ROUTE : u8 = 3 ;
434
+ pub const TAG_PRIVATE_ROUTE : u8 = 3 ;
435
435
pub const TAG_PAYMENT_SECRET : u8 = 16 ;
436
436
pub const TAG_FEATURES : u8 = 5 ;
437
437
}
@@ -509,9 +509,9 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool> InvoiceBui
509
509
}
510
510
511
511
/// 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) ) ,
515
515
Err ( e) => self . error = Some ( e) ,
516
516
}
517
517
self
@@ -913,8 +913,8 @@ impl RawInvoice {
913
913
find_all_extract ! ( self . known_tagged_fields( ) , TaggedField :: Fallback ( ref x) , x) . collect ( )
914
914
}
915
915
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 ( )
918
918
}
919
919
920
920
pub fn amount_pico_btc ( & self ) -> Option < u64 > {
@@ -1163,8 +1163,15 @@ impl Invoice {
1163
1163
}
1164
1164
1165
1165
/// 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 ( )
1168
1175
}
1169
1176
1170
1177
/// Returns the currency for which the invoice was issued
@@ -1195,7 +1202,7 @@ impl TaggedField {
1195
1202
TaggedField :: ExpiryTime ( _) => constants:: TAG_EXPIRY_TIME ,
1196
1203
TaggedField :: MinFinalCltvExpiry ( _) => constants:: TAG_MIN_FINAL_CLTV_EXPIRY ,
1197
1204
TaggedField :: Fallback ( _) => constants:: TAG_FALLBACK ,
1198
- TaggedField :: Route ( _) => constants:: TAG_ROUTE ,
1205
+ TaggedField :: PrivateRoute ( _) => constants:: TAG_PRIVATE_ROUTE ,
1199
1206
TaggedField :: PaymentSecret ( _) => constants:: TAG_PAYMENT_SECRET ,
1200
1207
TaggedField :: Features ( _) => constants:: TAG_FEATURES ,
1201
1208
} ;
@@ -1286,32 +1293,32 @@ impl ExpiryTime {
1286
1293
}
1287
1294
}
1288
1295
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) )
1294
1301
} else {
1295
1302
Err ( CreationError :: RouteTooLong )
1296
1303
}
1297
1304
}
1298
1305
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 {
1301
1308
self . 0
1302
1309
}
1303
1310
}
1304
1311
1305
- impl Into < Vec < RouteHintHop > > for RouteHint {
1306
- fn into ( self ) -> Vec < RouteHintHop > {
1312
+ impl Into < RouteHint > for PrivateRoute {
1313
+ fn into ( self ) -> RouteHint {
1307
1314
self . into_inner ( )
1308
1315
}
1309
1316
}
1310
1317
1311
- impl Deref for RouteHint {
1312
- type Target = Vec < RouteHintHop > ;
1318
+ impl Deref for PrivateRoute {
1319
+ type Target = RouteHint ;
1313
1320
1314
- fn deref ( & self ) -> & Vec < RouteHintHop > {
1321
+ fn deref ( & self ) -> & RouteHint {
1315
1322
& self . 0
1316
1323
}
1317
1324
}
@@ -1670,6 +1677,7 @@ mod test {
1670
1677
#[ test]
1671
1678
fn test_builder_fail ( ) {
1672
1679
use :: * ;
1680
+ use lightning:: routing:: router:: RouteHintHop ;
1673
1681
use std:: iter:: FromIterator ;
1674
1682
use secp256k1:: key:: PublicKey ;
1675
1683
@@ -1704,10 +1712,10 @@ mod test {
1704
1712
htlc_minimum_msat : None ,
1705
1713
htlc_maximum_msat : None ,
1706
1714
} ;
1707
- let too_long_route = vec ! [ route_hop; 13 ] ;
1715
+ let too_long_route = RouteHint ( vec ! [ route_hop; 13 ] ) ;
1708
1716
let long_route_res = builder. clone ( )
1709
1717
. description ( "Test" . into ( ) )
1710
- . route ( too_long_route)
1718
+ . private_route ( too_long_route)
1711
1719
. build_raw ( ) ;
1712
1720
assert_eq ! ( long_route_res, Err ( CreationError :: RouteTooLong ) ) ;
1713
1721
@@ -1722,6 +1730,7 @@ mod test {
1722
1730
#[ test]
1723
1731
fn test_builder_ok ( ) {
1724
1732
use :: * ;
1733
+ use lightning:: routing:: router:: RouteHintHop ;
1725
1734
use secp256k1:: Secp256k1 ;
1726
1735
use secp256k1:: key:: { SecretKey , PublicKey } ;
1727
1736
use std:: time:: { UNIX_EPOCH , Duration } ;
@@ -1737,7 +1746,7 @@ mod test {
1737
1746
) . unwrap ( ) ;
1738
1747
let public_key = PublicKey :: from_secret_key ( & secp_ctx, & private_key) ;
1739
1748
1740
- let route_1 = vec ! [
1749
+ let route_1 = RouteHint ( vec ! [
1741
1750
RouteHintHop {
1742
1751
src_node_id: public_key. clone( ) ,
1743
1752
short_channel_id: de:: parse_int_be( & [ 123 ; 8 ] , 256 ) . expect( "short chan ID slice too big?" ) ,
@@ -1760,9 +1769,9 @@ mod test {
1760
1769
htlc_minimum_msat: None ,
1761
1770
htlc_maximum_msat: None ,
1762
1771
}
1763
- ] ;
1772
+ ] ) ;
1764
1773
1765
- let route_2 = vec ! [
1774
+ let route_2 = RouteHint ( vec ! [
1766
1775
RouteHintHop {
1767
1776
src_node_id: public_key. clone( ) ,
1768
1777
short_channel_id: 0 ,
@@ -1785,7 +1794,7 @@ mod test {
1785
1794
htlc_minimum_msat: None ,
1786
1795
htlc_maximum_msat: None ,
1787
1796
}
1788
- ] ;
1797
+ ] ) ;
1789
1798
1790
1799
let builder = InvoiceBuilder :: new ( Currency :: BitcoinTestnet )
1791
1800
. amount_pico_btc ( 123 )
@@ -1794,8 +1803,8 @@ mod test {
1794
1803
. expiry_time ( Duration :: from_secs ( 54321 ) )
1795
1804
. min_final_cltv_expiry ( 144 )
1796
1805
. 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 ( ) )
1799
1808
. description_hash ( sha256:: Hash :: from_slice ( & [ 3 ; 32 ] [ ..] ) . unwrap ( ) )
1800
1809
. payment_hash ( sha256:: Hash :: from_slice ( & [ 21 ; 32 ] [ ..] ) . unwrap ( ) )
1801
1810
. payment_secret ( PaymentSecret ( [ 42 ; 32 ] ) )
@@ -1818,7 +1827,7 @@ mod test {
1818
1827
assert_eq ! ( invoice. expiry_time( ) , Duration :: from_secs( 54321 ) ) ;
1819
1828
assert_eq ! ( invoice. min_final_cltv_expiry( ) , 144 ) ;
1820
1829
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) ] ) ;
1822
1831
assert_eq ! (
1823
1832
invoice. description( ) ,
1824
1833
InvoiceDescription :: Hash ( & Sha256 ( sha256:: Hash :: from_slice( & [ 3 ; 32 ] [ ..] ) . unwrap( ) ) )
0 commit comments