@@ -124,7 +124,18 @@ pub struct RefundBuilder<'a, T: secp256k1::Signing> {
124
124
secp_ctx : Option < & ' a Secp256k1 < T > > ,
125
125
}
126
126
127
- macro_rules! refund_without_secp256k1_builder_methods { ( ) => {
127
+ /// Builds a [`Refund`] for the "offer for money" flow.
128
+ ///
129
+ /// See [module-level documentation] for usage.
130
+ ///
131
+ /// [module-level documentation]: self
132
+ #[ cfg( c_bindings) ]
133
+ pub struct RefundMaybeWithDerivedMetadataBuilder < ' a > {
134
+ refund : RefundContents ,
135
+ secp_ctx : Option < & ' a Secp256k1 < secp256k1:: All > > ,
136
+ }
137
+
138
+ macro_rules! refund_explicit_metadata_builder_methods { ( ) => {
128
139
/// Creates a new builder for a refund using the [`Refund::payer_id`] for the public node id to
129
140
/// send to if no [`Refund::paths`] are set. Otherwise, it may be a transient pubkey.
130
141
///
@@ -158,7 +169,7 @@ macro_rules! refund_without_secp256k1_builder_methods { () => {
158
169
} }
159
170
160
171
macro_rules! refund_builder_methods { (
161
- $self: ident, $self_type: ty, $return_type: ty, $return_value: expr
172
+ $self: ident, $self_type: ty, $return_type: ty, $return_value: expr, $secp_context : ty
162
173
) => {
163
174
/// Similar to [`RefundBuilder::new`] except, if [`RefundBuilder::path`] is called, the payer id
164
175
/// is derived from the given [`ExpandedKey`] and nonce. This provides sender privacy by using a
@@ -175,7 +186,7 @@ macro_rules! refund_builder_methods { (
175
186
/// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
176
187
pub fn deriving_payer_id<ES : Deref >(
177
188
description: String , node_id: PublicKey , expanded_key: & ExpandedKey , entropy_source: ES ,
178
- secp_ctx: & ' a Secp256k1 <T >, amount_msats: u64 , payment_id: PaymentId
189
+ secp_ctx: & ' a Secp256k1 <$secp_context >, amount_msats: u64 , payment_id: PaymentId
179
190
) -> Result <Self , Bolt12SemanticError > where ES :: Target : EntropySource {
180
191
if amount_msats > MAX_VALUE_MSAT {
181
192
return Err ( Bolt12SemanticError :: InvalidAmount ) ;
@@ -293,7 +304,13 @@ macro_rules! refund_builder_methods { (
293
304
let mut bytes = Vec :: new( ) ;
294
305
$self. refund. write( & mut bytes) . unwrap( ) ;
295
306
296
- Ok ( Refund { bytes, contents: $self. refund } )
307
+ Ok ( Refund {
308
+ bytes,
309
+ #[ cfg( not( c_bindings) ) ]
310
+ contents: $self. refund,
311
+ #[ cfg( c_bindings) ]
312
+ contents: $self. refund. clone( ) ,
313
+ } )
297
314
}
298
315
} }
299
316
@@ -313,16 +330,39 @@ macro_rules! refund_builder_test_methods { (
313
330
} }
314
331
315
332
impl < ' a > RefundBuilder < ' a , secp256k1:: SignOnly > {
316
- refund_without_secp256k1_builder_methods ! ( ) ;
333
+ refund_explicit_metadata_builder_methods ! ( ) ;
317
334
}
318
335
319
336
impl < ' a , T : secp256k1:: Signing > RefundBuilder < ' a , T > {
320
- refund_builder_methods ! ( self , Self , Self , self ) ;
337
+ refund_builder_methods ! ( self , Self , Self , self , T ) ;
321
338
322
339
#[ cfg( test) ]
323
340
refund_builder_test_methods ! ( self , Self , Self , self ) ;
324
341
}
325
342
343
+ #[ cfg( all( c_bindings, not( test) ) ) ]
344
+ impl < ' a > RefundMaybeWithDerivedMetadataBuilder < ' a > {
345
+ refund_explicit_metadata_builder_methods ! ( ) ;
346
+ refund_builder_methods ! ( self , & mut Self , ( ) , ( ) , secp256k1:: All ) ;
347
+ }
348
+
349
+ #[ cfg( all( c_bindings, test) ) ]
350
+ impl < ' a > RefundMaybeWithDerivedMetadataBuilder < ' a > {
351
+ refund_explicit_metadata_builder_methods ! ( ) ;
352
+ refund_builder_methods ! ( self , & mut Self , & mut Self , self , secp256k1:: All ) ;
353
+ refund_builder_test_methods ! ( self , & mut Self , & mut Self , self ) ;
354
+ }
355
+
356
+ #[ cfg( c_bindings) ]
357
+ impl < ' a > From < RefundBuilder < ' a , secp256k1:: All > >
358
+ for RefundMaybeWithDerivedMetadataBuilder < ' a > {
359
+ fn from ( builder : RefundBuilder < ' a , secp256k1:: All > ) -> Self {
360
+ let RefundBuilder { refund, secp_ctx } = builder;
361
+
362
+ Self { refund, secp_ctx }
363
+ }
364
+ }
365
+
326
366
/// A `Refund` is a request to send an [`Bolt12Invoice`] without a preceding [`Offer`].
327
367
///
328
368
/// Typically, after an invoice is paid, the recipient may publish a refund allowing the sender to
@@ -798,7 +838,15 @@ impl core::fmt::Display for Refund {
798
838
799
839
#[ cfg( test) ]
800
840
mod tests {
801
- use super :: { Refund , RefundBuilder , RefundTlvStreamRef } ;
841
+ use super :: { Refund , RefundTlvStreamRef } ;
842
+ #[ cfg( not( c_bindings) ) ]
843
+ use {
844
+ super :: RefundBuilder ,
845
+ } ;
846
+ #[ cfg( c_bindings) ]
847
+ use {
848
+ super :: RefundMaybeWithDerivedMetadataBuilder as RefundBuilder ,
849
+ } ;
802
850
803
851
use bitcoin:: blockdata:: constants:: ChainHash ;
804
852
use bitcoin:: network:: constants:: Network ;
0 commit comments