Skip to content

Commit a0641a2

Browse files
vincenzopalazzoAI Assistant
andcommitted
Update BOLT12 payer proof API for upstream LDK PR #4297
- Bump rust-lightning rev from f5c24c6 to c836395 - PaidBolt12Invoice changed from enum (lightning::events) to struct (lightning::offers::payer_proof) - New Bolt12InvoiceType enum replaces old PaidBolt12Invoice variants - OptionalOfferPaymentParams lost contact_secrets/payer_offer fields - PayerProofContextStore is now in-memory only since PaidBolt12Invoice cannot be serialized or reconstructed externally (new/nonce/invoice_type are all pub(crate) in LDK) - Removed payment_nonce field from Event::PaymentSuccessful - Removed read_payer_proof_contexts and related persistence constants - cfg-gated Bolt12InvoiceType vs FFI PaidBolt12Invoice for uniffi compat Co-authored-by: AI Assistant <ai@lightningdevkit.org>
1 parent dc6012f commit a0641a2

File tree

11 files changed

+168
-305
lines changed

11 files changed

+168
-305
lines changed

Cargo.toml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ default = []
3939
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
4040
#lightning-macros = { version = "0.2.0" }
4141

42-
lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["std"] }
43-
lightning-types = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
44-
lightning-invoice = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["std"] }
45-
lightning-net-tokio = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
46-
lightning-persister = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["tokio"] }
47-
lightning-background-processor = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
48-
lightning-rapid-gossip-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
49-
lightning-block-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["rest-client", "rpc-client", "tokio"] }
50-
lightning-transaction-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51-
lightning-liquidity = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["std"] }
52-
lightning-macros = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
42+
lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085", features = ["std"] }
43+
lightning-types = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
44+
lightning-invoice = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085", features = ["std"] }
45+
lightning-net-tokio = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
46+
lightning-persister = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085", features = ["tokio"] }
47+
lightning-background-processor = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
48+
lightning-rapid-gossip-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
49+
lightning-block-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085", features = ["rest-client", "rpc-client", "tokio"] }
50+
lightning-transaction-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51+
lightning-liquidity = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085", features = ["std"] }
52+
lightning-macros = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
5353

5454
bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
5555
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
@@ -85,7 +85,7 @@ bitcoin-payment-instructions = { git = "https://github.com/joostjager/bitcoin-pa
8585
winapi = { version = "0.3", features = ["winbase"] }
8686

8787
[dev-dependencies]
88-
lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["std", "_test_utils"] }
88+
lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085", features = ["std", "_test_utils"] }
8989
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
9090
proptest = "1.0.0"
9191
regex = "1.5.6"
@@ -173,14 +173,14 @@ harness = false
173173
#vss-client-ng = { git = "https://github.com/lightningdevkit/vss-client", branch = "main" }
174174
#
175175
[patch."https://github.com/lightningdevkit/rust-lightning"]
176-
lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
177-
lightning-types = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
178-
lightning-invoice = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
179-
lightning-net-tokio = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
180-
lightning-persister = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
181-
lightning-background-processor = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
182-
lightning-rapid-gossip-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
183-
lightning-block-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
184-
lightning-transaction-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
185-
lightning-liquidity = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
186-
lightning-macros = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
176+
lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
177+
lightning-types = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
178+
lightning-invoice = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
179+
lightning-net-tokio = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
180+
lightning-persister = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
181+
lightning-background-processor = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
182+
lightning-rapid-gossip-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
183+
lightning-block-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
184+
lightning-transaction-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
185+
lightning-liquidity = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }
186+
lightning-macros = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "c8363950d753f954b47d2bf4aaff07928c86b085" }

src/builder.rs

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,12 @@ use crate::gossip::GossipSource;
5656
use crate::io::sqlite_store::SqliteStore;
5757
use crate::io::utils::{
5858
read_event_queue, read_external_pathfinding_scores_from_cache, read_network_graph,
59-
read_node_metrics, read_output_sweeper, read_payer_proof_contexts, read_payments,
60-
read_peer_info, read_pending_payments, read_scorer, write_node_metrics,
59+
read_node_metrics, read_output_sweeper, read_payments, read_peer_info, read_pending_payments,
60+
read_scorer, write_node_metrics,
6161
};
6262
use crate::io::vss_store::VssStoreBuilder;
6363
use crate::io::{
64-
self, PAYER_PROOF_CONTEXT_PERSISTENCE_PRIMARY_NAMESPACE,
65-
PAYER_PROOF_CONTEXT_PERSISTENCE_SECONDARY_NAMESPACE,
66-
PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE, PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE,
64+
self, PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE, PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE,
6765
PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE,
6866
PENDING_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE,
6967
};
@@ -1262,19 +1260,14 @@ fn build_with_store_internal(
12621260

12631261
let kv_store_ref = Arc::clone(&kv_store);
12641262
let logger_ref = Arc::clone(&logger);
1265-
let (
1266-
payment_store_res,
1267-
node_metris_res,
1268-
pending_payment_store_res,
1269-
payer_proof_context_store_res,
1270-
) = runtime.block_on(async move {
1271-
tokio::join!(
1272-
read_payments(&*kv_store_ref, Arc::clone(&logger_ref)),
1273-
read_node_metrics(&*kv_store_ref, Arc::clone(&logger_ref)),
1274-
read_pending_payments(&*kv_store_ref, Arc::clone(&logger_ref)),
1275-
read_payer_proof_contexts(&*kv_store_ref, Arc::clone(&logger_ref))
1276-
)
1277-
});
1263+
let (payment_store_res, node_metris_res, pending_payment_store_res) =
1264+
runtime.block_on(async move {
1265+
tokio::join!(
1266+
read_payments(&*kv_store_ref, Arc::clone(&logger_ref)),
1267+
read_node_metrics(&*kv_store_ref, Arc::clone(&logger_ref)),
1268+
read_pending_payments(&*kv_store_ref, Arc::clone(&logger_ref)),
1269+
)
1270+
});
12781271

12791272
// Initialize the status fields.
12801273
let node_metrics = match node_metris_res {
@@ -1303,19 +1296,7 @@ fn build_with_store_internal(
13031296
},
13041297
};
13051298

1306-
let payer_proof_context_store = match payer_proof_context_store_res {
1307-
Ok(contexts) => Arc::new(PayerProofContextStore::new(
1308-
contexts,
1309-
PAYER_PROOF_CONTEXT_PERSISTENCE_PRIMARY_NAMESPACE.to_string(),
1310-
PAYER_PROOF_CONTEXT_PERSISTENCE_SECONDARY_NAMESPACE.to_string(),
1311-
Arc::clone(&kv_store),
1312-
Arc::clone(&logger),
1313-
)),
1314-
Err(e) => {
1315-
log_error!(logger, "Failed to read payer proof contexts from store: {}", e);
1316-
return Err(BuildError::ReadFailed);
1317-
},
1318-
};
1299+
let payer_proof_context_store = Arc::new(PayerProofContextStore::new());
13191300

13201301
let (chain_source, chain_tip_opt) = match chain_data_source_config {
13211302
Some(ChainDataSourceConfig::Esplora { server_url, headers, sync_config }) => {

src/event.rs

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ use bitcoin::blockdata::locktime::absolute::LockTime;
1515
use bitcoin::secp256k1::PublicKey;
1616
use bitcoin::{Amount, OutPoint};
1717
use lightning::events::bump_transaction::BumpTransactionEvent;
18-
#[cfg(not(feature = "uniffi"))]
19-
use lightning::events::PaidBolt12Invoice;
2018
use lightning::events::{
2119
ClosureReason, Event as LdkEvent, FundingInfo, PaymentFailureReason, PaymentPurpose,
2220
ReplayEvent,
2321
};
2422
use lightning::impl_writeable_tlv_based_enum;
2523
use lightning::ln::channelmanager::PaymentId;
2624
use lightning::ln::types::ChannelId;
27-
use lightning::offers::nonce::Nonce;
25+
#[cfg(not(feature = "uniffi"))]
26+
use lightning::offers::payer_proof::Bolt12InvoiceType;
27+
use lightning::offers::payer_proof::PaidBolt12Invoice;
2828
use lightning::routing::gossip::NodeId;
2929
use lightning::sign::EntropySource;
3030
use lightning::util::config::{
@@ -41,7 +41,7 @@ use crate::connection::ConnectionManager;
4141
use crate::data_store::DataStoreUpdateResult;
4242
use crate::fee_estimator::ConfirmationTarget;
4343
#[cfg(feature = "uniffi")]
44-
use crate::ffi::PaidBolt12Invoice;
44+
use crate::ffi::PaidBolt12Invoice as FfiPaidBolt12Invoice;
4545
use crate::io::{
4646
EVENT_QUEUE_PERSISTENCE_KEY, EVENT_QUEUE_PERSISTENCE_PRIMARY_NAMESPACE,
4747
EVENT_QUEUE_PERSISTENCE_SECONDARY_NAMESPACE,
@@ -50,7 +50,6 @@ use crate::liquidity::LiquiditySource;
5050
use crate::logger::{log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
5151
use crate::payment::asynchronous::om_mailbox::OnionMessageMailbox;
5252
use crate::payment::asynchronous::static_invoice_store::StaticInvoiceStore;
53-
use crate::payment::payer_proof_store::PayerProofContext;
5453
use crate::payment::store::{
5554
PaymentDetails, PaymentDetailsUpdate, PaymentDirection, PaymentKind, PaymentStatus,
5655
};
@@ -64,6 +63,11 @@ use crate::{
6463
UserChannelId,
6564
};
6665

66+
#[cfg(not(feature = "uniffi"))]
67+
type Bolt12InvoiceInfo = Bolt12InvoiceType;
68+
#[cfg(feature = "uniffi")]
69+
type Bolt12InvoiceInfo = FfiPaidBolt12Invoice;
70+
6771
/// An event emitted by [`Node`], which should be handled by the user.
6872
///
6973
/// [`Node`]: [`crate::Node`]
@@ -86,17 +90,16 @@ pub enum Event {
8690
payment_preimage: Option<PaymentPreimage>,
8791
/// The total fee which was spent at intermediate hops in this payment.
8892
fee_paid_msat: Option<u64>,
89-
/// The BOLT12 invoice that was paid.
93+
/// The BOLT12 invoice type that was paid.
9094
///
9195
/// This is useful for proof of payment. A third party can verify that the payment was made
9296
/// by checking that the `payment_hash` in the invoice matches `sha256(payment_preimage)`.
9397
///
9498
/// Will be `None` for non-BOLT12 payments.
9599
///
96-
/// Note that static invoices (indicated by [`PaidBolt12Invoice::StaticInvoice`], used for
97-
/// async payments) do not support proof of payment as the payment hash is not derived
98-
/// from a preimage known only to the recipient.
99-
bolt12_invoice: Option<PaidBolt12Invoice>,
100+
/// Note that static invoices (via [`Bolt12InvoiceType::StaticInvoice`], used for
101+
/// async payments) do not support payer proofs.
102+
bolt12_invoice: Option<Bolt12InvoiceInfo>,
100103
},
101104
/// A sent payment has failed.
102105
PaymentFailed {
@@ -560,33 +563,12 @@ where
560563
}
561564

562565
fn persist_payer_proof_context(
563-
&self, payment_id: PaymentId, bolt12_invoice: &Option<PaidBolt12Invoice>,
564-
payment_nonce: Option<Nonce>,
566+
&self, payment_id: PaymentId, paid_invoice: &Option<PaidBolt12Invoice>,
565567
) {
566-
#[cfg(not(feature = "uniffi"))]
567-
let invoice = match bolt12_invoice {
568-
Some(PaidBolt12Invoice::Bolt12Invoice(invoice)) => invoice.clone(),
569-
_ => return,
570-
};
571-
#[cfg(feature = "uniffi")]
572-
let invoice = match bolt12_invoice {
573-
Some(PaidBolt12Invoice::Bolt12(invoice)) => invoice.inner.clone(),
574-
_ => return,
575-
};
576-
577-
let nonce = match payment_nonce {
578-
Some(nonce) => nonce,
579-
None => return,
580-
};
581-
582-
let context = PayerProofContext { payment_id, invoice, nonce };
583-
if let Err(e) = self.payer_proof_context_store.insert_or_update(context) {
584-
log_error!(
585-
self.logger,
586-
"Failed to persist payer proof context for {}: {}",
587-
payment_id,
588-
e
589-
);
568+
if let Some(paid_invoice) = paid_invoice {
569+
if paid_invoice.bolt12_invoice().is_some() {
570+
self.payer_proof_context_store.insert_or_update(payment_id, paid_invoice.clone());
571+
}
590572
}
591573
}
592574

@@ -1103,7 +1085,6 @@ where
11031085
payment_hash,
11041086
fee_paid_msat,
11051087
bolt12_invoice,
1106-
payment_nonce,
11071088
..
11081089
} => {
11091090
let payment_id = if let Some(id) = payment_id {
@@ -1112,16 +1093,29 @@ where
11121093
debug_assert!(false, "payment_id should always be set.");
11131094
return Ok(());
11141095
};
1115-
let bolt12_invoice = bolt12_invoice.map(Into::into);
11161096

1117-
self.persist_payer_proof_context(payment_id, &bolt12_invoice, payment_nonce);
1097+
self.persist_payer_proof_context(payment_id, &bolt12_invoice);
1098+
1099+
#[cfg(not(feature = "uniffi"))]
1100+
let bolt12_invoice_info: Option<Bolt12InvoiceInfo> = bolt12_invoice
1101+
.as_ref()
1102+
.and_then(|p| {
1103+
p.bolt12_invoice().map(|i| Bolt12InvoiceType::Bolt12Invoice(i.clone()))
1104+
})
1105+
.or_else(|| {
1106+
bolt12_invoice.as_ref().and_then(|p| {
1107+
p.static_invoice().map(|i| Bolt12InvoiceType::StaticInvoice(i.clone()))
1108+
})
1109+
});
1110+
#[cfg(feature = "uniffi")]
1111+
let bolt12_invoice_info: Option<Bolt12InvoiceInfo> = bolt12_invoice.map(|p| p.into());
11181112

11191113
let update = PaymentDetailsUpdate {
11201114
hash: Some(Some(payment_hash)),
11211115
preimage: Some(Some(payment_preimage)),
11221116
fee_paid_msat: Some(fee_paid_msat),
11231117
status: Some(PaymentStatus::Succeeded),
1124-
bolt12_invoice: Some(bolt12_invoice.clone()),
1118+
bolt12_invoice: Some(bolt12_invoice_info.clone()),
11251119
..PaymentDetailsUpdate::new(payment_id)
11261120
};
11271121

@@ -1153,7 +1147,7 @@ where
11531147
payment_hash,
11541148
payment_preimage: Some(payment_preimage),
11551149
fee_paid_msat,
1156-
bolt12_invoice,
1150+
bolt12_invoice: bolt12_invoice_info,
11571151
};
11581152

11591153
match self.event_queue.add_event(event).await {

src/ffi/types.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ use bitcoin::hashes::Hash;
2323
use bitcoin::secp256k1::PublicKey;
2424
pub use bitcoin::{Address, BlockHash, Network, OutPoint, ScriptBuf, Txid};
2525
pub use lightning::chain::channelmonitor::BalanceSource;
26-
use lightning::events::PaidBolt12Invoice as LdkPaidBolt12Invoice;
2726
pub use lightning::events::{ClosureReason, PaymentFailureReason};
2827
use lightning::ln::channelmanager::PaymentId;
2928
use lightning::ln::msgs::DecodeError;
3029
pub use lightning::ln::types::ChannelId;
3130
use lightning::offers::invoice::Bolt12Invoice as LdkBolt12Invoice;
3231
pub use lightning::offers::offer::OfferId;
3332
use lightning::offers::offer::{Amount as LdkAmount, Offer as LdkOffer};
34-
use lightning::offers::payer_proof::PayerProof as LdkPayerProof;
33+
use lightning::offers::payer_proof::{
34+
Bolt12InvoiceType as LdkBolt12InvoiceType, PaidBolt12Invoice as LdkPaidBolt12Invoice,
35+
PayerProof as LdkPayerProof,
36+
};
3537
use lightning::offers::refund::Refund as LdkRefund;
3638
use lightning::offers::static_invoice::StaticInvoice as LdkStaticInvoice;
3739
use lightning::onion_message::dns_resolution::HumanReadableName as LdkHumanReadableName;
@@ -837,42 +839,41 @@ pub enum PaidBolt12Invoice {
837839

838840
impl From<LdkPaidBolt12Invoice> for PaidBolt12Invoice {
839841
fn from(ldk: LdkPaidBolt12Invoice) -> Self {
840-
match ldk {
841-
LdkPaidBolt12Invoice::Bolt12Invoice(invoice) => {
842-
PaidBolt12Invoice::Bolt12(Arc::new(Bolt12Invoice::from(invoice)))
843-
},
844-
LdkPaidBolt12Invoice::StaticInvoice(invoice) => {
845-
PaidBolt12Invoice::Static(Arc::new(StaticInvoice::from(invoice)))
846-
},
842+
if let Some(invoice) = ldk.bolt12_invoice() {
843+
PaidBolt12Invoice::Bolt12(Arc::new(Bolt12Invoice::from(invoice.clone())))
844+
} else if let Some(invoice) = ldk.static_invoice() {
845+
PaidBolt12Invoice::Static(Arc::new(StaticInvoice::from(invoice.clone())))
846+
} else {
847+
panic!("PaidBolt12Invoice must contain either a Bolt12Invoice or StaticInvoice")
847848
}
848849
}
849850
}
850851

851-
impl From<PaidBolt12Invoice> for LdkPaidBolt12Invoice {
852-
fn from(wrapper: PaidBolt12Invoice) -> Self {
853-
match wrapper {
852+
impl Writeable for PaidBolt12Invoice {
853+
fn write<W: Writer>(&self, w: &mut W) -> Result<(), lightning::io::Error> {
854+
let invoice_type = match self {
854855
PaidBolt12Invoice::Bolt12(invoice) => {
855-
LdkPaidBolt12Invoice::Bolt12Invoice(invoice.inner.clone())
856+
LdkBolt12InvoiceType::Bolt12Invoice(invoice.inner.clone())
856857
},
857858
PaidBolt12Invoice::Static(invoice) => {
858-
LdkPaidBolt12Invoice::StaticInvoice(invoice.inner.clone())
859+
LdkBolt12InvoiceType::StaticInvoice(invoice.inner.clone())
859860
},
860-
}
861-
}
862-
}
863-
864-
impl Writeable for PaidBolt12Invoice {
865-
fn write<W: Writer>(&self, w: &mut W) -> Result<(), lightning::io::Error> {
866-
// TODO: Find way to avoid cloning invoice data.
867-
let ldk_type: LdkPaidBolt12Invoice = self.clone().into();
868-
ldk_type.write(w)
861+
};
862+
invoice_type.write(w)
869863
}
870864
}
871865

872866
impl Readable for PaidBolt12Invoice {
873867
fn read<R: lightning::io::Read>(r: &mut R) -> Result<Self, DecodeError> {
874-
let ldk_type = LdkPaidBolt12Invoice::read(r)?;
875-
Ok(ldk_type.into())
868+
let invoice_type = LdkBolt12InvoiceType::read(r)?;
869+
Ok(match invoice_type {
870+
LdkBolt12InvoiceType::Bolt12Invoice(invoice) => {
871+
PaidBolt12Invoice::Bolt12(Arc::new(Bolt12Invoice::from(invoice)))
872+
},
873+
LdkBolt12InvoiceType::StaticInvoice(invoice) => {
874+
PaidBolt12Invoice::Static(Arc::new(StaticInvoice::from(invoice)))
875+
},
876+
})
876877
}
877878
}
878879

src/io/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,3 @@ pub(crate) const STATIC_INVOICE_STORE_PRIMARY_NAMESPACE: &str = "static_invoices
8282
/// The pending payment information will be persisted under this prefix.
8383
pub(crate) const PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE: &str = "pending_payments";
8484
pub(crate) const PENDING_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE: &str = "";
85-
86-
/// The payer proof context will be persisted under this prefix.
87-
pub(crate) const PAYER_PROOF_CONTEXT_PERSISTENCE_PRIMARY_NAMESPACE: &str = "payer_proof_contexts";
88-
pub(crate) const PAYER_PROOF_CONTEXT_PERSISTENCE_SECONDARY_NAMESPACE: &str = "";

0 commit comments

Comments
 (0)