Skip to content

Commit b42ef4f

Browse files
committed
f - Add docs for InvoiceRequestBuilder
1 parent bfaa374 commit b42ef4f

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
@@ -27,7 +27,39 @@ use util::ser::{Readable, WithoutLength, Writeable, Writer};
2727
///
2828
const SIGNATURE_TAG: &'static str = concat!("lightning", "invoice_request", "signature");
2929

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

0 commit comments

Comments
 (0)