@@ -151,6 +151,38 @@ pub struct InvoiceBuilder<'a, S: SigningPubkeyStrategy> {
151
151
signing_pubkey_strategy : S ,
152
152
}
153
153
154
+ /// Builds a [`Bolt12Invoice`] from either:
155
+ /// - an [`InvoiceRequest`] for the "offer to be paid" flow or
156
+ /// - a [`Refund`] for the "offer for money" flow.
157
+ ///
158
+ /// See [module-level documentation] for usage.
159
+ ///
160
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
161
+ /// [`Refund`]: crate::offers::refund::Refund
162
+ /// [module-level documentation]: self
163
+ #[ cfg( c_bindings) ]
164
+ pub struct InvoiceWithExplicitSigningPubkeyBuilder < ' a > {
165
+ invreq_bytes : & ' a Vec < u8 > ,
166
+ invoice : InvoiceContents ,
167
+ signing_pubkey_strategy : ExplicitSigningPubkey ,
168
+ }
169
+
170
+ /// Builds a [`Bolt12Invoice`] from either:
171
+ /// - an [`InvoiceRequest`] for the "offer to be paid" flow or
172
+ /// - a [`Refund`] for the "offer for money" flow.
173
+ ///
174
+ /// See [module-level documentation] for usage.
175
+ ///
176
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
177
+ /// [`Refund`]: crate::offers::refund::Refund
178
+ /// [module-level documentation]: self
179
+ #[ cfg( c_bindings) ]
180
+ pub struct InvoiceWithDerivedSigningPubkeyBuilder < ' a > {
181
+ invreq_bytes : & ' a Vec < u8 > ,
182
+ invoice : InvoiceContents ,
183
+ signing_pubkey_strategy : DerivedSigningPubkey ,
184
+ }
185
+
154
186
/// Indicates how [`Bolt12Invoice::signing_pubkey`] was set.
155
187
///
156
188
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
@@ -216,8 +248,13 @@ macro_rules! invoice_explicit_signing_pubkey_builder_methods { ($self: ident, $s
216
248
}
217
249
}
218
250
219
- let InvoiceBuilder { invreq_bytes, invoice, .. } = $self;
220
- Ok ( UnsignedBolt12Invoice :: new( invreq_bytes, invoice) )
251
+ let Self { invreq_bytes, invoice, .. } = $self;
252
+ #[ cfg( not( c_bindings) ) ] {
253
+ Ok ( UnsignedBolt12Invoice :: new( invreq_bytes, invoice) )
254
+ }
255
+ #[ cfg( c_bindings) ] {
256
+ Ok ( UnsignedBolt12Invoice :: new( invreq_bytes, invoice. clone( ) ) )
257
+ }
221
258
}
222
259
} }
223
260
@@ -272,10 +309,13 @@ macro_rules! invoice_derived_signing_pubkey_builder_methods { (
272
309
}
273
310
}
274
311
275
- let InvoiceBuilder {
312
+ let Self {
276
313
invreq_bytes, invoice, signing_pubkey_strategy: DerivedSigningPubkey ( keys)
277
314
} = $self;
315
+ #[ cfg( not( c_bindings) ) ]
278
316
let unsigned_invoice = UnsignedBolt12Invoice :: new( invreq_bytes, invoice) ;
317
+ #[ cfg( c_bindings) ]
318
+ let unsigned_invoice = UnsignedBolt12Invoice :: new( invreq_bytes, invoice. clone( ) ) ;
279
319
280
320
let invoice = unsigned_invoice
281
321
. sign:: <_, Infallible >(
@@ -287,7 +327,7 @@ macro_rules! invoice_derived_signing_pubkey_builder_methods { (
287
327
} }
288
328
289
329
macro_rules! invoice_builder_methods { (
290
- $self: ident, $self_type: ty, $return_type: ty, $return_value: expr
330
+ $self: ident, $self_type: ty, $return_type: ty, $return_value: expr, $type_param : ty
291
331
) => {
292
332
pub ( crate ) fn amount_msats(
293
333
invoice_request: & InvoiceRequest
@@ -316,7 +356,7 @@ macro_rules! invoice_builder_methods { (
316
356
}
317
357
318
358
fn new(
319
- invreq_bytes: & ' a Vec <u8 >, contents: InvoiceContents , signing_pubkey_strategy: S
359
+ invreq_bytes: & ' a Vec <u8 >, contents: InvoiceContents , signing_pubkey_strategy: $type_param
320
360
) -> Result <Self , Bolt12SemanticError > {
321
361
if contents. fields( ) . payment_paths. is_empty( ) {
322
362
return Err ( Bolt12SemanticError :: MissingPaths ) ;
@@ -392,7 +432,59 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
392
432
}
393
433
394
434
impl < ' a , S : SigningPubkeyStrategy > InvoiceBuilder < ' a , S > {
395
- invoice_builder_methods ! ( self , Self , Self , self ) ;
435
+ invoice_builder_methods ! ( self , Self , Self , self , S ) ;
436
+ }
437
+
438
+ #[ cfg( all( c_bindings, not( test) ) ) ]
439
+ impl < ' a > InvoiceWithExplicitSigningPubkeyBuilder < ' a > {
440
+ invoice_explicit_signing_pubkey_builder_methods ! ( self , & mut Self ) ;
441
+ invoice_builder_methods ! ( self , & mut Self , ( ) , ( ) , ExplicitSigningPubkey ) ;
442
+ }
443
+
444
+ #[ cfg( all( c_bindings, test) ) ]
445
+ impl < ' a > InvoiceWithExplicitSigningPubkeyBuilder < ' a > {
446
+ invoice_explicit_signing_pubkey_builder_methods ! ( self , & mut Self ) ;
447
+ invoice_builder_methods ! ( self , & mut Self , & mut Self , self , ExplicitSigningPubkey ) ;
448
+ }
449
+
450
+ #[ cfg( all( c_bindings, not( test) ) ) ]
451
+ impl < ' a > InvoiceWithDerivedSigningPubkeyBuilder < ' a > {
452
+ invoice_derived_signing_pubkey_builder_methods ! ( self , & mut Self , secp256k1:: All ) ;
453
+ invoice_builder_methods ! ( self , & mut Self , ( ) , ( ) , DerivedSigningPubkey ) ;
454
+ }
455
+
456
+ #[ cfg( all( c_bindings, test) ) ]
457
+ impl < ' a > InvoiceWithDerivedSigningPubkeyBuilder < ' a > {
458
+ invoice_derived_signing_pubkey_builder_methods ! ( self , & mut Self , secp256k1:: All ) ;
459
+ invoice_builder_methods ! ( self , & mut Self , & mut Self , self , DerivedSigningPubkey ) ;
460
+ }
461
+
462
+ #[ cfg( c_bindings) ]
463
+ impl < ' a > From < InvoiceWithDerivedSigningPubkeyBuilder < ' a > >
464
+ for InvoiceBuilder < ' a , DerivedSigningPubkey > {
465
+ fn from ( builder : InvoiceWithDerivedSigningPubkeyBuilder < ' a > ) -> Self {
466
+ let InvoiceWithDerivedSigningPubkeyBuilder {
467
+ invreq_bytes, invoice, signing_pubkey_strategy,
468
+ } = builder;
469
+
470
+ Self {
471
+ invreq_bytes, invoice, signing_pubkey_strategy,
472
+ }
473
+ }
474
+ }
475
+
476
+ #[ cfg( c_bindings) ]
477
+ impl < ' a > From < InvoiceWithExplicitSigningPubkeyBuilder < ' a > >
478
+ for InvoiceBuilder < ' a , ExplicitSigningPubkey > {
479
+ fn from ( builder : InvoiceWithExplicitSigningPubkeyBuilder < ' a > ) -> Self {
480
+ let InvoiceWithExplicitSigningPubkeyBuilder {
481
+ invreq_bytes, invoice, signing_pubkey_strategy,
482
+ } = builder;
483
+
484
+ Self {
485
+ invreq_bytes, invoice, signing_pubkey_strategy,
486
+ }
487
+ }
396
488
}
397
489
398
490
/// A semantically valid [`Bolt12Invoice`] that hasn't been signed.
@@ -1685,7 +1777,7 @@ mod tests {
1685
1777
if let Err ( e) = invoice_request. clone ( )
1686
1778
. verify ( & expanded_key, & secp_ctx) . unwrap ( )
1687
1779
. respond_using_derived_keys_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) ) . unwrap ( )
1688
- . build_and_sign ( & secp_ctx)
1780
+ . build_and_sign :: < secp256k1 :: All > ( & secp_ctx)
1689
1781
{
1690
1782
panic ! ( "error building invoice: {:?}" , e) ;
1691
1783
}
@@ -2122,8 +2214,13 @@ mod tests {
2122
2214
. request_invoice ( vec ! [ 1 ; 32 ] , payer_pubkey ( ) ) . unwrap ( )
2123
2215
. build ( ) . unwrap ( )
2124
2216
. sign ( payer_sign) . unwrap ( ) ;
2217
+ #[ cfg( not( c_bindings) ) ]
2218
+ let invoice_builder = invoice_request
2219
+ . respond_with_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) ) . unwrap ( ) ;
2220
+ #[ cfg( c_bindings) ]
2125
2221
let mut invoice_builder = invoice_request
2126
- . respond_with_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) ) . unwrap ( )
2222
+ . respond_with_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) ) . unwrap ( ) ;
2223
+ let mut invoice_builder = invoice_builder
2127
2224
. fallback_v0_p2wsh ( & script. wscript_hash ( ) )
2128
2225
. fallback_v0_p2wpkh ( & pubkey. wpubkey_hash ( ) . unwrap ( ) )
2129
2226
. fallback_v1_p2tr_tweaked ( & tweaked_pubkey) ;
0 commit comments