8
8
// licenses.
9
9
10
10
//! Data structures and encoding for `invoice_request` messages.
11
+ //!
12
+ //! An [`InvoiceRequest`] can be either built from a parsed [`Offer`] for the user-pays-merchant
13
+ //! flow or built directly for the merchant-pays-user flow.
14
+ //!
15
+ //! ```
16
+ //! extern crate bitcoin;
17
+ //! extern crate lightning;
18
+ //!
19
+ //! use bitcoin::network::constants::Network;
20
+ //! use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
21
+ //! use lightning::ln::features::OfferFeatures;
22
+ //! use lightning::offers::Offer;
23
+ //! use lightning::util::ser::Writeable;
24
+ //!
25
+ //! # fn parse() -> Result<(), lightning::offers::ParseError> {
26
+ //! let secp_ctx = Secp256k1::new();
27
+ //! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32])?);
28
+ //! let pubkey = PublicKey::from(keys);
29
+ //! let mut buffer = Vec::new();
30
+ //!
31
+ //! // User-pays-merchant flow
32
+ //! "lno1qcp4256ypq"
33
+ //! .parse::<Offer>()?
34
+ //! .request_invoice(pubkey)
35
+ //! .payer_info(vec![42; 64])
36
+ //! .chain(Network::Testnet)?
37
+ //! .amount_msats(1000)?
38
+ //! .features(OfferFeatures::known())
39
+ //! .quantity(5)?
40
+ //! .payer_note("foo".to_string())
41
+ //! .build()?
42
+ //! .sign(|digest| secp_ctx.sign_schnorr_no_aux_rand(digest, &keys))?
43
+ //! .write(&mut buffer)
44
+ //! .unwrap();
45
+ //! # Ok(())
46
+ //! # }
47
+ //! ```
11
48
12
49
use bitcoin:: blockdata:: constants:: ChainHash ;
13
50
use bitcoin:: network:: constants:: Network ;
@@ -28,38 +65,9 @@ const SIGNATURE_TAG: &'static str = concat!("lightning", "invoice_request", "sig
28
65
29
66
/// Builds an [`InvoiceRequest`] from an [`Offer`] for the user-pays-merchant flow.
30
67
///
31
- /// ```
32
- /// extern crate bitcoin;
33
- /// extern crate lightning;
68
+ /// See [module-level documentation] for usage.
34
69
///
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()?
57
- /// .sign(|digest| secp_ctx.sign_schnorr_no_aux_rand(digest, &keys))?
58
- /// .write(&mut buffer)
59
- /// .unwrap();
60
- /// # Ok(())
61
- /// # }
62
- /// ```
70
+ /// [module-level documentation]: self
63
71
pub struct InvoiceRequestBuilder < ' a > {
64
72
offer : & ' a Offer ,
65
73
invoice_request : InvoiceRequestContents ,
0 commit comments