Skip to content
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

Transaction Sorting and Querying #794

Closed
allisonmoyer opened this issue Nov 3, 2022 · 3 comments · Fixed by #1477
Closed

Transaction Sorting and Querying #794

allisonmoyer opened this issue Nov 3, 2022 · 3 comments · Fixed by #1477
Assignees
Labels
api A breaking API change module-wallet new feature New feature or request
Milestone

Comments

@allisonmoyer
Copy link

Describe the enhancement
We'd like to be able to sort transactions at the DB layer and be able to paginate (and maybe in the future search) queries to the transactions.

Use case
We want to display transactions to our customers in a sorted manner. We can do this by first querying all transactions and then sorting them after the fact, but this won't perform well once customers have a large number of transactions.

Currently we are thinking of sorting based on confirmation time for confirmed transactions and no sorting for unconfirmed transactions, but we may explore associating metadata with transactions (i.e. "initiation date" for when the transaction was initiated) and would want to be able to sort transactions based on that (this would help us sort unconfirmed transactions).

In the future, we may also allow customers to filter / search their transactions – ideally we could associate some sort of metadata here that we could filter / search by, but in a simpler use case could also imagine looking up date ranges (i.e. searching / grouping by confirmation time).

@allisonmoyer allisonmoyer added the new feature New feature or request label Nov 3, 2022
@LLFourn
Copy link
Contributor

LLFourn commented Nov 4, 2022

Hi @allisonmoyer I can give some commentary about where we're going with this. BDK is moving towards a v1.0 release. I made the first PR for this yesterday #793. The good news is that in v1.0 the (i) default sorting will be in ascending confirmation time and (ii) all the transactions will be stored in memory rather than in a database (with the ability to write out changes to persistent storage as you see fit). See: sparse_chain.

We have the ability to search for transactions in a height range already: https://github.com/LLFourn/bdk_core_staging/blob/c4de0235bae61d9e51dbe16f13a3c1c658444676/bdk_core/src/sparse_chain.rs#L386

We are planning to allow attaching some associated data to transactions in the SparseChain. I think it's likely that you will have to persist it and index yourself though. The database in v1.0 will be very much decoupled from the wallet itself (it will no longer have a "database" in it) so you should be free to store data in whatever format you want and then read it into memory whenever you want to use it.

@notmandatory
Copy link
Member

Need to confirm how this should be done with the new wallet API. I don't think the best way to do this will be via queries directly on the DB, it should be more efficient to do with the new in memory view of the wallet transactions.

@LLFourn
Copy link
Contributor

LLFourn commented Mar 17, 2024

see also #974, #776, #1333.

I have rough plan in #1333 for how to sort transaction in the way I think applications should display them which is by the first time they saw the transaction i.e. transactions don't move place in the list. Other indexes can of course be implemented by applications separately but that seems like the default one that will satisfy most people. This would also keep transactions that are not in the chain in the list but allow you to tell what happened to them (RBF, re-org) etc.

I would consider including this as the last task for v1.0 after #1194

@nondiremanuel nondiremanuel removed this from the 1.0.0-alpha milestone Mar 21, 2024
@notmandatory notmandatory added this to the 1.0.0-alpha milestone Jun 4, 2024
@notmandatory notmandatory modified the milestones: 1.0.0-alpha, 1.0.0-beta Jun 19, 2024
@notmandatory notmandatory modified the milestones: 1.0.0-beta, 1.1.0 Aug 9, 2024
@notmandatory notmandatory modified the milestones: 1.1.0, 1.0.0-beta Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api A breaking API change module-wallet new feature New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants