@@ -58,10 +58,11 @@ use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
58
58
use crate::ln::outbound_payment;
59
59
use crate::ln::outbound_payment::{Bolt12PaymentError, OutboundPayments, PaymentAttempts, PendingOutboundPayment, SendAlongPathArgs, StaleExpiration};
60
60
use crate::ln::wire::Encode;
61
- use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, InvoiceBuilder};
61
+ use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice };
62
62
use crate::offers::invoice_error::InvoiceError;
63
+ use crate::offers::invoice_request::{DerivedPayerId, InvoiceRequestBuilder};
63
64
use crate::offers::merkle::SignError;
64
- use crate::offers::offer::{DerivedMetadata, Offer, OfferBuilder};
65
+ use crate::offers::offer::{Offer, OfferBuilder};
65
66
use crate::offers::parse::Bolt12SemanticError;
66
67
use crate::offers::refund::{Refund, RefundBuilder};
67
68
use crate::onion_message::messenger::{Destination, MessageRouter, PendingOnionMessage, new_pending_onion_message};
@@ -77,11 +78,17 @@ use crate::util::logger::{Level, Logger, WithContext};
77
78
use crate::util::errors::APIError;
78
79
#[cfg(not(c_bindings))]
79
80
use {
81
+ crate::offers::offer::DerivedMetadata,
80
82
crate::routing::router::DefaultRouter,
81
83
crate::routing::gossip::NetworkGraph,
82
84
crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters},
83
85
crate::sign::KeysManager,
84
86
};
87
+ #[cfg(c_bindings)]
88
+ use {
89
+ crate::offers::offer::OfferWithDerivedMetadataBuilder,
90
+ crate::offers::refund::RefundMaybeWithDerivedMetadataBuilder,
91
+ };
85
92
86
93
use alloc::collections::{btree_map, BTreeMap};
87
94
@@ -7633,7 +7640,9 @@ where
7633
7640
self.finish_close_channel(failure);
7634
7641
}
7635
7642
}
7643
+ }
7636
7644
7645
+ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
7637
7646
/// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
7638
7647
/// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer. The offer will
7639
7648
/// not have an expiration unless otherwise set on the builder.
@@ -7662,23 +7671,25 @@ where
7662
7671
/// [`Offer`]: crate::offers::offer::Offer
7663
7672
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
7664
7673
pub fn create_offer_builder(
7665
- &self, description: String
7666
- ) -> Result<OfferBuilder<DerivedMetadata, secp256k1::All> , Bolt12SemanticError> {
7667
- let node_id = self.get_our_node_id();
7668
- let expanded_key = &self.inbound_payment_key;
7669
- let entropy = &*self.entropy_source;
7670
- let secp_ctx = &self.secp_ctx;
7671
-
7672
- let path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
7674
+ &$ self, description: String
7675
+ ) -> Result<$builder , Bolt12SemanticError> {
7676
+ let node_id = $ self.get_our_node_id();
7677
+ let expanded_key = &$ self.inbound_payment_key;
7678
+ let entropy = &*$ self.entropy_source;
7679
+ let secp_ctx = &$ self.secp_ctx;
7680
+
7681
+ let path = $ self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
7673
7682
let builder = OfferBuilder::deriving_signing_pubkey(
7674
7683
description, node_id, expanded_key, entropy, secp_ctx
7675
7684
)
7676
- .chain_hash(self.chain_hash)
7685
+ .chain_hash($ self.chain_hash)
7677
7686
.path(path);
7678
7687
7679
- Ok(builder)
7688
+ Ok(builder.into() )
7680
7689
}
7690
+ } }
7681
7691
7692
+ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
7682
7693
/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
7683
7694
/// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
7684
7695
///
@@ -7728,31 +7739,53 @@ where
7728
7739
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
7729
7740
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
7730
7741
pub fn create_refund_builder(
7731
- &self, description: String, amount_msats: u64, absolute_expiry: Duration,
7742
+ &$ self, description: String, amount_msats: u64, absolute_expiry: Duration,
7732
7743
payment_id: PaymentId, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
7733
- ) -> Result<RefundBuilder<secp256k1::All> , Bolt12SemanticError> {
7734
- let node_id = self.get_our_node_id();
7735
- let expanded_key = &self.inbound_payment_key;
7736
- let entropy = &*self.entropy_source;
7737
- let secp_ctx = &self.secp_ctx;
7744
+ ) -> Result<$builder , Bolt12SemanticError> {
7745
+ let node_id = $ self.get_our_node_id();
7746
+ let expanded_key = &$ self.inbound_payment_key;
7747
+ let entropy = &*$ self.entropy_source;
7748
+ let secp_ctx = &$ self.secp_ctx;
7738
7749
7739
- let path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
7750
+ let path = $ self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
7740
7751
let builder = RefundBuilder::deriving_payer_id(
7741
7752
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
7742
7753
)?
7743
- .chain_hash(self.chain_hash)
7754
+ .chain_hash($ self.chain_hash)
7744
7755
.absolute_expiry(absolute_expiry)
7745
7756
.path(path);
7746
7757
7747
7758
let expiration = StaleExpiration::AbsoluteTimeout(absolute_expiry);
7748
- self.pending_outbound_payments
7759
+ $ self.pending_outbound_payments
7749
7760
.add_new_awaiting_invoice(
7750
7761
payment_id, expiration, retry_strategy, max_total_routing_fee_msat,
7751
7762
)
7752
7763
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
7753
7764
7754
- Ok(builder)
7765
+ Ok(builder.into() )
7755
7766
}
7767
+ } }
7768
+
7769
+ impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref> ChannelManager<M, T, ES, NS, SP, F, R, L>
7770
+ where
7771
+ M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
7772
+ T::Target: BroadcasterInterface,
7773
+ ES::Target: EntropySource,
7774
+ NS::Target: NodeSigner,
7775
+ SP::Target: SignerProvider,
7776
+ F::Target: FeeEstimator,
7777
+ R::Target: Router,
7778
+ L::Target: Logger,
7779
+ {
7780
+ #[cfg(not(c_bindings))]
7781
+ create_offer_builder!(self, OfferBuilder<DerivedMetadata, secp256k1::All>);
7782
+ #[cfg(not(c_bindings))]
7783
+ create_refund_builder!(self, RefundBuilder<secp256k1::All>);
7784
+
7785
+ #[cfg(c_bindings)]
7786
+ create_offer_builder!(self, OfferWithDerivedMetadataBuilder);
7787
+ #[cfg(c_bindings)]
7788
+ create_refund_builder!(self, RefundMaybeWithDerivedMetadataBuilder);
7756
7789
7757
7790
/// Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
7758
7791
/// enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
@@ -7816,9 +7849,11 @@ where
7816
7849
let entropy = &*self.entropy_source;
7817
7850
let secp_ctx = &self.secp_ctx;
7818
7851
7819
- let builder = offer
7852
+ let builder: InvoiceRequestBuilder<DerivedPayerId, secp256k1::All> = offer
7820
7853
.request_invoice_deriving_payer_id(expanded_key, entropy, secp_ctx, payment_id)?
7821
- .chain_hash(self.chain_hash)?;
7854
+ .into();
7855
+ let builder = builder.chain_hash(self.chain_hash)?;
7856
+
7822
7857
let builder = match quantity {
7823
7858
None => builder,
7824
7859
Some(quantity) => builder.quantity(quantity)?,
@@ -7912,6 +7947,7 @@ where
7912
7947
let builder = refund.respond_using_derived_keys_no_std(
7913
7948
payment_paths, payment_hash, created_at, expanded_key, entropy
7914
7949
)?;
7950
+ let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
7915
7951
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
7916
7952
let reply_path = self.create_blinded_path()
7917
7953
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
@@ -9424,6 +9460,8 @@ where
9424
9460
let builder = invoice_request.respond_using_derived_keys_no_std(
9425
9461
payment_paths, payment_hash, created_at
9426
9462
);
9463
+ let builder: Result<InvoiceBuilder<DerivedSigningPubkey>, _> =
9464
+ builder.map(|b| b.into());
9427
9465
match builder.and_then(|b| b.allow_mpp().build_and_sign(secp_ctx)) {
9428
9466
Ok(invoice) => Some(OffersMessage::Invoice(invoice)),
9429
9467
Err(error) => Some(OffersMessage::InvoiceError(error.into())),
@@ -9435,18 +9473,25 @@ where
9435
9473
let builder = invoice_request.respond_with_no_std(
9436
9474
payment_paths, payment_hash, created_at
9437
9475
);
9476
+ let builder: Result<InvoiceBuilder<ExplicitSigningPubkey>, _> =
9477
+ builder.map(|b| b.into());
9438
9478
let response = builder.and_then(|builder| builder.allow_mpp().build())
9439
9479
.map_err(|e| OffersMessage::InvoiceError(e.into()))
9440
- .and_then(|invoice|
9441
- match invoice.sign(|invoice| self.node_signer.sign_bolt12_invoice(invoice)) {
9480
+ .and_then(|invoice| {
9481
+ #[cfg(c_bindings)]
9482
+ let mut invoice = invoice;
9483
+ match invoice.sign(|invoice: &UnsignedBolt12Invoice|
9484
+ self.node_signer.sign_bolt12_invoice(invoice)
9485
+ ) {
9442
9486
Ok(invoice) => Ok(OffersMessage::Invoice(invoice)),
9443
- Err(SignError::Signing(()) ) => Err(OffersMessage::InvoiceError(
9487
+ Err(SignError::Signing) => Err(OffersMessage::InvoiceError(
9444
9488
InvoiceError::from_string("Failed signing invoice".to_string())
9445
9489
)),
9446
9490
Err(SignError::Verification(_)) => Err(OffersMessage::InvoiceError(
9447
9491
InvoiceError::from_string("Failed invoice signature verification".to_string())
9448
9492
)),
9449
- });
9493
+ }
9494
+ });
9450
9495
match response {
9451
9496
Ok(invoice) => Some(invoice),
9452
9497
Err(error) => Some(error),
0 commit comments