Skip to content

feat: apply_unconfirmed_txs on wallet #704

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

Merged
merged 1 commit into from
Mar 24, 2025

Conversation

reez
Copy link
Collaborator

@reez reez commented Mar 20, 2025

Description

Add apply_unconfirmed_txs to Wallet, resolving #636 potentially.

Notes to the reviewers

Created a UnconfirmedTx type, similar to how we needed to create a SentAndReceivedValues type instead of returning a tuple. Totally open to naming it something different, but just needed a type instead of a tuple.

Changelog notice

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@reez reez linked an issue Mar 20, 2025 that may be closed by this pull request
@reez reez changed the title (draft) feat: apply_unconfirmed_txs on wallet feat: apply_unconfirmed_txs on wallet Mar 21, 2025
Copy link
Member

@thunderbiscuit thunderbiscuit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few ideas.

Comment on lines 746 to 749
dictionary UnconfirmedTx {
Transaction tx;
u64 last_seen;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applying our idea of using macros when possible on changes and new things, this block here can be replaced with

typedef dictionary UnconfirmedTx;

and the Rust code can simply add

#[derive(uniffi::Record)]
pub struct UnconfirmedTx {
    pub tx: Arc<Transaction>,
    pub last_seen: u64,
}

To leverage the procedural macros.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes totally! my first macro here, updated now.

@@ -592,3 +592,7 @@ impl From<BdkTx> for Tx {
}
}
}
pub struct UnconfirmedTx {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go with the proc macros proposed above, a little bit of API docs to describe this type might be nice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a UnconfirmedTx type, similar to how we needed to create a SentAndReceivedValues type instead of returning a tuple. Totally open to naming it something different, but just needed a type instead of a tuple.

Since it's not a 1-for-1 of a type I didn't add docs (but would have liked to! just wasn't sure if/how to do it best since its not 1-for-1), what are you thinking for a little bit of API docs? Here's the method docs https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.Wallet.html#method.apply_unconfirmed_txs let me know what you think and I'll def add!

Copy link
Member

@thunderbiscuit thunderbiscuit Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like this?

/// This type replaces the Rust tuple `(tx, last_seen)` used in the Wallet::apply_unconfirmed_txs` method,
/// where `last_seen` is the timestamp of when the transaction `tx` was last seen in the mempool.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect, updated

self.get_wallet().apply_unconfirmed_txs(
unconfirmed_txs
.into_iter()
.map(|utx| (Arc::new((&*utx.tx).into()), utx.last_seen)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this line hard to parse, but I understand it's required. You need to dereference the transaction in the Arc before taking a reference to it. I think in this case using

.map(|utx| (Arc::new(utx.tx.as_ref().into()), utx.last_seen)),

would work as well and might be easier to read? Just a nit, pick whatever line you like best.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you sir, much much easier to read, so thanks for calling this out. Updated

@reez reez force-pushed the apply branch 2 times, most recently from f98e3f4 to 14a3c53 Compare March 24, 2025 18:11
@thunderbiscuit
Copy link
Member

We can merge this one next as soon as the tests pass, and I'll rebase my 705 and we can merge that after.

@reez
Copy link
Collaborator Author

reez commented Mar 24, 2025

We can merge this one next as soon as the tests pass, and I'll rebase my 705 and we can merge that after.

cool catch you in a few hours when tests pass 😆

Copy link
Member

@thunderbiscuit thunderbiscuit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 4db7af0.

@thunderbiscuit thunderbiscuit merged commit 4db7af0 into bitcoindevkit:master Mar 24, 2025
46 of 47 checks passed
@reez reez deleted the apply branch March 24, 2025 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add apply_unconfirmed_txs to Wallet
2 participants