@@ -53,7 +53,8 @@ const SIGNATURE_TAG: &'static str = concat!("lightning", "invoice_request", "sig
53
53
/// .features(OfferFeatures::known())
54
54
/// .quantity(5)?
55
55
/// .payer_note("foo".to_string())
56
- /// .build_signed(|digest| secp_ctx.sign_schnorr_no_aux_rand(digest, &keys))?
56
+ /// .build()?
57
+ /// .sign(|digest| secp_ctx.sign_schnorr_no_aux_rand(digest, &keys))?
57
58
/// .write(&mut buffer)
58
59
/// .unwrap();
59
60
/// # Ok(())
@@ -124,8 +125,35 @@ impl<'a> InvoiceRequestBuilder<'a> {
124
125
self
125
126
}
126
127
127
- ///
128
- pub fn build_signed < F > ( self , sign : F ) -> Result < InvoiceRequest , secp256k1:: Error >
128
+ /// Builds the [`InvoiceRequest`] after checking for valid semantics.
129
+ pub fn build ( self ) -> Result < UnsignedInvoiceRequest < ' a > , SemanticError > {
130
+ let chain = self . invoice_request . chain . unwrap_or_else ( || self . offer . implied_chain ( ) ) ;
131
+ if !self . offer . supports_chain ( chain) {
132
+ return Err ( SemanticError :: UnsupportedChain ) ;
133
+ }
134
+
135
+ if self . offer . amount ( ) . is_some ( ) && self . invoice_request . amount_msats . is_none ( ) {
136
+ return Err ( SemanticError :: MissingAmount ) ;
137
+ }
138
+
139
+ if self . offer . expects_quantity ( ) && self . invoice_request . quantity . is_none ( ) {
140
+ return Err ( SemanticError :: InvalidQuantity ) ;
141
+ }
142
+
143
+ let InvoiceRequestBuilder { offer, invoice_request } = self ;
144
+ Ok ( UnsignedInvoiceRequest { offer, invoice_request } )
145
+ }
146
+ }
147
+
148
+ /// A semantically valid [`InvoiceRequest`] that hasn't been signed.
149
+ pub struct UnsignedInvoiceRequest < ' a > {
150
+ offer : & ' a Offer ,
151
+ invoice_request : InvoiceRequestContents ,
152
+ }
153
+
154
+ impl < ' a > UnsignedInvoiceRequest < ' a > {
155
+ /// Signs the invoice request using the given function.
156
+ pub fn sign < F > ( self , sign : F ) -> Result < InvoiceRequest , secp256k1:: Error >
129
157
where F : FnOnce ( & Message ) -> Signature
130
158
{
131
159
// Use the offer bytes instead of the offer TLV stream as the offer may have contained
0 commit comments