Module breez_sdk_core::lightning::offers::refund

Expand description

Data structures and encoding for refunds.

A Refund is an “offer for money” and is typically constructed by a merchant and presented directly to the customer. The recipient responds with a Bolt12Invoice to be paid.

This is an InvoiceRequest produced not in response to an Offer.

§Example

extern crate bitcoin;
extern crate core;
extern crate lightning;

use core::convert::TryFrom;
use core::time::Duration;

use bitcoin::network::constants::Network;
use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
use lightning::offers::parse::Bolt12ParseError;
use lightning::offers::refund::{Refund, RefundBuilder};
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 refund = RefundBuilder::new("coffee, large".to_string(), vec![1; 32], pubkey, 20_000)?
    .absolute_expiry(expiration.duration_since(SystemTime::UNIX_EPOCH).unwrap())
    .issuer("Foo Bar".to_string())
    .path(create_blinded_path())
    .path(create_another_blinded_path())
    .chain(Network::Bitcoin)
    .payer_note("refund for order #12345".to_string())
    .build()?;

// Encode as a bech32 string for use in a QR code.
let encoded_refund = refund.to_string();

// Parse from a bech32 string after scanning from a QR code.
let refund = encoded_refund.parse::<Refund>()?;

// Encode refund as raw bytes.
let mut bytes = Vec::new();
refund.write(&mut bytes).unwrap();

// Decode raw bytes into an refund.
let refund = Refund::try_from(bytes)?;

§Note

If constructing a Refund for use with a ChannelManager, use ChannelManager::create_refund_builder instead of RefundBuilder::new.

Structs§