@@ -57,7 +57,6 @@ use bitcoin::network::constants::Network;
5757use bitcoin:: secp256k1:: { Message , PublicKey } ;
5858use bitcoin:: secp256k1:: schnorr:: Signature ;
5959use core:: convert:: TryFrom ;
60- use core:: time:: Duration ;
6160use crate :: io;
6261use crate :: ln:: PaymentHash ;
6362use crate :: ln:: features:: InvoiceRequestFeatures ;
@@ -326,23 +325,35 @@ impl InvoiceRequest {
326325 /// Creates an [`Invoice`] for the request with the given required fields.
327326 ///
328327 /// 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.
331334 ///
332335 /// The `payment_paths` parameter is useful for maintaining the payment recipient's privacy. It
333336 /// must contain one or more elements.
334337 ///
335338 /// Errors if the request contains unknown required features.
336339 ///
340+ /// [`Duration`]: core::time::Duration
337341 /// [`Invoice`]: crate::offers::invoice::Invoice
342+ /// [`Invoice::created_at`]: crate::offers::invoice::Invoice::created_at
338343 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
341347 ) -> Result < InvoiceBuilder , SemanticError > {
342348 if self . features ( ) . requires_unknown_bits ( ) {
343349 return Err ( SemanticError :: UnknownRequiredFeatures ) ;
344350 }
345351
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+
346357 InvoiceBuilder :: for_offer ( self , payment_paths, created_at, payment_hash)
347358 }
348359
0 commit comments