Skip to content

Commit a1831ee

Browse files
committed
Add c_bindings version of InvoiceBuilder
Use the macros introduced in the previous commit to define two builders for each type parameterization of InvoiceBuilder - InvoiceWithExplicitSigningPubkeyBuilder - InvoiceWithDerivedSigningPubkeyBuilder The difference between these and InvoiceBuilder is that these have methods that take `self` by mutable reference instead of by value and don't return anything instead returning the modified builder. This is required because bindings don't support move semantics nor impl blocks specific to a certain type parameterization. Because of this, the builder's contents must be cloned when building a Bolt12Invoice. Keeps InvoiceBuilder defined so that it can be used internally in ChannelManager's OffersMessageHandler even when compiled for c_bindings.
1 parent 07d628e commit a1831ee

File tree

4 files changed

+211
-33
lines changed

4 files changed

+211
-33
lines changed

lightning/src/ln/channelmanager.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
5757
use crate::ln::outbound_payment;
5858
use crate::ln::outbound_payment::{Bolt12PaymentError, OutboundPayments, PaymentAttempts, PendingOutboundPayment, SendAlongPathArgs, StaleExpiration};
5959
use crate::ln::wire::Encode;
60-
use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, InvoiceBuilder};
60+
use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder};
6161
use crate::offers::invoice_error::InvoiceError;
6262
use crate::offers::invoice_request::{DerivedPayerId, InvoiceRequestBuilder};
6363
use crate::offers::merkle::SignError;
@@ -7834,6 +7834,7 @@ where
78347834
let builder = refund.respond_using_derived_keys_no_std(
78357835
payment_paths, payment_hash, created_at, expanded_key, entropy
78367836
)?;
7837+
let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
78377838
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
78387839
let reply_path = self.create_blinded_path()
78397840
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
@@ -9281,6 +9282,8 @@ where
92819282
let builder = invoice_request.respond_using_derived_keys_no_std(
92829283
payment_paths, payment_hash, created_at
92839284
);
9285+
let builder: Result<InvoiceBuilder<DerivedSigningPubkey>, _> =
9286+
builder.map(|b| b.into());
92849287
match builder.and_then(|b| b.allow_mpp().build_and_sign(secp_ctx)) {
92859288
Ok(invoice) => Some(OffersMessage::Invoice(invoice)),
92869289
Err(error) => Some(OffersMessage::InvoiceError(error.into())),
@@ -9292,9 +9295,13 @@ where
92929295
let builder = invoice_request.respond_with_no_std(
92939296
payment_paths, payment_hash, created_at
92949297
);
9298+
let builder: Result<InvoiceBuilder<ExplicitSigningPubkey>, _> =
9299+
builder.map(|b| b.into());
92959300
let response = builder.and_then(|builder| builder.allow_mpp().build())
92969301
.map_err(|e| OffersMessage::InvoiceError(e.into()))
9297-
.and_then(|invoice|
9302+
.and_then(|invoice| {
9303+
#[cfg(c_bindings)]
9304+
let mut invoice = invoice;
92989305
match invoice.sign(|invoice| self.node_signer.sign_bolt12_invoice(invoice)) {
92999306
Ok(invoice) => Ok(OffersMessage::Invoice(invoice)),
93009307
Err(SignError::Signing(())) => Err(OffersMessage::InvoiceError(
@@ -9303,7 +9310,8 @@ where
93039310
Err(SignError::Verification(_)) => Err(OffersMessage::InvoiceError(
93049311
InvoiceError::from_string("Failed invoice signature verification".to_string())
93059312
)),
9306-
});
9313+
}
9314+
});
93079315
match response {
93089316
Ok(invoice) => Some(invoice),
93099317
Err(error) => Some(error),

0 commit comments

Comments
 (0)