-
Notifications
You must be signed in to change notification settings - Fork 116
Use BDK events in update_payment_store
#658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Camillarhi
wants to merge
5
commits into
lightningdevkit:main
Choose a base branch
from
Camillarhi:payment-store-events-sync
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1c2b2f6
refactor: Extract payment creation logic into `create_payment_from_tx`
Camillarhi 5f9141d
Bump BDK_Wallet to 2.3.0
Camillarhi 281f6a4
Use BDK events in `update_payment_store` instead of scanning all tran…
Camillarhi 4a17b6f
Add `contains_key` method to DataStore
Camillarhi a677335
Add RBF replacement tracking with new persisted lookup table
Camillarhi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // This file is Copyright its original authors, visible in version control history. | ||
| // | ||
| // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
| // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or | ||
| // http://opensource.org/licenses/MIT>, at your option. You may not use this file except in | ||
| // accordance with one or both of these licenses. | ||
|
|
||
| use bitcoin::Txid; | ||
| use lightning::{impl_writeable_tlv_based, ln::channelmanager::PaymentId}; | ||
|
|
||
| use crate::{ | ||
| data_store::{StorableObject, StorableObjectUpdate}, | ||
| payment::{store::PaymentDetailsUpdate, PaymentDetails}, | ||
| }; | ||
|
|
||
| /// Represents a pending payment | ||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| pub struct PendingPaymentDetails { | ||
| /// The full payment details | ||
| pub details: PaymentDetails, | ||
| /// Cached timestamp for efficient cleanup queries | ||
| pub created_at: u64, | ||
| /// Transaction IDs that have replaced or conflict with this payment. | ||
| pub conflicting_txids: Vec<Txid>, | ||
| } | ||
|
|
||
| impl PendingPaymentDetails { | ||
| pub(crate) fn new(details: PaymentDetails, conflicting_txids: Vec<Txid>) -> Self { | ||
| Self { created_at: details.latest_update_timestamp, details, conflicting_txids } | ||
| } | ||
|
|
||
| /// Convert to finalized payment for the main payment store | ||
| pub fn into_payment_details(self) -> PaymentDetails { | ||
| self.details | ||
| } | ||
| } | ||
|
|
||
| impl_writeable_tlv_based!(PendingPaymentDetails, { | ||
| (0, details, required), | ||
| (2, created_at, required), | ||
| (4, conflicting_txids, optional_vec), | ||
| }); | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| pub(crate) struct PendingPaymentDetailsUpdate { | ||
| pub id: PaymentId, | ||
| pub payment_update: Option<PaymentDetailsUpdate>, | ||
| pub conflicting_txids: Option<Vec<Txid>>, | ||
| } | ||
|
|
||
| impl StorableObject for PendingPaymentDetails { | ||
| type Id = PaymentId; | ||
| type Update = PendingPaymentDetailsUpdate; | ||
|
|
||
| fn id(&self) -> Self::Id { | ||
| self.details.id | ||
| } | ||
|
|
||
| fn update(&mut self, update: &Self::Update) -> bool { | ||
| let mut updated = false; | ||
|
|
||
| // Update the underlying payment details if present | ||
| if let Some(payment_update) = &update.payment_update { | ||
| updated |= self.details.update(payment_update); | ||
| } | ||
|
|
||
| if let Some(new_conflicting_txids) = &update.conflicting_txids { | ||
| if &self.conflicting_txids != new_conflicting_txids { | ||
| self.conflicting_txids = new_conflicting_txids.clone(); | ||
| updated = true; | ||
| } | ||
| } | ||
|
|
||
| updated | ||
| } | ||
|
|
||
| fn to_update(&self) -> Self::Update { | ||
| self.into() | ||
| } | ||
| } | ||
|
|
||
| impl StorableObjectUpdate<PendingPaymentDetails> for PendingPaymentDetailsUpdate { | ||
| fn id(&self) -> <PendingPaymentDetails as StorableObject>::Id { | ||
| self.id | ||
| } | ||
| } | ||
|
|
||
| impl From<&PendingPaymentDetails> for PendingPaymentDetailsUpdate { | ||
| fn from(value: &PendingPaymentDetails) -> Self { | ||
| Self { | ||
| id: value.id(), | ||
| payment_update: Some(value.details.to_update()), | ||
| conflicting_txids: Some(value.conflicting_txids.clone()), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the BDK bump a dedicated commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this has been updated