Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c" }
lightning-dns-resolver = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c" }

bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
bdk_chain = { version = "0.23.3", default-features = false, features = ["std"] }
bdk_esplora = { version = "0.22.2", default-features = false, features = ["async-https-rustls", "tokio"]}
bdk_electrum = { version = "0.24.0", default-features = false, features = ["use-rustls-ring"]}
bdk_wallet = { version = "2.3.0", default-features = false, features = ["std", "keys-bip39"]}
bdk_wallet = { version = "3.0.0", default-features = false, features = ["std", "keys-bip39"]}

bitreq = { version = "0.3", default-features = false, features = ["async-https", "json-using-serde"] }
rustls = { version = "0.23", default-features = false }
Expand Down
8 changes: 4 additions & 4 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub(crate) const PEER_INFO_PERSISTENCE_KEY: &str = "peers";
pub(crate) const PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE: &str = "payments";
pub(crate) const PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE: &str = "";

/// The pending payment information will be persisted under this prefix.
pub(crate) const PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE: &str = "pending_payments";
pub(crate) const PENDING_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE: &str = "";

/// The node metrics will be persisted under this key.
pub(crate) const NODE_METRICS_PRIMARY_NAMESPACE: &str = "";
pub(crate) const NODE_METRICS_SECONDARY_NAMESPACE: &str = "";
Expand Down Expand Up @@ -80,7 +84,3 @@ pub(crate) const BDK_WALLET_INDEXER_KEY: &str = "indexer";
///
/// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
pub(crate) const STATIC_INVOICE_STORE_PRIMARY_NAMESPACE: &str = "static_invoices";

/// The pending payment information will be persisted under this prefix.
pub(crate) const PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE: &str = "pending_payments";
pub(crate) const PENDING_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE: &str = "";
3 changes: 1 addition & 2 deletions src/payment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub(crate) mod asynchronous;
mod bolt11;
mod bolt12;
mod onchain;
pub(crate) mod pending_payment_store;
mod spontaneous;
pub(crate) mod store;
mod unified;
Expand All @@ -20,8 +19,8 @@ pub use bolt11::Bolt11Payment;
pub(crate) use bolt11::PaymentMetadata;
pub use bolt12::Bolt12Payment;
pub use onchain::OnchainPayment;
pub use pending_payment_store::PendingPaymentDetails;
pub use spontaneous::SpontaneousPayment;
pub(crate) use store::PendingPaymentDetails;
pub use store::{
ConfirmationStatus, LSPS2Parameters, PaymentDetails, PaymentDirection, PaymentKind,
PaymentStatus,
Expand Down
94 changes: 0 additions & 94 deletions src/payment/pending_payment_store.rs

This file was deleted.

81 changes: 81 additions & 0 deletions src/payment/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,87 @@ impl StorableObjectUpdate<PaymentDetails> for PaymentDetailsUpdate {
}
}

/// Represents a pending payment
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct PendingPaymentDetails {
/// The payment id tracked in the main payment store.
pub payment_id: PaymentId,
/// The canonical transaction id currently associated with the payment.
pub txid: Txid,
/// Transaction IDs that have replaced or conflict with this payment.
pub conflicting_txids: Vec<Txid>,
}

impl PendingPaymentDetails {
pub(crate) fn new(payment_id: PaymentId, txid: Txid, conflicting_txids: Vec<Txid>) -> Self {
Self { payment_id, txid, conflicting_txids }
}
}

impl_writeable_tlv_based!(PendingPaymentDetails, {
(0, payment_id, required),
(2, txid, required),
(4, conflicting_txids, optional_vec),
});

#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct PendingPaymentDetailsUpdate {
pub payment_id: PaymentId,
pub txid: Txid,
pub conflicting_txids: Vec<Txid>,
}

impl StorableObject for PendingPaymentDetails {
type Id = PaymentId;
type Update = PendingPaymentDetailsUpdate;

fn id(&self) -> Self::Id {
self.payment_id
}

fn update(&mut self, update: Self::Update) -> bool {
let mut updated = false;

if self.txid != update.txid {
let old_txid = self.txid;
self.txid = update.txid;
if old_txid != self.txid && !self.conflicting_txids.contains(&old_txid) {
self.conflicting_txids.push(old_txid);
}
updated = true;
}

for txid in update.conflicting_txids {
if txid != self.txid && !self.conflicting_txids.contains(&txid) {
self.conflicting_txids.push(txid);
updated = true;
}
}

updated
}

fn to_update(&self) -> Self::Update {
self.into()
}
}

impl StorableObjectUpdate<PendingPaymentDetails> for PendingPaymentDetailsUpdate {
fn id(&self) -> <PendingPaymentDetails as StorableObject>::Id {
self.payment_id
}
}

impl From<&PendingPaymentDetails> for PendingPaymentDetailsUpdate {
fn from(value: &PendingPaymentDetails) -> Self {
Self {
payment_id: value.id(),
txid: value.txid,
conflicting_txids: value.conflicting_txids.clone(),
}
}
}

#[cfg(test)]
mod tests {
use lightning::util::ser::{Readable, Writeable};
Expand Down
Loading