From: Valentine Wallace Date: Mon, 19 Apr 2021 22:22:21 +0000 (-0400) Subject: invoice: rename Route to RouteHint (which is more accurate) X-Git-Tag: v0.0.14~20^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=a62a71cb5253b7594df476fa36d09887ebc5f8b9;p=rust-lightning invoice: rename Route to RouteHint (which is more accurate) --- diff --git a/lightning-invoice/src/de.rs b/lightning-invoice/src/de.rs index 17bbaf44d..fe77a93a9 100644 --- a/lightning-invoice/src/de.rs +++ b/lightning-invoice/src/de.rs @@ -430,7 +430,7 @@ impl FromBase32 for TaggedField { constants::TAG_FALLBACK => Ok(TaggedField::Fallback(Fallback::from_base32(field_data)?)), constants::TAG_ROUTE => - Ok(TaggedField::Route(Route::from_base32(field_data)?)), + Ok(TaggedField::Route(RouteHint::from_base32(field_data)?)), constants::TAG_PAYMENT_SECRET => Ok(TaggedField::PaymentSecret(PaymentSecret::from_base32(field_data)?)), _ => { @@ -567,10 +567,10 @@ impl FromBase32 for Fallback { } } -impl FromBase32 for Route { +impl FromBase32 for RouteHint { type Err = ParseError; - fn from_base32(field_data: &[u5]) -> Result { + fn from_base32(field_data: &[u5]) -> Result { let bytes = Vec::::from_base32(field_data)?; if bytes.len() % 51 != 0 { @@ -602,7 +602,7 @@ impl FromBase32 for Route { route_hops.push(hop); } - Ok(Route(route_hops)) + Ok(RouteHint(route_hops)) } } @@ -939,7 +939,7 @@ mod test { fn test_parse_route() { use lightning::routing::network_graph::RoutingFees; use lightning::routing::router::RouteHintHop; - use ::Route; + use ::RouteHint; use bech32::FromBase32; use de::parse_int_be; @@ -984,10 +984,10 @@ mod test { htlc_maximum_msat: None }); - assert_eq!(Route::from_base32(&input), Ok(Route(expected))); + assert_eq!(RouteHint::from_base32(&input), Ok(RouteHint(expected))); assert_eq!( - Route::from_base32(&[u5::try_from_u8(0).unwrap(); 40][..]), + RouteHint::from_base32(&[u5::try_from_u8(0).unwrap(); 40][..]), Err(ParseError::UnexpectedEndOfTaggedFields) ); } diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index cdb293d1f..2ce022248 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -327,7 +327,7 @@ pub enum TaggedField { ExpiryTime(ExpiryTime), MinFinalCltvExpiry(MinFinalCltvExpiry), Fallback(Fallback), - Route(Route), + Route(RouteHint), PaymentSecret(PaymentSecret), } @@ -387,7 +387,7 @@ pub struct Signature(pub RecoverableSignature); /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops) /// #[derive(Eq, PartialEq, Debug, Clone)] -pub struct Route(Vec); +pub struct RouteHint(Vec); /// Tag constants as specified in BOLT11 #[allow(missing_docs)] @@ -485,7 +485,7 @@ impl InvoiceBuilder { /// Adds a private route. pub fn route(mut self, route: Vec) -> Self { - match Route::new(route) { + match RouteHint::new(route) { Ok(r) => self.tagged_fields.push(TaggedField::Route(r)), Err(e) => self.error = Some(e), } @@ -817,11 +817,11 @@ impl RawInvoice { }).collect::>() } - pub fn routes(&self) -> Vec<&Route> { + pub fn routes(&self) -> Vec<&RouteHint> { self.known_tagged_fields().filter_map(|tf| match tf { &TaggedField::Route(ref r) => Some(r), _ => None, - }).collect::>() + }).collect::>() } pub fn amount_pico_btc(&self) -> Option { @@ -1020,7 +1020,7 @@ impl Invoice { } /// Returns a list of all routes included in the invoice - pub fn routes(&self) -> Vec<&Route> { + pub fn routes(&self) -> Vec<&RouteHint> { self.signed_invoice.routes() } @@ -1142,11 +1142,11 @@ impl ExpiryTime { } } -impl Route { +impl RouteHint { /// Create a new (partial) route from a list of hops - pub fn new(hops: Vec) -> Result { + pub fn new(hops: Vec) -> Result { if hops.len() <= 12 { - Ok(Route(hops)) + Ok(RouteHint(hops)) } else { Err(CreationError::RouteTooLong) } @@ -1158,13 +1158,13 @@ impl Route { } } -impl Into> for Route { +impl Into> for RouteHint { fn into(self) -> Vec { self.into_inner() } } -impl Deref for Route { +impl Deref for RouteHint { type Target = Vec; fn deref(&self) -> &Vec { @@ -1573,7 +1573,7 @@ mod test { assert_eq!(invoice.expiry_time(), Duration::from_secs(54321)); assert_eq!(invoice.min_final_cltv_expiry(), Some(&144)); assert_eq!(invoice.fallbacks(), vec![&Fallback::PubKeyHash([0;20])]); - assert_eq!(invoice.routes(), vec![&Route(route_1), &Route(route_2)]); + assert_eq!(invoice.routes(), vec![&RouteHint(route_1), &RouteHint(route_2)]); assert_eq!( invoice.description(), InvoiceDescription::Hash(&Sha256(sha256::Hash::from_slice(&[3;32][..]).unwrap())) diff --git a/lightning-invoice/src/ser.rs b/lightning-invoice/src/ser.rs index 68fbfcf12..83888e826 100644 --- a/lightning-invoice/src/ser.rs +++ b/lightning-invoice/src/ser.rs @@ -365,7 +365,7 @@ impl Base32Len for Fallback { } } -impl ToBase32 for Route { +impl ToBase32 for RouteHint { fn write_base32(&self, writer: &mut W) -> Result<(), ::Err> { let mut converter = BytesToBase32::new(writer); @@ -401,7 +401,7 @@ impl ToBase32 for Route { } } -impl Base32Len for Route { +impl Base32Len for RouteHint { fn base32_len(&self) -> usize { bytes_size_to_base32_size(self.0.len() * 51) }