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:: genesis_block;
13
50
use bitcoin:: hash_types:: BlockHash ;
@@ -29,38 +66,9 @@ const SIGNATURE_TAG: &'static str = concat!("lightning", "invoice_request", "sig
29
66
30
67
/// Builds an [`InvoiceRequest`] from an [`Offer`] for the user-pays-merchant flow.
31
68
///
32
- /// ```
33
- /// extern crate bitcoin;
34
- /// extern crate lightning;
69
+ /// See [module-level documentation] for usage.
35
70
///
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()?
58
- /// .sign(|digest| secp_ctx.sign_schnorr_no_aux_rand(digest, &keys))?
59
- /// .write(&mut buffer)
60
- /// .unwrap();
61
- /// # Ok(())
62
- /// # }
63
- /// ```
71
+ /// [module-level documentation]: self
64
72
pub struct InvoiceRequestBuilder < ' a > {
65
73
offer : & ' a Offer ,
66
74
invoice_request : InvoiceRequestContents ,
0 commit comments