@@ -90,9 +90,12 @@ impl<'a> InvoiceRequestBuilder<'a> {
90
90
Self {
91
91
offer,
92
92
invoice_request : InvoiceRequestContents {
93
- payer : PayerContents ( metadata) , offer : offer. contents . clone ( ) , chain : None ,
94
- amount_msats : None , features : InvoiceRequestFeatures :: empty ( ) , quantity : None ,
95
- payer_id, payer_note : None ,
93
+ inner : InvoiceRequestContentsWithoutPayerId {
94
+ payer : PayerContents ( metadata) , offer : offer. contents . clone ( ) , chain : None ,
95
+ amount_msats : None , features : InvoiceRequestFeatures :: empty ( ) , quantity : None ,
96
+ payer_note : None ,
97
+ } ,
98
+ payer_id,
96
99
} ,
97
100
}
98
101
}
@@ -108,7 +111,7 @@ impl<'a> InvoiceRequestBuilder<'a> {
108
111
return Err ( SemanticError :: UnsupportedChain ) ;
109
112
}
110
113
111
- self . invoice_request . chain = Some ( chain) ;
114
+ self . invoice_request . inner . chain = Some ( chain) ;
112
115
Ok ( self )
113
116
}
114
117
@@ -119,10 +122,10 @@ impl<'a> InvoiceRequestBuilder<'a> {
119
122
///
120
123
/// [`quantity`]: Self::quantity
121
124
pub fn amount_msats ( mut self , amount_msats : u64 ) -> Result < Self , SemanticError > {
122
- self . invoice_request . offer . check_amount_msats_for_quantity (
123
- Some ( amount_msats) , self . invoice_request . quantity
125
+ self . invoice_request . inner . offer . check_amount_msats_for_quantity (
126
+ Some ( amount_msats) , self . invoice_request . inner . quantity
124
127
) ?;
125
- self . invoice_request . amount_msats = Some ( amount_msats) ;
128
+ self . invoice_request . inner . amount_msats = Some ( amount_msats) ;
126
129
Ok ( self )
127
130
}
128
131
@@ -131,16 +134,16 @@ impl<'a> InvoiceRequestBuilder<'a> {
131
134
///
132
135
/// Successive calls to this method will override the previous setting.
133
136
pub fn quantity ( mut self , quantity : u64 ) -> Result < Self , SemanticError > {
134
- self . invoice_request . offer . check_quantity ( Some ( quantity) ) ?;
135
- self . invoice_request . quantity = Some ( quantity) ;
137
+ self . invoice_request . inner . offer . check_quantity ( Some ( quantity) ) ?;
138
+ self . invoice_request . inner . quantity = Some ( quantity) ;
136
139
Ok ( self )
137
140
}
138
141
139
142
/// Sets the [`InvoiceRequest::payer_note`].
140
143
///
141
144
/// Successive calls to this method will override the previous setting.
142
145
pub fn payer_note ( mut self , payer_note : String ) -> Self {
143
- self . invoice_request . payer_note = Some ( payer_note) ;
146
+ self . invoice_request . inner . payer_note = Some ( payer_note) ;
144
147
self
145
148
}
146
149
@@ -159,16 +162,16 @@ impl<'a> InvoiceRequestBuilder<'a> {
159
162
}
160
163
161
164
if chain == self . offer . implied_chain ( ) {
162
- self . invoice_request . chain = None ;
165
+ self . invoice_request . inner . chain = None ;
163
166
}
164
167
165
- if self . offer . amount ( ) . is_none ( ) && self . invoice_request . amount_msats . is_none ( ) {
168
+ if self . offer . amount ( ) . is_none ( ) && self . invoice_request . inner . amount_msats . is_none ( ) {
166
169
return Err ( SemanticError :: MissingAmount ) ;
167
170
}
168
171
169
- self . invoice_request . offer . check_quantity ( self . invoice_request . quantity ) ?;
170
- self . invoice_request . offer . check_amount_msats_for_quantity (
171
- self . invoice_request . amount_msats , self . invoice_request . quantity
172
+ self . invoice_request . inner . offer . check_quantity ( self . invoice_request . inner . quantity ) ?;
173
+ self . invoice_request . inner . offer . check_amount_msats_for_quantity (
174
+ self . invoice_request . inner . amount_msats , self . invoice_request . inner . quantity
172
175
) ?;
173
176
174
177
let InvoiceRequestBuilder { offer, invoice_request } = self ;
@@ -180,22 +183,22 @@ impl<'a> InvoiceRequestBuilder<'a> {
180
183
impl < ' a > InvoiceRequestBuilder < ' a > {
181
184
fn chain_unchecked ( mut self , network : Network ) -> Self {
182
185
let chain = ChainHash :: using_genesis_block ( network) ;
183
- self . invoice_request . chain = Some ( chain) ;
186
+ self . invoice_request . inner . chain = Some ( chain) ;
184
187
self
185
188
}
186
189
187
190
fn amount_msats_unchecked ( mut self , amount_msats : u64 ) -> Self {
188
- self . invoice_request . amount_msats = Some ( amount_msats) ;
191
+ self . invoice_request . inner . amount_msats = Some ( amount_msats) ;
189
192
self
190
193
}
191
194
192
195
fn features_unchecked ( mut self , features : InvoiceRequestFeatures ) -> Self {
193
- self . invoice_request . features = features;
196
+ self . invoice_request . inner . features = features;
194
197
self
195
198
}
196
199
197
200
fn quantity_unchecked ( mut self , quantity : u64 ) -> Self {
198
- self . invoice_request . quantity = Some ( quantity) ;
201
+ self . invoice_request . inner . quantity = Some ( quantity) ;
199
202
self
200
203
}
201
204
@@ -265,13 +268,19 @@ pub struct InvoiceRequest {
265
268
#[ derive( Clone , Debug ) ]
266
269
#[ cfg_attr( test, derive( PartialEq ) ) ]
267
270
pub ( super ) struct InvoiceRequestContents {
271
+ pub ( super ) inner : InvoiceRequestContentsWithoutPayerId ,
272
+ payer_id : PublicKey ,
273
+ }
274
+
275
+ #[ derive( Clone , Debug ) ]
276
+ #[ cfg_attr( test, derive( PartialEq ) ) ]
277
+ pub ( super ) struct InvoiceRequestContentsWithoutPayerId {
268
278
payer : PayerContents ,
269
279
pub ( super ) offer : OfferContents ,
270
280
chain : Option < ChainHash > ,
271
281
amount_msats : Option < u64 > ,
272
282
features : InvoiceRequestFeatures ,
273
283
quantity : Option < u64 > ,
274
- payer_id : PublicKey ,
275
284
payer_note : Option < String > ,
276
285
}
277
286
@@ -281,7 +290,7 @@ impl InvoiceRequest {
281
290
///
282
291
/// [`payer_id`]: Self::payer_id
283
292
pub fn metadata ( & self ) -> & [ u8 ] {
284
- & self . contents . payer . 0 [ ..]
293
+ & self . contents . inner . payer . 0 [ ..]
285
294
}
286
295
287
296
/// A chain from [`Offer::chains`] that the offer is valid for.
@@ -294,17 +303,17 @@ impl InvoiceRequest {
294
303
///
295
304
/// [`chain`]: Self::chain
296
305
pub fn amount_msats ( & self ) -> Option < u64 > {
297
- self . contents . amount_msats
306
+ self . contents . inner . amount_msats
298
307
}
299
308
300
309
/// Features pertaining to requesting an invoice.
301
310
pub fn features ( & self ) -> & InvoiceRequestFeatures {
302
- & self . contents . features
311
+ & self . contents . inner . features
303
312
}
304
313
305
314
/// The quantity of the offer's item conforming to [`Offer::is_valid_quantity`].
306
315
pub fn quantity ( & self ) -> Option < u64 > {
307
- self . contents . quantity
316
+ self . contents . inner . quantity
308
317
}
309
318
310
319
/// A possibly transient pubkey used to sign the invoice request.
@@ -315,7 +324,8 @@ impl InvoiceRequest {
315
324
/// A payer-provided note which will be seen by the recipient and reflected back in the invoice
316
325
/// response.
317
326
pub fn payer_note ( & self ) -> Option < PrintableString > {
318
- self . contents . payer_note . as_ref ( ) . map ( |payer_note| PrintableString ( payer_note. as_str ( ) ) )
327
+ self . contents . inner . payer_note . as_ref ( )
328
+ . map ( |payer_note| PrintableString ( payer_note. as_str ( ) ) )
319
329
}
320
330
321
331
/// Signature of the invoice request using [`payer_id`].
@@ -377,7 +387,7 @@ impl InvoiceRequest {
377
387
pub fn verify < T : secp256k1:: Signing > (
378
388
& self , key : & ExpandedKey , secp_ctx : & Secp256k1 < T >
379
389
) -> bool {
380
- self . contents . offer . verify ( TlvStream :: new ( & self . bytes ) , key, secp_ctx)
390
+ self . contents . inner . offer . verify ( TlvStream :: new ( & self . bytes ) , key, secp_ctx)
381
391
}
382
392
383
393
#[ cfg( test) ]
@@ -392,6 +402,18 @@ impl InvoiceRequest {
392
402
}
393
403
394
404
impl InvoiceRequestContents {
405
+ pub ( super ) fn chain ( & self ) -> ChainHash {
406
+ self . inner . chain ( )
407
+ }
408
+
409
+ pub ( super ) fn as_tlv_stream ( & self ) -> PartialInvoiceRequestTlvStreamRef {
410
+ let ( payer, offer, mut invoice_request) = self . inner . as_tlv_stream ( ) ;
411
+ invoice_request. payer_id = Some ( & self . payer_id ) ;
412
+ ( payer, offer, invoice_request)
413
+ }
414
+ }
415
+
416
+ impl InvoiceRequestContentsWithoutPayerId {
395
417
pub ( super ) fn chain ( & self ) -> ChainHash {
396
418
self . chain . unwrap_or_else ( || self . offer . implied_chain ( ) )
397
419
}
@@ -413,7 +435,7 @@ impl InvoiceRequestContents {
413
435
amount : self . amount_msats ,
414
436
features,
415
437
quantity : self . quantity ,
416
- payer_id : Some ( & self . payer_id ) ,
438
+ payer_id : None ,
417
439
payer_note : self . payer_note . as_ref ( ) ,
418
440
} ;
419
441
@@ -531,7 +553,10 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
531
553
} ;
532
554
533
555
Ok ( InvoiceRequestContents {
534
- payer, offer, chain, amount_msats : amount, features, quantity, payer_id, payer_note,
556
+ inner : InvoiceRequestContentsWithoutPayerId {
557
+ payer, offer, chain, amount_msats : amount, features, quantity, payer_note,
558
+ } ,
559
+ payer_id,
535
560
} )
536
561
}
537
562
}
0 commit comments