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

[Wallet] Paginate transactions sorted by timestamp, taking into account the timelock #1895

Open
gabaldon opened this issue Apr 12, 2021 · 1 comment

Comments

@gabaldon
Copy link
Contributor

Currently, Sheikah sorts transactions by timestamp and timelock. Due to pagination, it only could order transactions page by page.
Sheikah needs to receive the transactions paginated sorted by timestamp and timelock in order to have a coherent UI where the first transaction unlocked is shown at the top of the first page.

@gabaldon gabaldon changed the title [Wallet] Paginate transactions by timestamp, taking into account the timelock [Wallet] Paginate transactions sorted by timestamp, taking into account the timelock Apr 12, 2021
@tmpolaczyk
Copy link
Contributor

Currently transactions are not sorted, they are simply inserted in the database in the order they are seen. So to implement this, we would need to change the logic that inserts transactions in the database. This means that old transactions will keep the wrong order, unless we manually reorder them which I don't know if is possible.

Another option would be to read the transaction range, then also read all the transactions before and after these ones that have the same timestamp, then sort them, and then apply pagination and send the transaction range to sheikah, I guess that would be easier to implement but it's still very error prone.

I assume that the transactions are already sorted by block and the timestamp is just equal to the block number, so some pseudocode for option 2 would be:

# This is the database, 0 means transaction in block 0, 1 means transaction in block 1, etc
# I assume that the transactions are already sorted by block, but we should verify that assumption
00001111222233334444
# Ask for 5 transactions with offset 6
      11222
# Read all the transactions on the left and on the right that have the same block number
# as the first and the last transaction
    11112222
# Sort them by block number, then by timelock
    11112222
# Return the 5 transactions that are in the desired position
      11222

With that approach the database order would not change, so we would need to sort them every time. Also, that algorithm could be implemented in sheikah and that will probably be the easiest option.

Question: how to sort transactions by timelock when there is more than one output? Because each output can have a different timelock. Can we simply use the timelock of the first output? Or maybe the maximum of all the timelocks?

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

No branches or pull requests

2 participants