Skip to content

Commit 93ead4a

Browse files
committed
Qualify the BOLT 11 invoice type
A previous commit qualified the BOLT 12 invoice type. Qualify the BOLT 11 invoice type for consistency.
1 parent 3234136 commit 93ead4a

File tree

6 files changed

+94
-93
lines changed

6 files changed

+94
-93
lines changed

lightning-invoice/src/de.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use num_traits::{CheckedAdd, CheckedMul};
2323
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
2424
use secp256k1::PublicKey;
2525

26-
use super::{Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiryDelta, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp,
26+
use super::{Bolt11Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiryDelta, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp,
2727
SemanticError, PrivateRoute, ParseError, ParseOrSemanticError, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawInvoice,
2828
constants, SignedRawInvoice, RawDataPart, InvoiceFeatures};
2929

@@ -210,7 +210,7 @@ impl FromStr for SiPrefix {
210210
}
211211

212212
/// ```
213-
/// use lightning_invoice::Invoice;
213+
/// use lightning_invoice::Bolt11Invoice;
214214
///
215215
///
216216
/// let invoice = "lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\
@@ -225,14 +225,14 @@ impl FromStr for SiPrefix {
225225
/// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\
226226
/// j5r6drg6k6zcqj0fcwg";
227227
///
228-
/// assert!(invoice.parse::<Invoice>().is_ok());
228+
/// assert!(invoice.parse::<Bolt11Invoice>().is_ok());
229229
/// ```
230-
impl FromStr for Invoice {
230+
impl FromStr for Bolt11Invoice {
231231
type Err = ParseOrSemanticError;
232232

233233
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
234234
let signed = s.parse::<SignedRawInvoice>()?;
235-
Ok(Invoice::from_signed(signed)?)
235+
Ok(Bolt11Invoice::from_signed(signed)?)
236236
}
237237
}
238238

@@ -251,10 +251,10 @@ impl FromStr for Invoice {
251251
/// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\
252252
/// j5r6drg6k6zcqj0fcwg";
253253
///
254-
/// let parsed_1 = invoice.parse::<Invoice>();
254+
/// let parsed_1 = invoice.parse::<Bolt11Invoice>();
255255
///
256256
/// let parsed_2 = match invoice.parse::<SignedRawInvoice>() {
257-
/// Ok(signed) => match Invoice::from_signed(signed) {
257+
/// Ok(signed) => match Bolt11Invoice::from_signed(signed) {
258258
/// Ok(invoice) => Ok(invoice),
259259
/// Err(e) => Err(ParseOrSemanticError::SemanticError(e)),
260260
/// },

lightning-invoice/src/lib.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
//! invoices and functions to create, encode and decode these. If you just want to use the standard
1919
//! en-/decoding functionality this should get you started:
2020
//!
21-
//! * For parsing use `str::parse::<Invoice>(&self)` (see [`Invoice::from_str`])
21+
//! * For parsing use `str::parse::<Bolt11Invoice>(&self)` (see [`Bolt11Invoice::from_str`])
2222
//! * For constructing invoices use the [`InvoiceBuilder`]
2323
//! * For serializing invoices use the [`Display`]/[`ToString`] traits
2424
//!
25-
//! [`Invoice::from_str`]: crate::Invoice#impl-FromStr
25+
//! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
2626
2727
#[cfg(not(any(feature = "std", feature = "no-std")))]
2828
compile_error!("at least one of the `std` or `no-std` features must be enabled");
@@ -164,8 +164,8 @@ pub const DEFAULT_EXPIRY_TIME: u64 = 3600;
164164
/// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
165165
pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
166166

167-
/// Builder for [`Invoice`]s. It's the most convenient and advised way to use this library. It ensures
168-
/// that only a semantically and syntactically correct Invoice can be built using it.
167+
/// Builder for [`Bolt11Invoice`]s. It's the most convenient and advised way to use this library. It
168+
/// ensures that only a semantically and syntactically correct invoice can be built using it.
169169
///
170170
/// ```
171171
/// extern crate secp256k1;
@@ -243,14 +243,14 @@ pub struct InvoiceBuilder<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S:
243243

244244
/// Represents a syntactically and semantically correct lightning BOLT11 invoice.
245245
///
246-
/// There are three ways to construct an `Invoice`:
246+
/// There are three ways to construct a `Bolt11Invoice`:
247247
/// 1. using [`InvoiceBuilder`]
248-
/// 2. using [`Invoice::from_signed`]
249-
/// 3. using `str::parse::<Invoice>(&str)` (see [`Invoice::from_str`])
248+
/// 2. using [`Bolt11Invoice::from_signed`]
249+
/// 3. using `str::parse::<Bolt11Invoice>(&str)` (see [`Bolt11Invoice::from_str`])
250250
///
251-
/// [`Invoice::from_str`]: crate::Invoice#impl-FromStr
251+
/// [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
252252
#[derive(Eq, PartialEq, Debug, Clone, Hash, Ord, PartialOrd)]
253-
pub struct Invoice {
253+
pub struct Bolt11Invoice {
254254
signed_invoice: SignedRawInvoice,
255255
}
256256

@@ -291,11 +291,11 @@ pub struct SignedRawInvoice {
291291
signature: InvoiceSignature,
292292
}
293293

294-
/// Represents an syntactically correct [`Invoice`] for a payment on the lightning network,
294+
/// Represents an syntactically correct [`Bolt11Invoice`] for a payment on the lightning network,
295295
/// but without the signature information.
296296
/// Decoding and encoding should not lead to information loss but may lead to different hashes.
297297
///
298-
/// For methods without docs see the corresponding methods in [`Invoice`].
298+
/// For methods without docs see the corresponding methods in [`Bolt11Invoice`].
299299
#[derive(Eq, PartialEq, Debug, Clone, Hash, Ord, PartialOrd)]
300300
pub struct RawInvoice {
301301
/// human readable part
@@ -807,7 +807,7 @@ impl<M: tb::Bool> InvoiceBuilder<tb::True, tb::True, tb::True, tb::True, tb::Tru
807807
/// Builds and signs an invoice using the supplied `sign_function`. This function MAY NOT fail
808808
/// and MUST produce a recoverable signature valid for the given hash and if applicable also for
809809
/// the included payee public key.
810-
pub fn build_signed<F>(self, sign_function: F) -> Result<Invoice, CreationError>
810+
pub fn build_signed<F>(self, sign_function: F) -> Result<Bolt11Invoice, CreationError>
811811
where F: FnOnce(&Message) -> RecoverableSignature
812812
{
813813
let invoice = self.try_build_signed::<_, ()>(|hash| {
@@ -824,7 +824,7 @@ impl<M: tb::Bool> InvoiceBuilder<tb::True, tb::True, tb::True, tb::True, tb::Tru
824824
/// Builds and signs an invoice using the supplied `sign_function`. This function MAY fail with
825825
/// an error of type `E` and MUST produce a recoverable signature valid for the given hash and
826826
/// if applicable also for the included payee public key.
827-
pub fn try_build_signed<F, E>(self, sign_function: F) -> Result<Invoice, SignOrCreationError<E>>
827+
pub fn try_build_signed<F, E>(self, sign_function: F) -> Result<Bolt11Invoice, SignOrCreationError<E>>
828828
where F: FnOnce(&Message) -> Result<RecoverableSignature, E>
829829
{
830830
let raw = match self.build_raw() {
@@ -837,7 +837,7 @@ impl<M: tb::Bool> InvoiceBuilder<tb::True, tb::True, tb::True, tb::True, tb::Tru
837837
Err(e) => return Err(SignOrCreationError::SignError(e)),
838838
};
839839

840-
let invoice = Invoice {
840+
let invoice = Bolt11Invoice {
841841
signed_invoice: signed,
842842
};
843843

@@ -1142,13 +1142,13 @@ impl From<PositiveTimestamp> for SystemTime {
11421142
}
11431143
}
11441144

1145-
impl Invoice {
1145+
impl Bolt11Invoice {
11461146
/// The hash of the [`RawInvoice`] that was signed.
11471147
pub fn signable_hash(&self) -> [u8; 32] {
11481148
self.signed_invoice.hash
11491149
}
11501150

1151-
/// Transform the `Invoice` into its unchecked version.
1151+
/// Transform the `Bolt11Invoice` into its unchecked version.
11521152
pub fn into_signed_raw(self) -> SignedRawInvoice {
11531153
self.signed_invoice
11541154
}
@@ -1252,7 +1252,7 @@ impl Invoice {
12521252
Ok(())
12531253
}
12541254

1255-
/// Constructs an `Invoice` from a [`SignedRawInvoice`] by checking all its invariants.
1255+
/// Constructs a `Bolt11Invoice` from a [`SignedRawInvoice`] by checking all its invariants.
12561256
/// ```
12571257
/// use lightning_invoice::*;
12581258
///
@@ -1270,10 +1270,10 @@ impl Invoice {
12701270
///
12711271
/// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
12721272
///
1273-
/// assert!(Invoice::from_signed(signed).is_ok());
1273+
/// assert!(Bolt11Invoice::from_signed(signed).is_ok());
12741274
/// ```
12751275
pub fn from_signed(signed_invoice: SignedRawInvoice) -> Result<Self, SemanticError> {
1276-
let invoice = Invoice {
1276+
let invoice = Bolt11Invoice {
12771277
signed_invoice,
12781278
};
12791279
invoice.check_field_counts()?;
@@ -1284,18 +1284,18 @@ impl Invoice {
12841284
Ok(invoice)
12851285
}
12861286

1287-
/// Returns the `Invoice`'s timestamp (should equal its creation time)
1287+
/// Returns the `Bolt11Invoice`'s timestamp (should equal its creation time)
12881288
#[cfg(feature = "std")]
12891289
pub fn timestamp(&self) -> SystemTime {
12901290
self.signed_invoice.raw_invoice().data.timestamp.as_time()
12911291
}
12921292

1293-
/// Returns the `Invoice`'s timestamp as a duration since the Unix epoch
1293+
/// Returns the `Bolt11Invoice`'s timestamp as a duration since the Unix epoch
12941294
pub fn duration_since_epoch(&self) -> Duration {
12951295
self.signed_invoice.raw_invoice().data.timestamp.0
12961296
}
12971297

1298-
/// Returns an iterator over all tagged fields of this Invoice.
1298+
/// Returns an iterator over all tagged fields of this `Bolt11Invoice`.
12991299
///
13001300
/// This is not exported to bindings users as there is not yet a manual mapping for a FilterMap
13011301
pub fn tagged_fields(&self)
@@ -1607,7 +1607,7 @@ impl Deref for SignedRawInvoice {
16071607
}
16081608
}
16091609

1610-
/// Errors that may occur when constructing a new [`RawInvoice`] or [`Invoice`]
1610+
/// Errors that may occur when constructing a new [`RawInvoice`] or [`Bolt11Invoice`]
16111611
#[derive(Eq, PartialEq, Debug, Clone)]
16121612
pub enum CreationError {
16131613
/// The supplied description string was longer than 639 __bytes__ (see [`Description::new`])
@@ -1651,8 +1651,8 @@ impl Display for CreationError {
16511651
#[cfg(feature = "std")]
16521652
impl std::error::Error for CreationError { }
16531653

1654-
/// Errors that may occur when converting a [`RawInvoice`] to an [`Invoice`]. They relate to the
1655-
/// requirements sections in BOLT #11
1654+
/// Errors that may occur when converting a [`RawInvoice`] to a [`Bolt11Invoice`]. They relate to
1655+
/// the requirements sections in BOLT #11
16561656
#[derive(Eq, PartialEq, Debug, Clone)]
16571657
pub enum SemanticError {
16581658
/// The invoice is missing the mandatory payment hash
@@ -1728,16 +1728,16 @@ impl<S> Display for SignOrCreationError<S> {
17281728
}
17291729

17301730
#[cfg(feature = "serde")]
1731-
impl Serialize for Invoice {
1731+
impl Serialize for Bolt11Invoice {
17321732
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
17331733
serializer.serialize_str(self.to_string().as_str())
17341734
}
17351735
}
17361736
#[cfg(feature = "serde")]
1737-
impl<'de> Deserialize<'de> for Invoice {
1738-
fn deserialize<D>(deserializer: D) -> Result<Invoice, D::Error> where D: Deserializer<'de> {
1737+
impl<'de> Deserialize<'de> for Bolt11Invoice {
1738+
fn deserialize<D>(deserializer: D) -> Result<Bolt11Invoice, D::Error> where D: Deserializer<'de> {
17391739
let bolt11 = String::deserialize(deserializer)?
1740-
.parse::<Invoice>()
1740+
.parse::<Bolt11Invoice>()
17411741
.map_err(|e| D::Error::custom(format_args!("{:?}", e)))?;
17421742

17431743
Ok(bolt11)
@@ -1866,7 +1866,7 @@ mod test {
18661866
use lightning::ln::features::InvoiceFeatures;
18671867
use secp256k1::Secp256k1;
18681868
use secp256k1::SecretKey;
1869-
use crate::{RawInvoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp, Invoice,
1869+
use crate::{Bolt11Invoice, RawInvoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp,
18701870
SemanticError};
18711871

18721872
let private_key = SecretKey::from_slice(&[42; 32]).unwrap();
@@ -1898,7 +1898,7 @@ mod test {
18981898
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
18991899
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
19001900
}.unwrap();
1901-
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::InvalidFeatures));
1901+
assert_eq!(Bolt11Invoice::from_signed(invoice), Err(SemanticError::InvalidFeatures));
19021902

19031903
// Missing feature bits
19041904
let invoice = {
@@ -1907,7 +1907,7 @@ mod test {
19071907
invoice.data.tagged_fields.push(Features(InvoiceFeatures::empty()).into());
19081908
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
19091909
}.unwrap();
1910-
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::InvalidFeatures));
1910+
assert_eq!(Bolt11Invoice::from_signed(invoice), Err(SemanticError::InvalidFeatures));
19111911

19121912
let mut payment_secret_features = InvoiceFeatures::empty();
19131913
payment_secret_features.set_payment_secret_required();
@@ -1919,30 +1919,30 @@ mod test {
19191919
invoice.data.tagged_fields.push(Features(payment_secret_features.clone()).into());
19201920
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
19211921
}.unwrap();
1922-
assert!(Invoice::from_signed(invoice).is_ok());
1922+
assert!(Bolt11Invoice::from_signed(invoice).is_ok());
19231923

19241924
// No payment secret or features
19251925
let invoice = {
19261926
let invoice = invoice_template.clone();
19271927
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
19281928
}.unwrap();
1929-
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
1929+
assert_eq!(Bolt11Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
19301930

19311931
// No payment secret or feature bits
19321932
let invoice = {
19331933
let mut invoice = invoice_template.clone();
19341934
invoice.data.tagged_fields.push(Features(InvoiceFeatures::empty()).into());
19351935
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
19361936
}.unwrap();
1937-
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
1937+
assert_eq!(Bolt11Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
19381938

19391939
// Missing payment secret
19401940
let invoice = {
19411941
let mut invoice = invoice_template.clone();
19421942
invoice.data.tagged_fields.push(Features(payment_secret_features).into());
19431943
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
19441944
}.unwrap();
1945-
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
1945+
assert_eq!(Bolt11Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
19461946

19471947
// Multiple payment secrets
19481948
let invoice = {
@@ -1951,7 +1951,7 @@ mod test {
19511951
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
19521952
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
19531953
}.unwrap();
1954-
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::MultiplePaymentSecrets));
1954+
assert_eq!(Bolt11Invoice::from_signed(invoice), Err(SemanticError::MultiplePaymentSecrets));
19551955
}
19561956

19571957
#[test]
@@ -2176,7 +2176,7 @@ mod test {
21762176
Ok(secp_ctx.sign_ecdsa_recoverable(hash, &privkey))
21772177
})
21782178
.unwrap();
2179-
let invoice = Invoice::from_signed(signed_invoice).unwrap();
2179+
let invoice = Bolt11Invoice::from_signed(signed_invoice).unwrap();
21802180

21812181
assert_eq!(invoice.min_final_cltv_expiry_delta(), DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA);
21822182
assert_eq!(invoice.expiry_time(), Duration::from_secs(DEFAULT_EXPIRY_TIME));
@@ -2202,7 +2202,7 @@ mod test {
22022202
Ok(secp_ctx.sign_ecdsa_recoverable(hash, &privkey))
22032203
})
22042204
.unwrap();
2205-
let invoice = Invoice::from_signed(signed_invoice).unwrap();
2205+
let invoice = Bolt11Invoice::from_signed(signed_invoice).unwrap();
22062206

22072207
assert!(invoice.would_expire(Duration::from_secs(1234567 + DEFAULT_EXPIRY_TIME + 1)));
22082208
}
@@ -2221,9 +2221,9 @@ mod test {
22212221
p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\
22222222
8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\
22232223
j5r6drg6k6zcqj0fcwg";
2224-
let invoice = invoice_str.parse::<super::Invoice>().unwrap();
2224+
let invoice = invoice_str.parse::<super::Bolt11Invoice>().unwrap();
22252225
let serialized_invoice = serde_json::to_string(&invoice).unwrap();
2226-
let deserialized_invoice: super::Invoice = serde_json::from_str(serialized_invoice.as_str()).unwrap();
2226+
let deserialized_invoice: super::Bolt11Invoice = serde_json::from_str(serialized_invoice.as_str()).unwrap();
22272227
assert_eq!(invoice, deserialized_invoice);
22282228
assert_eq!(invoice_str, deserialized_invoice.to_string().as_str());
22292229
assert_eq!(invoice_str, serialized_invoice.as_str().trim_matches('\"'));

0 commit comments

Comments
 (0)