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 the docs of `impl FromStr for Invoice`)
22
- //! * For constructing invoices use the `InvoiceBuilder`
23
- //! * For serializing invoices use the `Display`/`ToString` traits
21
+ //! * For parsing use `str::parse::<Invoice>(&self)` (see [`Invoice::from_str`])
22
+ //! * For constructing invoices use the [`InvoiceBuilder`]
23
+ //! * For serializing invoices use the [`Display`]/[`ToString`] traits
24
+ //!
25
+ //! [`Invoice::from_str`]: crate::Invoice#impl-FromStr
24
26
25
27
#[ cfg( not( any( feature = "std" , feature = "no-std" ) ) ) ]
26
28
compile_error ! ( "at least one of the `std` or `no-std` features must be enabled" ) ;
@@ -160,7 +162,7 @@ pub const DEFAULT_EXPIRY_TIME: u64 = 3600;
160
162
/// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
161
163
pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA : u64 = 18 ;
162
164
163
- /// Builder for `Invoice`s. It's the most convenient and advised way to use this library. It ensures
165
+ /// Builder for [ `Invoice`] s. It's the most convenient and advised way to use this library. It ensures
164
166
/// that only a semantically and syntactically correct Invoice can be built using it.
165
167
///
166
168
/// ```
@@ -212,8 +214,8 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
212
214
/// # Type parameters
213
215
/// The two parameters `D` and `H` signal if the builder already contains the correct amount of the
214
216
/// given field:
215
- /// * `D`: exactly one ` Description` or ` DescriptionHash`
216
- /// * `H`: exactly one ` PaymentHash`
217
+ /// * `D`: exactly one [`TaggedField:: Description`] or [`TaggedField:: DescriptionHash`]
218
+ /// * `H`: exactly one [`TaggedField:: PaymentHash`]
217
219
/// * `T`: the timestamp is set
218
220
///
219
221
/// This is not exported to bindings users as we likely need to manually select one set of boolean type parameters.
@@ -236,9 +238,11 @@ pub struct InvoiceBuilder<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S:
236
238
/// Represents a syntactically and semantically correct lightning BOLT11 invoice.
237
239
///
238
240
/// There are three ways to construct an `Invoice`:
239
- /// 1. using `InvoiceBuilder`
240
- /// 2. using `Invoice::from_signed(SignedRawInvoice)`
241
- /// 3. using `str::parse::<Invoice>(&str)`
241
+ /// 1. using [`InvoiceBuilder`]
242
+ /// 2. using [`Invoice::from_signed`]
243
+ /// 3. using `str::parse::<Invoice>(&str)` (see [`Invoice::from_str`])
244
+ ///
245
+ /// [`Invoice::from_str`]: crate::Invoice#impl-FromStr
242
246
#[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
243
247
pub struct Invoice {
244
248
signed_invoice : SignedRawInvoice ,
@@ -258,34 +262,34 @@ pub enum InvoiceDescription<'f> {
258
262
Hash ( & ' f Sha256 ) ,
259
263
}
260
264
261
- /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
265
+ /// Represents a signed [ `RawInvoice`] with cached hash. The signature is not checked and may be
262
266
/// invalid.
263
267
///
264
268
/// # Invariants
265
- /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice` .
269
+ /// The hash has to be either from the deserialized invoice or from the serialized [`RawInvoice`] .
266
270
#[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
267
271
pub struct SignedRawInvoice {
268
272
/// The rawInvoice that the signature belongs to
269
273
raw_invoice : RawInvoice ,
270
274
271
- /// Hash of the `RawInvoice` that will be used to check the signature.
275
+ /// Hash of the [ `RawInvoice`] that will be used to check the signature.
272
276
///
273
277
/// * if the `SignedRawInvoice` was deserialized the hash is of from the original encoded form,
274
278
/// since it's not guaranteed that encoding it again will lead to the same result since integers
275
279
/// could have been encoded with leading zeroes etc.
276
280
/// * if the `SignedRawInvoice` was constructed manually the hash will be the calculated hash
277
- /// from the `RawInvoice`
281
+ /// from the [ `RawInvoice`]
278
282
hash : [ u8 ; 32 ] ,
279
283
280
284
/// signature of the payment request
281
285
signature : InvoiceSignature ,
282
286
}
283
287
284
- /// Represents an syntactically correct Invoice for a payment on the lightning network,
288
+ /// Represents an syntactically correct [` Invoice`] for a payment on the lightning network,
285
289
/// but without the signature information.
286
- /// De- and encoding should not lead to information loss but may lead to different hashes.
290
+ /// Decoding and encoding should not lead to information loss but may lead to different hashes.
287
291
///
288
- /// For methods without docs see the corresponding methods in `Invoice`.
292
+ /// For methods without docs see the corresponding methods in [ `Invoice`] .
289
293
#[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
290
294
pub struct RawInvoice {
291
295
/// human readable part
@@ -295,7 +299,7 @@ pub struct RawInvoice {
295
299
pub data : RawDataPart ,
296
300
}
297
301
298
- /// Data of the `RawInvoice` that is encoded in the human readable part
302
+ /// Data of the [ `RawInvoice`] that is encoded in the human readable part.
299
303
///
300
304
/// This is not exported to bindings users as we don't yet support `Option<Enum>`
301
305
#[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
@@ -310,7 +314,7 @@ pub struct RawHrp {
310
314
pub si_prefix : Option < SiPrefix > ,
311
315
}
312
316
313
- /// Data of the `RawInvoice` that is encoded in the data part
317
+ /// Data of the [ `RawInvoice`] that is encoded in the data part
314
318
#[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
315
319
pub struct RawDataPart {
316
320
/// generation time of the invoice
@@ -564,7 +568,8 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool> InvoiceBui
564
568
}
565
569
566
570
impl < D : tb:: Bool , H : tb:: Bool , C : tb:: Bool , S : tb:: Bool > InvoiceBuilder < D , H , tb:: True , C , S > {
567
- /// Builds a `RawInvoice` if no `CreationError` occurred while construction any of the fields.
571
+ /// Builds a [`RawInvoice`] if no [`CreationError`] occurred while construction any of the
572
+ /// fields.
568
573
pub fn build_raw ( self ) -> Result < RawInvoice , CreationError > {
569
574
570
575
// If an error occurred at any time before, return it now
@@ -753,17 +758,17 @@ impl SignedRawInvoice {
753
758
( self . raw_invoice , self . hash , self . signature )
754
759
}
755
760
756
- /// The `RawInvoice` which was signed.
761
+ /// The [ `RawInvoice`] which was signed.
757
762
pub fn raw_invoice ( & self ) -> & RawInvoice {
758
763
& self . raw_invoice
759
764
}
760
765
761
- /// The hash of the `RawInvoice` that was signed.
766
+ /// The hash of the [ `RawInvoice`] that was signed.
762
767
pub fn signable_hash ( & self ) -> & [ u8 ; 32 ] {
763
768
& self . hash
764
769
}
765
770
766
- /// InvoiceSignature for the invoice.
771
+ /// Signature for the invoice.
767
772
pub fn signature ( & self ) -> & InvoiceSignature {
768
773
& self . signature
769
774
}
@@ -881,8 +886,8 @@ impl RawInvoice {
881
886
)
882
887
}
883
888
884
- /// Signs the invoice using the supplied `sign_function `. This function MAY fail with an error
885
- /// of type `E`. Since the signature of a `SignedRawInvoice` is not required to be valid there
889
+ /// Signs the invoice using the supplied `sign_method `. This function MAY fail with an error of
890
+ /// type `E`. Since the signature of a [ `SignedRawInvoice`] is not required to be valid there
886
891
/// are no constraints regarding the validity of the produced signature.
887
892
///
888
893
/// This is not exported to bindings users as we don't currently support passing function pointers into methods
@@ -1033,6 +1038,11 @@ impl From<PositiveTimestamp> for SystemTime {
1033
1038
}
1034
1039
1035
1040
impl Invoice {
1041
+ /// The hash of the [`RawInvoice`] that was signed.
1042
+ pub fn signable_hash ( & self ) -> [ u8 ; 32 ] {
1043
+ self . signed_invoice . hash
1044
+ }
1045
+
1036
1046
/// Transform the `Invoice` into it's unchecked version
1037
1047
pub fn into_signed_raw ( self ) -> SignedRawInvoice {
1038
1048
self . signed_invoice
@@ -1137,7 +1147,7 @@ impl Invoice {
1137
1147
Ok ( ( ) )
1138
1148
}
1139
1149
1140
- /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
1150
+ /// Constructs an `Invoice` from a [ `SignedRawInvoice`] by checking all its invariants.
1141
1151
/// ```
1142
1152
/// use lightning_invoice::*;
1143
1153
///
@@ -1347,7 +1357,7 @@ impl TaggedField {
1347
1357
impl Description {
1348
1358
1349
1359
/// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1350
- /// returns `CreationError::DescriptionTooLong` otherwise
1360
+ /// returns [ `CreationError::DescriptionTooLong`] otherwise
1351
1361
///
1352
1362
/// Please note that single characters may use more than one byte due to UTF8 encoding.
1353
1363
pub fn new ( description : String ) -> Result < Description , CreationError > {
@@ -1358,7 +1368,7 @@ impl Description {
1358
1368
}
1359
1369
}
1360
1370
1361
- /// Returns the underlying description `String`
1371
+ /// Returns the underlying description [ `String`]
1362
1372
pub fn into_inner ( self ) -> String {
1363
1373
self . 0
1364
1374
}
@@ -1398,7 +1408,7 @@ impl ExpiryTime {
1398
1408
ExpiryTime ( Duration :: from_secs ( seconds) )
1399
1409
}
1400
1410
1401
- /// Construct an `ExpiryTime` from a `Duration`, dropping the sub-second part.
1411
+ /// Construct an `ExpiryTime` from a [ `Duration`] , dropping the sub-second part.
1402
1412
pub fn from_duration ( duration : Duration ) -> ExpiryTime {
1403
1413
Self :: from_seconds ( duration. as_secs ( ) )
1404
1414
}
@@ -1408,7 +1418,7 @@ impl ExpiryTime {
1408
1418
self . 0 . as_secs ( )
1409
1419
}
1410
1420
1411
- /// Returns a reference to the underlying `Duration` (=expiry time)
1421
+ /// Returns a reference to the underlying [ `Duration`] (=expiry time)
1412
1422
pub fn as_duration ( & self ) -> & Duration {
1413
1423
& self . 0
1414
1424
}
@@ -1460,10 +1470,10 @@ impl Deref for SignedRawInvoice {
1460
1470
}
1461
1471
}
1462
1472
1463
- /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
1473
+ /// Errors that may occur when constructing a new [ `RawInvoice`] or [ `Invoice`]
1464
1474
#[ derive( Eq , PartialEq , Debug , Clone ) ]
1465
1475
pub enum CreationError {
1466
- /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new) )
1476
+ /// The supplied description string was longer than 639 __bytes__ (see [`Description::new`] )
1467
1477
DescriptionTooLong ,
1468
1478
1469
1479
/// The specified route has too many hops and can't be encoded
@@ -1504,7 +1514,7 @@ impl Display for CreationError {
1504
1514
#[ cfg( feature = "std" ) ]
1505
1515
impl std:: error:: Error for CreationError { }
1506
1516
1507
- /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
1517
+ /// Errors that may occur when converting a [ `RawInvoice`] to an [ `Invoice`] . They relate to the
1508
1518
/// requirements sections in BOLT #11
1509
1519
#[ derive( Eq , PartialEq , Debug , Clone ) ]
1510
1520
pub enum SemanticError {
@@ -1560,7 +1570,7 @@ impl Display for SemanticError {
1560
1570
#[ cfg( feature = "std" ) ]
1561
1571
impl std:: error:: Error for SemanticError { }
1562
1572
1563
- /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
1573
+ /// When signing using a fallible method either an user-supplied `SignError` or a [ `CreationError`]
1564
1574
/// may occur.
1565
1575
#[ derive( Eq , PartialEq , Debug , Clone ) ]
1566
1576
pub enum SignOrCreationError < S = ( ) > {
0 commit comments