Skip to content

Commit 2c65d6a

Browse files
f reworking PR by allowing passing an wrapper enum
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 8ba0498 commit 2c65d6a

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

lightning/src/events/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, Paym
2323
use crate::chain::transaction;
2424
use crate::ln::channelmanager::{InterceptId, PaymentId, RecipientOnionFields};
2525
use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
26+
use crate::offers::OfferInvoice;
2627
use crate::types::features::ChannelTypeFeatures;
2728
use crate::ln::msgs;
2829
use crate::ln::types::ChannelId;
@@ -955,7 +956,7 @@ pub enum Event {
955956
/// payment hash. A third party can verify that the payment was made by
956957
/// showing the invoice and confirming that the payment hash matches
957958
/// the hash of the payment preimage.
958-
bolt12_invoice: Option<Bolt12Invoice>,
959+
bolt12_invoice: Option<OfferInvoice>,
959960
},
960961
/// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events
961962
/// provide failure information for each path attempt in the payment, including retries.

lightning/src/ln/outbound_payment.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::ln::onion_utils::{DecodedOnionFailure, HTLCFailReason};
2424
use crate::offers::invoice::Bolt12Invoice;
2525
use crate::offers::invoice_request::InvoiceRequest;
2626
use crate::offers::nonce::Nonce;
27+
use crate::offers::OfferInvoice;
2728
use crate::routing::router::{BlindedTail, InFlightHtlcs, RouteParametersConfig, Path, PaymentParameters, Route, RouteParameters, Router};
2829
use crate::sign::{EntropySource, NodeSigner, Recipient};
2930
use crate::util::errors::APIError;
@@ -107,7 +108,7 @@ pub(crate) enum PendingOutboundPayment {
107108
invoice_request: Option<InvoiceRequest>,
108109
// Storing the bolt12 invoice here to allow Proof of Payment after
109110
// the payment is made.
110-
bolt12_invoice: Option<Bolt12Invoice>,
111+
bolt12_invoice: Option<OfferInvoice>,
111112
custom_tlvs: Vec<(u64, Vec<u8>)>,
112113
pending_amt_msat: u64,
113114
/// Used to track the fee paid. Present iff the payment was serialized on 0.0.103+.
@@ -157,7 +158,7 @@ impl_writeable_tlv_based!(RetryableInvoiceRequest, {
157158
});
158159

159160
impl PendingOutboundPayment {
160-
fn bolt12_invoice(&self) -> Option<&Bolt12Invoice> {
161+
fn bolt12_invoice(&self) -> Option<&OfferInvoice> {
161162
match self {
162163
PendingOutboundPayment::Retryable { bolt12_invoice, .. } => bolt12_invoice.as_ref(),
163164
_ => None,
@@ -906,8 +907,9 @@ impl OutboundPayments {
906907
if let Some(max_fee_msat) = params_config.max_total_routing_fee_msat {
907908
route_params.max_total_routing_fee_msat = Some(max_fee_msat);
908909
}
910+
let invoice = OfferInvoice::Bolt12Invoice(invoice.clone());
909911
self.send_payment_for_bolt12_invoice_internal(
910-
payment_id, payment_hash, None, None, Some(invoice), route_params, retry_strategy, router, first_hops,
912+
payment_id, payment_hash, None, None, Some(&invoice), route_params, retry_strategy, router, first_hops,
911913
inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx, best_block_height,
912914
logger, pending_events, send_payment_along_path
913915
)
@@ -918,7 +920,7 @@ impl OutboundPayments {
918920
>(
919921
&self, payment_id: PaymentId, payment_hash: PaymentHash,
920922
keysend_preimage: Option<PaymentPreimage>, invoice_request: Option<&InvoiceRequest>,
921-
bolt12_invoice: Option<&Bolt12Invoice>,
923+
bolt12_invoice: Option<&OfferInvoice>,
922924
mut route_params: RouteParameters, retry_strategy: Retry, router: &R,
923925
first_hops: Vec<ChannelDetails>, inflight_htlcs: IH, entropy_source: &ES, node_signer: &NS,
924926
node_id_lookup: &NL, secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
@@ -1665,7 +1667,7 @@ impl OutboundPayments {
16651667
&self, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, payment_id: PaymentId,
16661668
keysend_preimage: Option<PaymentPreimage>, route: &Route, retry_strategy: Option<Retry>,
16671669
payment_params: Option<PaymentParameters>, entropy_source: &ES, best_block_height: u32,
1668-
bolt12_invoice: Option<Bolt12Invoice>
1670+
bolt12_invoice: Option<OfferInvoice>
16691671
) -> Result<Vec<[u8; 32]>, PaymentSendFailure> where ES::Target: EntropySource {
16701672
let mut pending_outbounds = self.pending_outbound_payments.lock().unwrap();
16711673
match pending_outbounds.entry(payment_id) {
@@ -1684,7 +1686,7 @@ impl OutboundPayments {
16841686
fn create_pending_payment<ES: Deref>(
16851687
payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
16861688
keysend_preimage: Option<PaymentPreimage>, invoice_request: Option<InvoiceRequest>,
1687-
bolt12_invoice: Option<Bolt12Invoice>, route: &Route, retry_strategy: Option<Retry>,
1689+
bolt12_invoice: Option<OfferInvoice>, route: &Route, retry_strategy: Option<Retry>,
16881690
payment_params: Option<PaymentParameters>, entropy_source: &ES, best_block_height: u32
16891691
) -> (PendingOutboundPayment, Vec<[u8; 32]>)
16901692
where

lightning/src/offers/mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,30 @@ pub(crate) mod signer;
2929
pub mod static_invoice;
3030
#[cfg(test)]
3131
pub(crate) mod test_utils;
32+
33+
/// Wrapper time to move the bolt12 invoice and the static invoice across the same event as a unique
34+
/// type.
35+
// P.S: `OfferInvoice` is confusing, offer is containing the info for asking an invoice :) but I will leave
36+
// this up to the reviewer that I am sure that will find a better name!
37+
#[derive(Clone, PartialEq, Eq, Debug)]
38+
pub enum OfferInvoice {
39+
/// Bolt12 invoice
40+
Bolt12Invoice(invoice::Bolt12Invoice),
41+
#[cfg(async_payments)]
42+
/// Static invoice
43+
StaticInvoice(static_invoice::StaticInvoice),
44+
}
45+
46+
// FIXME(vincenzopalazzo): I do not think there is a way (easy and trivial) that adds cfg to the macro, so
47+
// when we remove the cfg will be removed we can merge these two macro in two.
48+
impl_writeable_tlv_based_enum_legacy!(OfferInvoice,
49+
;
50+
(0, Bolt12Invoice),
51+
);
52+
53+
#[cfg(async_payments)]
54+
impl_writeable_tlv_based_enum_legacy!(OfferInvoice,
55+
;
56+
(0, Bolt12Invoice),
57+
(2, StaticInvoice)
58+
);

0 commit comments

Comments
 (0)