Module breez_sdk_core::lightning::offers::offer
Expand description
Data structures and encoding for offer
messages.
An Offer
represents an “offer to be paid.” It is typically constructed by a merchant and
published as a QR code to be scanned by a customer. The customer uses the offer to request an
invoice from the merchant to be paid.
§Example
extern crate bitcoin;
extern crate core;
extern crate lightning;
use core::convert::TryFrom;
use core::num::NonZeroU64;
use core::time::Duration;
use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
use lightning::offers::offer::{Offer, OfferBuilder, Quantity};
use lightning::offers::parse::Bolt12ParseError;
use lightning::util::ser::{Readable, Writeable};
let secp_ctx = Secp256k1::new();
let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
let pubkey = PublicKey::from(keys);
let expiration = SystemTime::now() + Duration::from_secs(24 * 60 * 60);
let offer = OfferBuilder::new("coffee, large".to_string(), pubkey)
.amount_msats(20_000)
.supported_quantity(Quantity::Unbounded)
.absolute_expiry(expiration.duration_since(SystemTime::UNIX_EPOCH).unwrap())
.issuer("Foo Bar".to_string())
.path(create_blinded_path())
.path(create_another_blinded_path())
.build()?;
// Encode as a bech32 string for use in a QR code.
let encoded_offer = offer.to_string();
// Parse from a bech32 string after scanning from a QR code.
let offer = encoded_offer.parse::<Offer>()?;
// Encode offer as raw bytes.
let mut bytes = Vec::new();
offer.write(&mut bytes).unwrap();
// Decode raw bytes into an offer.
let offer = Offer::try_from(bytes)?;
§Note
If constructing an Offer
for use with a ChannelManager
, use
ChannelManager::create_offer_builder
instead of OfferBuilder::new
.
Structs§
Offer::metadata
will be derived.Offer::metadata
may be explicitly set or left empty.- An
Offer
is a potentially long-lived proposal for payment of a good or service. - Builds an
Offer
for the “offer to be paid” flow.
Enums§
- The minimum amount required for an item in an
Offer
, denominated in either bitcoin or another currency. - Quantity of items supported by an
Offer
.
Traits§
- Indicates how
Offer::metadata
may be set.
Type Aliases§
- An ISO 4712 three-letter currency code (e.g., USD).