.respond_with(payment_paths, payment_hash)?
")]
#![cfg_attr(not(feature = "std"), doc = "
- .respond_with(payment_paths, payment_hash, core::time::Duration::from_secs(0))?
+ .respond_with_no_std(payment_paths, payment_hash, core::time::Duration::from_secs(0))?
")]
//! .relative_expiry(3600)
//! .allow_mpp()
.respond_with(payment_paths, payment_hash, pubkey)?
")]
#![cfg_attr(not(feature = "std"), doc = "
- .respond_with(payment_paths, payment_hash, pubkey, core::time::Duration::from_secs(0))?
+ .respond_with_no_std(payment_paths, payment_hash, pubkey, core::time::Duration::from_secs(0))?
")]
//! .relative_expiry(3600)
//! .allow_mpp()
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths.clone(), payment_hash, now).unwrap()
+ .respond_with_no_std(payment_paths.clone(), payment_hash, now).unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
let now = now();
let invoice = RefundBuilder::new("foo".into(), vec![1; 32], payer_pubkey(), 1000).unwrap()
.build().unwrap()
- .respond_with(payment_paths.clone(), payment_hash, recipient_pubkey(), now).unwrap()
+ .respond_with_no_std(payment_paths.clone(), payment_hash, recipient_pubkey(), now)
+ .unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
if let Err(e) = RefundBuilder::new("foo".into(), vec![1; 32], payer_pubkey(), 1000).unwrap()
.absolute_expiry(future_expiry)
.build().unwrap()
- .respond_with(payment_paths(), payment_hash(), recipient_pubkey(), now()).unwrap()
+ .respond_with(payment_paths(), payment_hash(), recipient_pubkey())
+ .unwrap()
.build()
{
panic!("error building invoice: {:?}", e);
match RefundBuilder::new("foo".into(), vec![1; 32], payer_pubkey(), 1000).unwrap()
.absolute_expiry(past_expiry)
.build().unwrap()
- .respond_with(payment_paths(), payment_hash(), recipient_pubkey(), now()).unwrap()
+ .respond_with(payment_paths(), payment_hash(), recipient_pubkey())
+ .unwrap()
.build()
{
Ok(_) => panic!("expected error"),
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now).unwrap()
.relative_expiry(one_hour.as_secs() as u32)
.build().unwrap()
.sign(recipient_sign).unwrap();
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now - one_hour).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now - one_hour).unwrap()
.relative_expiry(one_hour.as_secs() as u32 - 1)
.build().unwrap()
.sign(recipient_sign).unwrap();
.amount_msats(1001).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
let (_, _, _, tlv_stream, _) = invoice.as_tlv_stream();
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.fallback_v0_p2wsh(&script.wscript_hash())
.fallback_v0_p2wpkh(&pubkey.wpubkey_hash().unwrap())
.fallback_v1_p2tr_tweaked(&tweaked_pubkey)
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.allow_mpp()
.build().unwrap()
.sign(recipient_sign).unwrap();
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.build().unwrap()
.sign(|_| Err(()))
{
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.build().unwrap()
.sign(payer_sign)
{
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.relative_expiry(3600)
.build().unwrap()
.sign(recipient_sign).unwrap();
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.allow_mpp()
.build().unwrap()
.sign(recipient_sign).unwrap();
.build().unwrap()
.sign(payer_sign).unwrap();
let mut unsigned_invoice = invoice_request
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.fallback_v0_p2wsh(&script.wscript_hash())
.fallback_v0_p2wpkh(&pubkey.wpubkey_hash().unwrap())
.fallback_v1_p2tr_tweaked(&tweaked_pubkey)
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.build().unwrap()
.invoice
.write(&mut buffer).unwrap();
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
let last_signature_byte = invoice.bytes.last_mut().unwrap();
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.build().unwrap()
.sign(payer_sign).unwrap()
- .respond_with(payment_paths(), payment_hash(), now()).unwrap()
+ .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
self.signature
}
+ /// Creates an [`Invoice`] for the request with the given required fields and using the
+ /// [`Duration`] since [`std::time::SystemTime::UNIX_EPOCH`] as the creation time.
+ ///
+ /// See [`InvoiceRequest::respond_with_no_std`] for further details where the aforementioned
+ /// creation time is used for the `created_at` parameter.
+ ///
+ /// [`Invoice`]: crate::offers::invoice::Invoice
+ /// [`Duration`]: core::time::Duration
+ #[cfg(feature = "std")]
+ pub fn respond_with(
+ &self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash
+ ) -> Result<InvoiceBuilder, SemanticError> {
+ let created_at = std::time::SystemTime::now()
+ .duration_since(std::time::SystemTime::UNIX_EPOCH)
+ .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
+
+ self.respond_with_no_std(payment_paths, payment_hash, created_at)
+ }
+
/// Creates an [`Invoice`] for the request with the given required fields.
///
/// Unless [`InvoiceBuilder::relative_expiry`] is set, the invoice will expire two hours after
- /// 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.
+ /// `created_at`, which is used to set [`Invoice::created_at`]. Useful for `no-std` builds where
+ /// [`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.
///
/// Errors if the request contains unknown required features.
///
- /// [`Duration`]: core::time::Duration
/// [`Invoice`]: crate::offers::invoice::Invoice
/// [`Invoice::created_at`]: crate::offers::invoice::Invoice::created_at
- pub fn respond_with(
+ pub fn respond_with_no_std(
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,
- #[cfg(any(test, not(feature = "std")))]
created_at: core::time::Duration
) -> Result<InvoiceBuilder, SemanticError> {
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_offer(self, payment_paths, created_at, payment_hash)
}
self.contents.payer_note.as_ref().map(|payer_note| PrintableString(payer_note.as_str()))
}
+ /// Creates an [`Invoice`] for the refund with the given required fields and using the
+ /// [`Duration`] since [`std::time::SystemTime::UNIX_EPOCH`] as the creation time.
+ ///
+ /// See [`Refund::respond_with_no_std`] for further details where the aforementioned creation
+ /// time is used for the `created_at` parameter.
+ ///
+ /// [`Invoice`]: crate::offers::invoice::Invoice
+ /// [`Duration`]: core::time::Duration
+ #[cfg(feature = "std")]
+ pub fn respond_with(
+ &self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,
+ signing_pubkey: PublicKey,
+ ) -> Result<InvoiceBuilder, SemanticError> {
+ let created_at = std::time::SystemTime::now()
+ .duration_since(std::time::SystemTime::UNIX_EPOCH)
+ .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
+
+ self.respond_with_no_std(payment_paths, payment_hash, signing_pubkey, created_at)
+ }
+
/// Creates an [`Invoice`] for the refund with the given required fields.
///
/// Unless [`InvoiceBuilder::relative_expiry`] is set, the invoice will expire two hours after
- /// 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.
+ /// `created_at`, which is used to set [`Invoice::created_at`]. Useful for `no-std` builds where
+ /// [`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.
///
/// [`Invoice`]: crate::offers::invoice::Invoice
/// [`Invoice::created_at`]: crate::offers::invoice::Invoice::created_at
- pub fn respond_with(
+ pub fn respond_with_no_std(
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,
- signing_pubkey: PublicKey,
- #[cfg(any(test, not(feature = "std")))]
- created_at: Duration
+ signing_pubkey: PublicKey, created_at: Duration
) -> Result<InvoiceBuilder, SemanticError> {
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)
}