@@ -57,7 +57,6 @@ use bitcoin::network::constants::Network;
57
57
use bitcoin:: secp256k1:: { Message , PublicKey } ;
58
58
use bitcoin:: secp256k1:: schnorr:: Signature ;
59
59
use core:: convert:: TryFrom ;
60
- use core:: time:: Duration ;
61
60
use crate :: io;
62
61
use crate :: ln:: PaymentHash ;
63
62
use crate :: ln:: features:: InvoiceRequestFeatures ;
@@ -326,23 +325,35 @@ impl InvoiceRequest {
326
325
/// Creates an [`Invoice`] for the request with the given required fields.
327
326
///
328
327
/// Unless [`InvoiceBuilder::relative_expiry`] is set, the invoice will expire two hours after
329
- /// `created_at`. The caller is expected to remember the preimage of `payment_hash` in order to
330
- /// claim a payment for the invoice.
328
+ /// calling this method in `std` builds. For `no-std` builds, a final [`Duration`] parameter
329
+ /// must be given, which is used to set [`Invoice::created_at`] since [`std::time::SystemTime`]
330
+ /// is not available.
331
+ ///
332
+ /// The caller is expected to remember the preimage of `payment_hash` in order to claim a payment
333
+ /// for the invoice.
331
334
///
332
335
/// The `payment_paths` parameter is useful for maintaining the payment recipient's privacy. It
333
336
/// must contain one or more elements.
334
337
///
335
338
/// Errors if the request contains unknown required features.
336
339
///
340
+ /// [`Duration`]: core::time::Duration
337
341
/// [`Invoice`]: crate::offers::invoice::Invoice
342
+ /// [`Invoice::created_at`]: crate::offers::invoice::Invoice::created_at
338
343
pub fn respond_with (
339
- & self , payment_paths : Vec < ( BlindedPath , BlindedPayInfo ) > , created_at : Duration ,
340
- payment_hash : PaymentHash
344
+ & self , payment_paths : Vec < ( BlindedPath , BlindedPayInfo ) > , payment_hash : PaymentHash ,
345
+ #[ cfg( not( feature = "std" ) ) ]
346
+ created_at : core:: time:: Duration
341
347
) -> Result < InvoiceBuilder , SemanticError > {
342
348
if self . features ( ) . requires_unknown_bits ( ) {
343
349
return Err ( SemanticError :: UnknownRequiredFeatures ) ;
344
350
}
345
351
352
+ #[ cfg( feature = "std" ) ]
353
+ let created_at = std:: time:: SystemTime :: now ( )
354
+ . duration_since ( std:: time:: SystemTime :: UNIX_EPOCH )
355
+ . expect ( "SystemTime::now() should come after SystemTime::UNIX_EPOCH" ) ;
356
+
346
357
InvoiceBuilder :: for_offer ( self , payment_paths, created_at, payment_hash)
347
358
}
348
359
0 commit comments