X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Foffers%2Frefund.rs;h=bee6cc7f5f61ddd39a89744bf33f9d6bc8ea66f5;hb=e0a0add9fe0b239f8a5176ab62e7ba3cb4f541ca;hp=e5d8e78f0794e08c7dee1fe8e994bacb9ab14cd2;hpb=f779bc066fe9a0da409502cd0c4655ba71c50a93;p=rust-lightning diff --git a/lightning/src/offers/refund.rs b/lightning/src/offers/refund.rs index e5d8e78f..bee6cc7f 100644 --- a/lightning/src/offers/refund.rs +++ b/lightning/src/offers/refund.rs @@ -301,7 +301,11 @@ impl Refund { /// Creates an [`Invoice`] for the refund with the given required fields. /// /// Unless [`InvoiceBuilder::relative_expiry`] is set, the invoice will expire two hours after - /// `created_at`. The caller is expected to remember the preimage of `payment_hash` in order to + /// calling this method in `std` builds. For `no-std` builds, a final [`Duration`] parameter + /// must be given, which is used to set [`Invoice::created_at`] since [`std::time::SystemTime`] + /// is not available. + /// + /// The caller is expected to remember the preimage of `payment_hash` in order to /// claim a payment for the invoice. /// /// The `signing_pubkey` is required to sign the invoice since refunds are not in response to an @@ -313,14 +317,22 @@ impl Refund { /// Errors if the request contains unknown required features. /// /// [`Invoice`]: crate::offers::invoice::Invoice + /// [`Invoice::created_at`]: crate::offers::invoice::Invoice::created_at pub fn respond_with( - &self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, created_at: Duration, - payment_hash: PaymentHash, signing_pubkey: PublicKey + &self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash, + signing_pubkey: PublicKey, + #[cfg(any(test, not(feature = "std")))] + created_at: Duration ) -> Result { if self.features().requires_unknown_bits() { return Err(SemanticError::UnknownRequiredFeatures); } + #[cfg(all(not(test), feature = "std"))] + let created_at = std::time::SystemTime::now() + .duration_since(std::time::SystemTime::UNIX_EPOCH) + .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH"); + InvoiceBuilder::for_refund(self, payment_paths, created_at, payment_hash, signing_pubkey) }