Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9b72246

Browse files
committedMar 3, 2025··
f play with static invoice
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
1 parent 2c65d6a commit 9b72246

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed
 

‎lightning/src/ln/outbound_payment.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ pub(crate) enum PendingOutboundPayment {
9595
retry_strategy: Retry,
9696
route_params: RouteParameters,
9797
invoice_request: InvoiceRequest,
98+
// FIXME: we should pass the invoice as a string
99+
static_invoice: String,
98100
},
99101
Retryable {
100102
retry_strategy: Option<Retry>,
@@ -989,12 +991,19 @@ impl OutboundPayments {
989991
*entry.into_mut() = retryable_payment;
990992
onion_session_privs
991993
},
992-
PendingOutboundPayment::StaticInvoiceReceived { .. } => {
994+
PendingOutboundPayment::StaticInvoiceReceived { static_invoice: _static_invoice, .. } => {
993995
let invreq = if let PendingOutboundPayment::StaticInvoiceReceived { invoice_request, .. } = entry.remove() {
994996
invoice_request
995997
} else { unreachable!() };
998+
999+
#[cfg(not(async_payments))]
1000+
let invoice: Option<OfferInvoice> = None;
1001+
#[cfg(async_payments)]
1002+
let invoice = {
1003+
None
1004+
};
9961005
let (retryable_payment, onion_session_privs) = Self::create_pending_payment(
997-
payment_hash, recipient_onion.clone(), keysend_preimage, Some(invreq), bolt12_invoice.cloned(), &route,
1006+
payment_hash, recipient_onion.clone(), keysend_preimage, Some(invreq), invoice, &route,
9981007
Some(retry_strategy), payment_params, entropy_source, best_block_height
9991008
);
10001009
outbounds.insert(payment_id, retryable_payment);
@@ -1092,6 +1101,7 @@ impl OutboundPayments {
10921101
return Err(Bolt12PaymentError::SendingFailed(RetryableSendFailure::OnionPacketSizeExceeded))
10931102
}
10941103

1104+
// Adds the static invoice here?
10951105
*entry.into_mut() = PendingOutboundPayment::StaticInvoiceReceived {
10961106
payment_hash,
10971107
keysend_preimage,
@@ -1102,6 +1112,7 @@ impl OutboundPayments {
11021112
.take()
11031113
.ok_or(Bolt12PaymentError::UnexpectedInvoice)?
11041114
.invoice_request,
1115+
static_invoice: String::from("we should have the static invoice here"),
11051116
};
11061117
return Ok(())
11071118
},
@@ -2469,6 +2480,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
24692480
(4, retry_strategy, required),
24702481
(6, route_params, required),
24712482
(8, invoice_request, required),
2483+
(10, static_invoice, required),
24722484
},
24732485
// Added in 0.1. Prior versions will drop these outbounds on downgrade, which is safe because
24742486
// no HTLCs are in-flight.

‎lightning/src/offers/invoice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ pub(super) type BlindedPayInfoIter<'a> = core::iter::Map<
14901490
>;
14911491

14921492
/// Wire representation for an on-chain fallback address.
1493-
#[derive(Clone, Debug, PartialEq)]
1493+
#[derive(Clone, Debug, PartialEq, Eq)]
14941494
pub(super) struct FallbackAddress {
14951495
pub(super) version: u8,
14961496
pub(super) program: Vec<u8>,

‎lightning/src/offers/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub enum OfferInvoice {
4545

4646
// FIXME(vincenzopalazzo): I do not think there is a way (easy and trivial) that adds cfg to the macro, so
4747
// when we remove the cfg will be removed we can merge these two macro in two.
48+
#[cfg(not(async_payments))]
4849
impl_writeable_tlv_based_enum_legacy!(OfferInvoice,
4950
;
5051
(0, Bolt12Invoice),

‎lightning/src/offers/offer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ pub struct Offer {
603603
///
604604
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
605605
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
606-
#[derive(Clone, Debug)]
606+
#[derive(Clone, Debug, PartialEq)]
607607
#[cfg_attr(test, derive(PartialEq))]
608608
pub(super) struct OfferContents {
609609
chains: Option<Vec<ChainHash>>,

‎lightning/src/offers/signer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const ASYNC_PAYMENTS_HELD_HTLC_HMAC_INPUT: &[u8; 16] = &[9; 16];
5757

5858
/// Message metadata which possibly is derived from [`MetadataMaterial`] such that it can be
5959
/// verified.
60-
#[derive(Clone)]
60+
#[derive(Clone, PartialEq, Eq)]
6161
pub(super) enum Metadata {
6262
/// Metadata as parsed, supplied by the user, or derived from the message contents.
6363
///
@@ -255,7 +255,7 @@ impl PartialEq for Metadata {
255255
}
256256

257257
/// Material used to create metadata for a message.
258-
#[derive(Clone)]
258+
#[derive(Clone, PartialEq, Eq)]
259259
pub(super) struct MetadataMaterial {
260260
nonce: Nonce,
261261
hmac: HmacEngine<Sha256>,

‎lightning/src/offers/static_invoice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub const SIGNATURE_TAG: &'static str = concat!("lightning", "static_invoice", "
6363
/// [`Offer`]: crate::offers::offer::Offer
6464
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
6565
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
66-
#[derive(Clone, Debug)]
66+
#[derive(Clone, Debug, PartialEq, Eq)]
6767
pub struct StaticInvoice {
6868
bytes: Vec<u8>,
6969
contents: InvoiceContents,
@@ -73,7 +73,7 @@ pub struct StaticInvoice {
7373
/// The contents of a [`StaticInvoice`] for responding to an [`Offer`].
7474
///
7575
/// [`Offer`]: crate::offers::offer::Offer
76-
#[derive(Clone, Debug)]
76+
#[derive(Clone, Debug, PartialEq, Eq)]
7777
struct InvoiceContents {
7878
offer: OfferContents,
7979
payment_paths: Vec<BlindedPaymentPath>,

0 commit comments

Comments
 (0)
Please sign in to comment.