Skip to content

Commit a23a6ee

Browse files
committed
f - Rename Route to PrivateRoute in lightning-invoice
1 parent cfbd2a4 commit a23a6ee

File tree

4 files changed

+39
-39
lines changed

4 files changed

+39
-39
lines changed

lightning-invoice/src/de.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use secp256k1::recovery::{RecoveryId, RecoverableSignature};
2121
use secp256k1::key::PublicKey;
2222

2323
use super::{Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiry, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp,
24-
SemanticError, Route, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawInvoice, constants, SignedRawInvoice,
24+
SemanticError, PrivateRoute, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawInvoice, constants, SignedRawInvoice,
2525
RawDataPart, CreationError, InvoiceFeatures};
2626

2727
use self::hrp_sm::parse_hrp;
@@ -433,8 +433,8 @@ impl FromBase32 for TaggedField {
433433
Ok(TaggedField::MinFinalCltvExpiry(MinFinalCltvExpiry::from_base32(field_data)?)),
434434
constants::TAG_FALLBACK =>
435435
Ok(TaggedField::Fallback(Fallback::from_base32(field_data)?)),
436-
constants::TAG_ROUTE =>
437-
Ok(TaggedField::Route(Route::from_base32(field_data)?)),
436+
constants::TAG_PRIVATE_ROUTE =>
437+
Ok(TaggedField::PrivateRoute(PrivateRoute::from_base32(field_data)?)),
438438
constants::TAG_PAYMENT_SECRET =>
439439
Ok(TaggedField::PaymentSecret(PaymentSecret::from_base32(field_data)?)),
440440
constants::TAG_FEATURES =>
@@ -558,10 +558,10 @@ impl FromBase32 for Fallback {
558558
}
559559
}
560560

561-
impl FromBase32 for Route {
561+
impl FromBase32 for PrivateRoute {
562562
type Err = ParseError;
563563

564-
fn from_base32(field_data: &[u5]) -> Result<Route, ParseError> {
564+
fn from_base32(field_data: &[u5]) -> Result<PrivateRoute, ParseError> {
565565
let bytes = Vec::<u8>::from_base32(field_data)?;
566566

567567
if bytes.len() % 51 != 0 {
@@ -593,7 +593,7 @@ impl FromBase32 for Route {
593593
route_hops.push(hop);
594594
}
595595

596-
Ok(Route(RouteHint(route_hops)))
596+
Ok(PrivateRoute(RouteHint(route_hops)))
597597
}
598598
}
599599

@@ -931,7 +931,7 @@ mod test {
931931
fn test_parse_route() {
932932
use lightning::routing::network_graph::RoutingFees;
933933
use lightning::routing::router::{RouteHint, RouteHintHop};
934-
use ::Route;
934+
use ::PrivateRoute;
935935
use bech32::FromBase32;
936936
use de::parse_int_be;
937937

@@ -976,10 +976,10 @@ mod test {
976976
htlc_maximum_msat: None
977977
});
978978

979-
assert_eq!(Route::from_base32(&input), Ok(Route(RouteHint(expected))));
979+
assert_eq!(PrivateRoute::from_base32(&input), Ok(PrivateRoute(RouteHint(expected))));
980980

981981
assert_eq!(
982-
Route::from_base32(&[u5::try_from_u8(0).unwrap(); 40][..]),
982+
PrivateRoute::from_base32(&[u5::try_from_u8(0).unwrap(); 40][..]),
983983
Err(ParseError::UnexpectedEndOfTaggedFields)
984984
);
985985
}

lightning-invoice/src/lib.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ pub enum TaggedField {
362362
ExpiryTime(ExpiryTime),
363363
MinFinalCltvExpiry(MinFinalCltvExpiry),
364364
Fallback(Fallback),
365-
Route(Route),
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 Route(RouteHint);
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: RouteHint) -> Self {
513-
match Route::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
@@ -892,11 +892,11 @@ impl RawInvoice {
892892
}).collect::<Vec<&Fallback>>()
893893
}
894894

895-
pub fn routes(&self) -> Vec<&Route> {
895+
pub fn private_routes(&self) -> Vec<&PrivateRoute> {
896896
self.known_tagged_fields().filter_map(|tf| match tf {
897-
&TaggedField::Route(ref r) => Some(r),
897+
&TaggedField::PrivateRoute(ref r) => Some(r),
898898
_ => None,
899-
}).collect::<Vec<&Route>>()
899+
}).collect::<Vec<&PrivateRoute>>()
900900
}
901901

902902
pub fn amount_pico_btc(&self) -> Option<u64> {
@@ -1145,13 +1145,13 @@ impl Invoice {
11451145
}
11461146

11471147
/// Returns a list of all routes included in the invoice
1148-
pub fn routes(&self) -> Vec<&Route> {
1149-
self.signed_invoice.routes()
1148+
pub fn private_routes(&self) -> Vec<&PrivateRoute> {
1149+
self.signed_invoice.private_routes()
11501150
}
11511151

1152-
/// Returns a list of all routes included in the invoice as the underlying type
1152+
/// Returns a list of all routes included in the invoice as the underlying hints
11531153
pub fn route_hints(&self) -> Vec<&RouteHint> {
1154-
self.routes().into_iter().map(|route| &**route).collect()
1154+
self.private_routes().into_iter().map(|route| &**route).collect()
11551155
}
11561156

11571157
/// Returns the currency for which the invoice was issued
@@ -1182,7 +1182,7 @@ impl TaggedField {
11821182
TaggedField::ExpiryTime(_) => constants::TAG_EXPIRY_TIME,
11831183
TaggedField::MinFinalCltvExpiry(_) => constants::TAG_MIN_FINAL_CLTV_EXPIRY,
11841184
TaggedField::Fallback(_) => constants::TAG_FALLBACK,
1185-
TaggedField::Route(_) => constants::TAG_ROUTE,
1185+
TaggedField::PrivateRoute(_) => constants::TAG_PRIVATE_ROUTE,
11861186
TaggedField::PaymentSecret(_) => constants::TAG_PAYMENT_SECRET,
11871187
TaggedField::Features(_) => constants::TAG_FEATURES,
11881188
};
@@ -1273,11 +1273,11 @@ impl ExpiryTime {
12731273
}
12741274
}
12751275

1276-
impl Route {
1276+
impl PrivateRoute {
12771277
/// Creates a new (partial) route from a list of hops
1278-
pub fn new(hops: RouteHint) -> Result<Route, CreationError> {
1278+
pub fn new(hops: RouteHint) -> Result<PrivateRoute, CreationError> {
12791279
if hops.0.len() <= 12 {
1280-
Ok(Route(hops))
1280+
Ok(PrivateRoute(hops))
12811281
} else {
12821282
Err(CreationError::RouteTooLong)
12831283
}
@@ -1289,13 +1289,13 @@ impl Route {
12891289
}
12901290
}
12911291

1292-
impl Into<RouteHint> for Route {
1292+
impl Into<RouteHint> for PrivateRoute {
12931293
fn into(self) -> RouteHint {
12941294
self.into_inner()
12951295
}
12961296
}
12971297

1298-
impl Deref for Route {
1298+
impl Deref for PrivateRoute {
12991299
type Target = RouteHint;
13001300

13011301
fn deref(&self) -> &RouteHint {
@@ -1695,7 +1695,7 @@ mod test {
16951695
let too_long_route = RouteHint(vec![route_hop; 13]);
16961696
let long_route_res = builder.clone()
16971697
.description("Test".into())
1698-
.route(too_long_route)
1698+
.private_route(too_long_route)
16991699
.build_raw();
17001700
assert_eq!(long_route_res, Err(CreationError::RouteTooLong));
17011701

@@ -1783,8 +1783,8 @@ mod test {
17831783
.expiry_time(Duration::from_secs(54321))
17841784
.min_final_cltv_expiry(144)
17851785
.fallback(Fallback::PubKeyHash([0;20]))
1786-
.route(route_1.clone())
1787-
.route(route_2.clone())
1786+
.private_route(route_1.clone())
1787+
.private_route(route_2.clone())
17881788
.description_hash(sha256::Hash::from_slice(&[3;32][..]).unwrap())
17891789
.payment_hash(sha256::Hash::from_slice(&[21;32][..]).unwrap())
17901790
.payment_secret(PaymentSecret([42; 32]))
@@ -1807,7 +1807,7 @@ mod test {
18071807
assert_eq!(invoice.expiry_time(), Duration::from_secs(54321));
18081808
assert_eq!(invoice.min_final_cltv_expiry(), 144);
18091809
assert_eq!(invoice.fallbacks(), vec![&Fallback::PubKeyHash([0;20])]);
1810-
assert_eq!(invoice.routes(), vec![&Route(route_1), &Route(route_2)]);
1810+
assert_eq!(invoice.private_routes(), vec![&PrivateRoute(route_1), &PrivateRoute(route_2)]);
18111811
assert_eq!(
18121812
invoice.description(),
18131813
InvoiceDescription::Hash(&Sha256(sha256::Hash::from_slice(&[3;32][..]).unwrap()))

lightning-invoice/src/ser.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt::{Display, Formatter};
33
use bech32::{ToBase32, u5, WriteBase32, Base32Len};
44

55
use super::{Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiry, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp,
6-
Route, Description, RawTaggedField, Currency, RawHrp, SiPrefix, constants, SignedRawInvoice, RawDataPart};
6+
PrivateRoute, Description, RawTaggedField, Currency, RawHrp, SiPrefix, constants, SignedRawInvoice, RawDataPart};
77

88
/// Converts a stream of bytes written to it to base32. On finalization the according padding will
99
/// be applied. That means the results of writing two data blocks with one or two `BytesToBase32`
@@ -356,7 +356,7 @@ impl Base32Len for Fallback {
356356
}
357357
}
358358

359-
impl ToBase32 for Route {
359+
impl ToBase32 for PrivateRoute {
360360
fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
361361
let mut converter = BytesToBase32::new(writer);
362362

@@ -392,7 +392,7 @@ impl ToBase32 for Route {
392392
}
393393
}
394394

395-
impl Base32Len for Route {
395+
impl Base32Len for PrivateRoute {
396396
fn base32_len(&self) -> usize {
397397
bytes_size_to_base32_size((self.0).0.len() * 51)
398398
}
@@ -439,8 +439,8 @@ impl ToBase32 for TaggedField {
439439
TaggedField::Fallback(ref fallback_address) => {
440440
write_tagged_field(writer, constants::TAG_FALLBACK, fallback_address)
441441
},
442-
TaggedField::Route(ref route_hops) => {
443-
write_tagged_field(writer, constants::TAG_ROUTE, route_hops)
442+
TaggedField::PrivateRoute(ref route_hops) => {
443+
write_tagged_field(writer, constants::TAG_PRIVATE_ROUTE, route_hops)
444444
},
445445
TaggedField::PaymentSecret(ref payment_secret) => {
446446
write_tagged_field(writer, constants::TAG_PAYMENT_SECRET, payment_secret)

lightning-invoice/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ where
7070
if let Some(amt) = amt_msat {
7171
invoice = invoice.amount_pico_btc(amt * 10);
7272
}
73-
for hint in route_hints.drain(..) {
74-
invoice = invoice.route(hint);
73+
for hint in route_hints {
74+
invoice = invoice.private_route(hint);
7575
}
7676

7777
let raw_invoice = match invoice.build_raw() {

0 commit comments

Comments
 (0)