@@ -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
+ Route ( Route ) ,
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 Route ( RouteHint ) ;
423
423
424
424
/// Tag constants as specified in BOLT11
425
425
#[ allow( missing_docs) ]
@@ -509,8 +509,8 @@ 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) {
512
+ pub fn route ( mut self , route : RouteHint ) -> Self {
513
+ match Route :: new ( route) {
514
514
Ok ( r) => self . tagged_fields . push ( TaggedField :: Route ( r) ) ,
515
515
Err ( e) => self . error = Some ( e) ,
516
516
}
@@ -892,11 +892,11 @@ impl RawInvoice {
892
892
} ) . collect :: < Vec < & Fallback > > ( )
893
893
}
894
894
895
- pub fn routes ( & self ) -> Vec < & RouteHint > {
895
+ pub fn routes ( & self ) -> Vec < & Route > {
896
896
self . known_tagged_fields ( ) . filter_map ( |tf| match tf {
897
897
& TaggedField :: Route ( ref r) => Some ( r) ,
898
898
_ => None ,
899
- } ) . collect :: < Vec < & RouteHint > > ( )
899
+ } ) . collect :: < Vec < & Route > > ( )
900
900
}
901
901
902
902
pub fn amount_pico_btc ( & self ) -> Option < u64 > {
@@ -1145,10 +1145,15 @@ impl Invoice {
1145
1145
}
1146
1146
1147
1147
/// Returns a list of all routes included in the invoice
1148
- pub fn routes ( & self ) -> Vec < & RouteHint > {
1148
+ pub fn routes ( & self ) -> Vec < & Route > {
1149
1149
self . signed_invoice . routes ( )
1150
1150
}
1151
1151
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
+
1152
1157
/// Returns the currency for which the invoice was issued
1153
1158
pub fn currency ( & self ) -> Currency {
1154
1159
self . signed_invoice . currency ( )
@@ -1268,32 +1273,32 @@ impl ExpiryTime {
1268
1273
}
1269
1274
}
1270
1275
1271
- impl RouteHint {
1276
+ impl Route {
1272
1277
/// 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) )
1278
+ pub fn new ( hops : RouteHint ) -> Result < Route , CreationError > {
1279
+ if hops. 0 . len ( ) <= 12 {
1280
+ Ok ( Route ( hops) )
1276
1281
} else {
1277
1282
Err ( CreationError :: RouteTooLong )
1278
1283
}
1279
1284
}
1280
1285
1281
1286
/// Returrn the underlying vector of hops
1282
- pub fn into_inner ( self ) -> Vec < RouteHintHop > {
1287
+ pub fn into_inner ( self ) -> RouteHint {
1283
1288
self . 0
1284
1289
}
1285
1290
}
1286
1291
1287
- impl Into < Vec < RouteHintHop > > for RouteHint {
1288
- fn into ( self ) -> Vec < RouteHintHop > {
1292
+ impl Into < RouteHint > for Route {
1293
+ fn into ( self ) -> RouteHint {
1289
1294
self . into_inner ( )
1290
1295
}
1291
1296
}
1292
1297
1293
- impl Deref for RouteHint {
1294
- type Target = Vec < RouteHintHop > ;
1298
+ impl Deref for Route {
1299
+ type Target = RouteHint ;
1295
1300
1296
- fn deref ( & self ) -> & Vec < RouteHintHop > {
1301
+ fn deref ( & self ) -> & RouteHint {
1297
1302
& self . 0
1298
1303
}
1299
1304
}
@@ -1652,6 +1657,7 @@ mod test {
1652
1657
#[ test]
1653
1658
fn test_builder_fail ( ) {
1654
1659
use :: * ;
1660
+ use lightning:: routing:: router:: RouteHintHop ;
1655
1661
use std:: iter:: FromIterator ;
1656
1662
use secp256k1:: key:: PublicKey ;
1657
1663
@@ -1686,7 +1692,7 @@ mod test {
1686
1692
htlc_minimum_msat : None ,
1687
1693
htlc_maximum_msat : None ,
1688
1694
} ;
1689
- let too_long_route = vec ! [ route_hop; 13 ] ;
1695
+ let too_long_route = RouteHint ( vec ! [ route_hop; 13 ] ) ;
1690
1696
let long_route_res = builder. clone ( )
1691
1697
. description ( "Test" . into ( ) )
1692
1698
. route ( too_long_route)
@@ -1704,6 +1710,7 @@ mod test {
1704
1710
#[ test]
1705
1711
fn test_builder_ok ( ) {
1706
1712
use :: * ;
1713
+ use lightning:: routing:: router:: RouteHintHop ;
1707
1714
use secp256k1:: Secp256k1 ;
1708
1715
use secp256k1:: key:: { SecretKey , PublicKey } ;
1709
1716
use std:: time:: { UNIX_EPOCH , Duration } ;
@@ -1719,7 +1726,7 @@ mod test {
1719
1726
) . unwrap ( ) ;
1720
1727
let public_key = PublicKey :: from_secret_key ( & secp_ctx, & private_key) ;
1721
1728
1722
- let route_1 = vec ! [
1729
+ let route_1 = RouteHint ( vec ! [
1723
1730
RouteHintHop {
1724
1731
src_node_id: public_key. clone( ) ,
1725
1732
short_channel_id: de:: parse_int_be( & [ 123 ; 8 ] , 256 ) . expect( "short chan ID slice too big?" ) ,
@@ -1742,9 +1749,9 @@ mod test {
1742
1749
htlc_minimum_msat: None ,
1743
1750
htlc_maximum_msat: None ,
1744
1751
}
1745
- ] ;
1752
+ ] ) ;
1746
1753
1747
- let route_2 = vec ! [
1754
+ let route_2 = RouteHint ( vec ! [
1748
1755
RouteHintHop {
1749
1756
src_node_id: public_key. clone( ) ,
1750
1757
short_channel_id: 0 ,
@@ -1767,7 +1774,7 @@ mod test {
1767
1774
htlc_minimum_msat: None ,
1768
1775
htlc_maximum_msat: None ,
1769
1776
}
1770
- ] ;
1777
+ ] ) ;
1771
1778
1772
1779
let builder = InvoiceBuilder :: new ( Currency :: BitcoinTestnet )
1773
1780
. amount_pico_btc ( 123 )
@@ -1800,7 +1807,7 @@ mod test {
1800
1807
assert_eq ! ( invoice. expiry_time( ) , Duration :: from_secs( 54321 ) ) ;
1801
1808
assert_eq ! ( invoice. min_final_cltv_expiry( ) , 144 ) ;
1802
1809
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) ] ) ;
1804
1811
assert_eq ! (
1805
1812
invoice. description( ) ,
1806
1813
InvoiceDescription :: Hash ( & Sha256 ( sha256:: Hash :: from_slice( & [ 3 ; 32 ] [ ..] ) . unwrap( ) ) )
0 commit comments