Skip to content

Commit b593f07

Browse files
committed
f - Add docs for InvoiceRequestBuilder
1 parent b408e26 commit b593f07

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

lightning/src/offers/invoice_request.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,39 @@ use util::ser::{Readable, WithoutLength, Writeable, Writer};
2626
///
2727
const SIGNATURE_TAG: &'static str = concat!("lightning", "invoice_request", "signature");
2828

29+
/// Builds an [`InvoiceRequest`] from an [`Offer`] for the user-pays-merchant flow.
2930
///
31+
/// ```
32+
/// extern crate bitcoin;
33+
/// extern crate lightning;
34+
///
35+
/// use bitcoin::network::constants::Network;
36+
/// use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
37+
/// use lightning::ln::features::OfferFeatures;
38+
/// use lightning::offers::Offer;
39+
/// use lightning::util::ser::Writeable;
40+
///
41+
/// # fn parse() -> Result<(), lightning::offers::ParseError> {
42+
/// let secp_ctx = Secp256k1::new();
43+
/// let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32])?);
44+
/// let pubkey = PublicKey::from(keys);
45+
/// let mut buffer = Vec::new();
46+
///
47+
/// "lno1qcp4256ypq"
48+
/// .parse::<Offer>()?
49+
/// .request_invoice(pubkey)
50+
/// .payer_info(vec![42; 64])
51+
/// .chain(Network::Testnet)?
52+
/// .amount_msats(1000)?
53+
/// .features(OfferFeatures::known())
54+
/// .quantity(5)?
55+
/// .payer_note("foo".to_string())
56+
/// .build_signed(|digest| secp_ctx.sign_schnorr_no_aux_rand(digest, &keys))?
57+
/// .write(&mut buffer)
58+
/// .unwrap();
59+
/// # Ok(())
60+
/// # }
61+
/// ```
3062
pub struct InvoiceRequestBuilder<'a> {
3163
offer: &'a Offer,
3264
invoice_request: InvoiceRequestContents,

0 commit comments

Comments
 (0)