18
18
//! invoices and functions to create, encode and decode these. If you just want to use the standard
19
19
//! en-/decoding functionality this should get you started:
20
20
//!
21
- //! * For parsing use `str::parse::<Invoice >(&self)` (see [`Invoice ::from_str`])
21
+ //! * For parsing use `str::parse::<Bolt11Invoice >(&self)` (see [`Bolt11Invoice ::from_str`])
22
22
//! * For constructing invoices use the [`InvoiceBuilder`]
23
23
//! * For serializing invoices use the [`Display`]/[`ToString`] traits
24
24
//!
25
- //! [`Invoice ::from_str`]: crate::Invoice #impl-FromStr
25
+ //! [`Bolt11Invoice ::from_str`]: crate::Bolt11Invoice #impl-FromStr
26
26
27
27
#[ cfg( not( any( feature = "std" , feature = "no-std" ) ) ) ]
28
28
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;
164
164
/// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
165
165
pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA : u64 = 18 ;
166
166
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.
169
169
///
170
170
/// ```
171
171
/// extern crate secp256k1;
@@ -243,14 +243,14 @@ pub struct InvoiceBuilder<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S:
243
243
244
244
/// Represents a syntactically and semantically correct lightning BOLT11 invoice.
245
245
///
246
- /// There are three ways to construct an `Invoice `:
246
+ /// There are three ways to construct a `Bolt11Invoice `:
247
247
/// 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`])
250
250
///
251
- /// [`Invoice ::from_str`]: crate::Invoice #impl-FromStr
251
+ /// [`Bolt11Invoice ::from_str`]: crate::Bolt11Invoice #impl-FromStr
252
252
#[ derive( Eq , PartialEq , Debug , Clone , Hash , Ord , PartialOrd ) ]
253
- pub struct Invoice {
253
+ pub struct Bolt11Invoice {
254
254
signed_invoice : SignedRawInvoice ,
255
255
}
256
256
@@ -291,11 +291,11 @@ pub struct SignedRawInvoice {
291
291
signature : InvoiceSignature ,
292
292
}
293
293
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,
295
295
/// but without the signature information.
296
296
/// Decoding and encoding should not lead to information loss but may lead to different hashes.
297
297
///
298
- /// For methods without docs see the corresponding methods in [`Invoice `].
298
+ /// For methods without docs see the corresponding methods in [`Bolt11Invoice `].
299
299
#[ derive( Eq , PartialEq , Debug , Clone , Hash , Ord , PartialOrd ) ]
300
300
pub struct RawInvoice {
301
301
/// human readable part
@@ -807,7 +807,7 @@ impl<M: tb::Bool> InvoiceBuilder<tb::True, tb::True, tb::True, tb::True, tb::Tru
807
807
/// Builds and signs an invoice using the supplied `sign_function`. This function MAY NOT fail
808
808
/// and MUST produce a recoverable signature valid for the given hash and if applicable also for
809
809
/// 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 >
811
811
where F : FnOnce ( & Message ) -> RecoverableSignature
812
812
{
813
813
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
824
824
/// Builds and signs an invoice using the supplied `sign_function`. This function MAY fail with
825
825
/// an error of type `E` and MUST produce a recoverable signature valid for the given hash and
826
826
/// 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 > >
828
828
where F : FnOnce ( & Message ) -> Result < RecoverableSignature , E >
829
829
{
830
830
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
837
837
Err ( e) => return Err ( SignOrCreationError :: SignError ( e) ) ,
838
838
} ;
839
839
840
- let invoice = Invoice {
840
+ let invoice = Bolt11Invoice {
841
841
signed_invoice : signed,
842
842
} ;
843
843
@@ -1142,13 +1142,13 @@ impl From<PositiveTimestamp> for SystemTime {
1142
1142
}
1143
1143
}
1144
1144
1145
- impl Invoice {
1145
+ impl Bolt11Invoice {
1146
1146
/// The hash of the [`RawInvoice`] that was signed.
1147
1147
pub fn signable_hash ( & self ) -> [ u8 ; 32 ] {
1148
1148
self . signed_invoice . hash
1149
1149
}
1150
1150
1151
- /// Transform the `Invoice ` into its unchecked version.
1151
+ /// Transform the `Bolt11Invoice ` into its unchecked version.
1152
1152
pub fn into_signed_raw ( self ) -> SignedRawInvoice {
1153
1153
self . signed_invoice
1154
1154
}
@@ -1252,7 +1252,7 @@ impl Invoice {
1252
1252
Ok ( ( ) )
1253
1253
}
1254
1254
1255
- /// Constructs an `Invoice ` from a [`SignedRawInvoice`] by checking all its invariants.
1255
+ /// Constructs a `Bolt11Invoice ` from a [`SignedRawInvoice`] by checking all its invariants.
1256
1256
/// ```
1257
1257
/// use lightning_invoice::*;
1258
1258
///
@@ -1270,10 +1270,10 @@ impl Invoice {
1270
1270
///
1271
1271
/// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1272
1272
///
1273
- /// assert!(Invoice ::from_signed(signed).is_ok());
1273
+ /// assert!(Bolt11Invoice ::from_signed(signed).is_ok());
1274
1274
/// ```
1275
1275
pub fn from_signed ( signed_invoice : SignedRawInvoice ) -> Result < Self , SemanticError > {
1276
- let invoice = Invoice {
1276
+ let invoice = Bolt11Invoice {
1277
1277
signed_invoice,
1278
1278
} ;
1279
1279
invoice. check_field_counts ( ) ?;
@@ -1284,18 +1284,18 @@ impl Invoice {
1284
1284
Ok ( invoice)
1285
1285
}
1286
1286
1287
- /// Returns the `Invoice `'s timestamp (should equal its creation time)
1287
+ /// Returns the `Bolt11Invoice `'s timestamp (should equal its creation time)
1288
1288
#[ cfg( feature = "std" ) ]
1289
1289
pub fn timestamp ( & self ) -> SystemTime {
1290
1290
self . signed_invoice . raw_invoice ( ) . data . timestamp . as_time ( )
1291
1291
}
1292
1292
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
1294
1294
pub fn duration_since_epoch ( & self ) -> Duration {
1295
1295
self . signed_invoice . raw_invoice ( ) . data . timestamp . 0
1296
1296
}
1297
1297
1298
- /// Returns an iterator over all tagged fields of this Invoice .
1298
+ /// Returns an iterator over all tagged fields of this `Bolt11Invoice` .
1299
1299
///
1300
1300
/// This is not exported to bindings users as there is not yet a manual mapping for a FilterMap
1301
1301
pub fn tagged_fields ( & self )
@@ -1607,7 +1607,7 @@ impl Deref for SignedRawInvoice {
1607
1607
}
1608
1608
}
1609
1609
1610
- /// Errors that may occur when constructing a new [`RawInvoice`] or [`Invoice `]
1610
+ /// Errors that may occur when constructing a new [`RawInvoice`] or [`Bolt11Invoice `]
1611
1611
#[ derive( Eq , PartialEq , Debug , Clone ) ]
1612
1612
pub enum CreationError {
1613
1613
/// The supplied description string was longer than 639 __bytes__ (see [`Description::new`])
@@ -1651,8 +1651,8 @@ impl Display for CreationError {
1651
1651
#[ cfg( feature = "std" ) ]
1652
1652
impl std:: error:: Error for CreationError { }
1653
1653
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
1656
1656
#[ derive( Eq , PartialEq , Debug , Clone ) ]
1657
1657
pub enum SemanticError {
1658
1658
/// The invoice is missing the mandatory payment hash
@@ -1728,16 +1728,16 @@ impl<S> Display for SignOrCreationError<S> {
1728
1728
}
1729
1729
1730
1730
#[ cfg( feature = "serde" ) ]
1731
- impl Serialize for Invoice {
1731
+ impl Serialize for Bolt11Invoice {
1732
1732
fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error > where S : Serializer {
1733
1733
serializer. serialize_str ( self . to_string ( ) . as_str ( ) )
1734
1734
}
1735
1735
}
1736
1736
#[ 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 > {
1739
1739
let bolt11 = String :: deserialize ( deserializer) ?
1740
- . parse :: < Invoice > ( )
1740
+ . parse :: < Bolt11Invoice > ( )
1741
1741
. map_err ( |e| D :: Error :: custom ( format_args ! ( "{:?}" , e) ) ) ?;
1742
1742
1743
1743
Ok ( bolt11)
@@ -1866,7 +1866,7 @@ mod test {
1866
1866
use lightning:: ln:: features:: InvoiceFeatures ;
1867
1867
use secp256k1:: Secp256k1 ;
1868
1868
use secp256k1:: SecretKey ;
1869
- use crate :: { RawInvoice , RawHrp , RawDataPart , Currency , Sha256 , PositiveTimestamp , Invoice ,
1869
+ use crate :: { Bolt11Invoice , RawInvoice , RawHrp , RawDataPart , Currency , Sha256 , PositiveTimestamp ,
1870
1870
SemanticError } ;
1871
1871
1872
1872
let private_key = SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
@@ -1898,7 +1898,7 @@ mod test {
1898
1898
invoice. data . tagged_fields . push ( PaymentSecret ( payment_secret) . into ( ) ) ;
1899
1899
invoice. sign :: < _ , ( ) > ( |hash| Ok ( Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash, & private_key) ) )
1900
1900
} . unwrap ( ) ;
1901
- assert_eq ! ( Invoice :: from_signed( invoice) , Err ( SemanticError :: InvalidFeatures ) ) ;
1901
+ assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( SemanticError :: InvalidFeatures ) ) ;
1902
1902
1903
1903
// Missing feature bits
1904
1904
let invoice = {
@@ -1907,7 +1907,7 @@ mod test {
1907
1907
invoice. data . tagged_fields . push ( Features ( InvoiceFeatures :: empty ( ) ) . into ( ) ) ;
1908
1908
invoice. sign :: < _ , ( ) > ( |hash| Ok ( Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash, & private_key) ) )
1909
1909
} . unwrap ( ) ;
1910
- assert_eq ! ( Invoice :: from_signed( invoice) , Err ( SemanticError :: InvalidFeatures ) ) ;
1910
+ assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( SemanticError :: InvalidFeatures ) ) ;
1911
1911
1912
1912
let mut payment_secret_features = InvoiceFeatures :: empty ( ) ;
1913
1913
payment_secret_features. set_payment_secret_required ( ) ;
@@ -1919,30 +1919,30 @@ mod test {
1919
1919
invoice. data . tagged_fields . push ( Features ( payment_secret_features. clone ( ) ) . into ( ) ) ;
1920
1920
invoice. sign :: < _ , ( ) > ( |hash| Ok ( Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash, & private_key) ) )
1921
1921
} . unwrap ( ) ;
1922
- assert ! ( Invoice :: from_signed( invoice) . is_ok( ) ) ;
1922
+ assert ! ( Bolt11Invoice :: from_signed( invoice) . is_ok( ) ) ;
1923
1923
1924
1924
// No payment secret or features
1925
1925
let invoice = {
1926
1926
let invoice = invoice_template. clone ( ) ;
1927
1927
invoice. sign :: < _ , ( ) > ( |hash| Ok ( Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash, & private_key) ) )
1928
1928
} . unwrap ( ) ;
1929
- assert_eq ! ( Invoice :: from_signed( invoice) , Err ( SemanticError :: NoPaymentSecret ) ) ;
1929
+ assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( SemanticError :: NoPaymentSecret ) ) ;
1930
1930
1931
1931
// No payment secret or feature bits
1932
1932
let invoice = {
1933
1933
let mut invoice = invoice_template. clone ( ) ;
1934
1934
invoice. data . tagged_fields . push ( Features ( InvoiceFeatures :: empty ( ) ) . into ( ) ) ;
1935
1935
invoice. sign :: < _ , ( ) > ( |hash| Ok ( Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash, & private_key) ) )
1936
1936
} . unwrap ( ) ;
1937
- assert_eq ! ( Invoice :: from_signed( invoice) , Err ( SemanticError :: NoPaymentSecret ) ) ;
1937
+ assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( SemanticError :: NoPaymentSecret ) ) ;
1938
1938
1939
1939
// Missing payment secret
1940
1940
let invoice = {
1941
1941
let mut invoice = invoice_template. clone ( ) ;
1942
1942
invoice. data . tagged_fields . push ( Features ( payment_secret_features) . into ( ) ) ;
1943
1943
invoice. sign :: < _ , ( ) > ( |hash| Ok ( Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash, & private_key) ) )
1944
1944
} . unwrap ( ) ;
1945
- assert_eq ! ( Invoice :: from_signed( invoice) , Err ( SemanticError :: NoPaymentSecret ) ) ;
1945
+ assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( SemanticError :: NoPaymentSecret ) ) ;
1946
1946
1947
1947
// Multiple payment secrets
1948
1948
let invoice = {
@@ -1951,7 +1951,7 @@ mod test {
1951
1951
invoice. data . tagged_fields . push ( PaymentSecret ( payment_secret) . into ( ) ) ;
1952
1952
invoice. sign :: < _ , ( ) > ( |hash| Ok ( Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash, & private_key) ) )
1953
1953
} . unwrap ( ) ;
1954
- assert_eq ! ( Invoice :: from_signed( invoice) , Err ( SemanticError :: MultiplePaymentSecrets ) ) ;
1954
+ assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( SemanticError :: MultiplePaymentSecrets ) ) ;
1955
1955
}
1956
1956
1957
1957
#[ test]
@@ -2176,7 +2176,7 @@ mod test {
2176
2176
Ok ( secp_ctx. sign_ecdsa_recoverable ( hash, & privkey) )
2177
2177
} )
2178
2178
. unwrap ( ) ;
2179
- let invoice = Invoice :: from_signed ( signed_invoice) . unwrap ( ) ;
2179
+ let invoice = Bolt11Invoice :: from_signed ( signed_invoice) . unwrap ( ) ;
2180
2180
2181
2181
assert_eq ! ( invoice. min_final_cltv_expiry_delta( ) , DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA ) ;
2182
2182
assert_eq ! ( invoice. expiry_time( ) , Duration :: from_secs( DEFAULT_EXPIRY_TIME ) ) ;
@@ -2202,7 +2202,7 @@ mod test {
2202
2202
Ok ( secp_ctx. sign_ecdsa_recoverable ( hash, & privkey) )
2203
2203
} )
2204
2204
. unwrap ( ) ;
2205
- let invoice = Invoice :: from_signed ( signed_invoice) . unwrap ( ) ;
2205
+ let invoice = Bolt11Invoice :: from_signed ( signed_invoice) . unwrap ( ) ;
2206
2206
2207
2207
assert ! ( invoice. would_expire( Duration :: from_secs( 1234567 + DEFAULT_EXPIRY_TIME + 1 ) ) ) ;
2208
2208
}
@@ -2221,9 +2221,9 @@ mod test {
2221
2221
p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\
2222
2222
8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\
2223
2223
j5r6drg6k6zcqj0fcwg";
2224
- let invoice = invoice_str. parse :: < super :: Invoice > ( ) . unwrap ( ) ;
2224
+ let invoice = invoice_str. parse :: < super :: Bolt11Invoice > ( ) . unwrap ( ) ;
2225
2225
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 ( ) ;
2227
2227
assert_eq ! ( invoice, deserialized_invoice) ;
2228
2228
assert_eq ! ( invoice_str, deserialized_invoice. to_string( ) . as_str( ) ) ;
2229
2229
assert_eq ! ( invoice_str, serialized_invoice. as_str( ) . trim_matches( '\"' ) ) ;
0 commit comments