Skip to content

Commit 795a396

Browse files
committed
OfferBuilder for c_bindings
OfferBuilder is currently not exported to bindings because it uses move semantics and has impl blocks for specific type parameterizations. Define a macro that defines OfferBuilder methods such that c_bindings versions can be defined.
1 parent 51d9ee3 commit 795a396

File tree

4 files changed

+201
-74
lines changed

4 files changed

+201
-74
lines changed

lightning/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ default = ["std", "grind_signatures"]
4141

4242
[dependencies]
4343
bitcoin = { version = "0.30.2", default-features = false, features = ["secp-recovery"] }
44+
secp256k1 = { version = "0.27", features = ["global-context", "recovery"] }
4445

4546
hashbrown = { version = "0.8", optional = true }
4647
hex = { package = "hex-conservative", version = "0.1.1", default-features = false }

lightning/src/ln/channelmanager.rs

+27-9
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use crate::ln::wire::Encode;
6060
use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, InvoiceBuilder};
6161
use crate::offers::invoice_error::InvoiceError;
6262
use crate::offers::merkle::SignError;
63-
use crate::offers::offer::{DerivedMetadata, Offer, OfferBuilder};
63+
use crate::offers::offer::Offer;
6464
use crate::offers::parse::Bolt12SemanticError;
6565
use crate::offers::refund::{Refund, RefundBuilder};
6666
use crate::onion_message::messenger::{Destination, MessageRouter, PendingOnionMessage, new_pending_onion_message};
@@ -98,6 +98,12 @@ use core::ops::Deref;
9898
pub use crate::ln::outbound_payment::{PaymentSendFailure, ProbeSendFailure, Retry, RetryableSendFailure, RecipientOnionFields};
9999
use crate::ln::script::ShutdownScript;
100100

101+
#[cfg(not(c_bindings))]
102+
type OfferBuilder<'a> =
103+
crate::offers::offer::OfferBuilder<'a, crate::offers::offer::DerivedMetadata, secp256k1::All>;
104+
#[cfg(c_bindings)]
105+
type OfferBuilder<'a> = crate::offers::offer::OfferWithDerivedMetadataBuilder;
106+
101107
// We hold various information about HTLC relay in the HTLC objects in Channel itself:
102108
//
103109
// Upon receipt of an HTLC from a peer, we'll give it a PendingHTLCStatus indicating if it should
@@ -7550,20 +7556,32 @@ where
75507556
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
75517557
pub fn create_offer_builder(
75527558
&self, description: String
7553-
) -> Result<OfferBuilder<DerivedMetadata, secp256k1::All>, Bolt12SemanticError> {
7559+
) -> Result<OfferBuilder, Bolt12SemanticError> {
75547560
let node_id = self.get_our_node_id();
75557561
let expanded_key = &self.inbound_payment_key;
75567562
let entropy = &*self.entropy_source;
7557-
let secp_ctx = &self.secp_ctx;
75587563

75597564
let path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
7560-
let builder = OfferBuilder::deriving_signing_pubkey(
7561-
description, node_id, expanded_key, entropy, secp_ctx
7562-
)
7563-
.chain_hash(self.chain_hash)
7564-
.path(path);
75657565

7566-
Ok(builder)
7566+
#[cfg(not(c_bindings))] {
7567+
let builder = OfferBuilder::deriving_signing_pubkey(
7568+
description, node_id, expanded_key, entropy, &self.secp_ctx
7569+
)
7570+
.chain_hash(self.chain_hash)
7571+
.path(path);
7572+
7573+
Ok(builder)
7574+
}
7575+
7576+
#[cfg(c_bindings)] {
7577+
let mut builder = OfferBuilder::deriving_signing_pubkey(
7578+
description, node_id, expanded_key, entropy, &self.secp_ctx
7579+
);
7580+
builder.chain_hash(self.chain_hash);
7581+
builder.path(path);
7582+
7583+
Ok(builder)
7584+
}
75677585
}
75687586

75697587
/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the

lightning/src/offers/invoice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,8 @@ mod tests {
16441644
],
16451645
};
16461646

1647+
#[cfg(c_bindings)]
1648+
use crate::offers::offer::OfferWithDerivedMetadataBuilder as OfferBuilder;
16471649
let offer = OfferBuilder
16481650
::deriving_signing_pubkey(desc, node_id, &expanded_key, &entropy, &secp_ctx)
16491651
.amount_msats(1000)

0 commit comments

Comments
 (0)