Skip to content

Commit

Permalink
Return transaction receipts ordered by block height
Browse files Browse the repository at this point in the history
Not split between half incoming and half outgoing, with potential left out transactions in between.
  • Loading branch information
sisou committed Sep 27, 2024
1 parent eb5b3bb commit 9b65cf9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/generic/consensus/full/FullChain.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ class FullChain extends BaseChain {
}

const transactionReceipts = [];
const entriesBySender = await this._transactionStore.getBySender(address, (!limit || limit < 0 || !Number.isFinite(limit)) ? null : (limit / 2));
const entriesByRecipient = await this._transactionStore.getByRecipient(address, (!limit || limit < 0 || !Number.isFinite(limit)) ? null : (limit / 2));
const entriesBySender = await this._transactionStore.getBySender(address, (!limit || limit < 0 || !Number.isFinite(limit)) ? null : limit);
const entriesByRecipient = await this._transactionStore.getByRecipient(address, (!limit || limit < 0 || !Number.isFinite(limit)) ? null : limit);

entriesBySender.forEach(entry => {
transactionReceipts.push(new TransactionReceipt(entry.transactionHash, entry.blockHash, entry.blockHeight));
Expand All @@ -603,7 +603,13 @@ class FullChain extends BaseChain {
transactionReceipts.push(new TransactionReceipt(entry.transactionHash, entry.blockHash, entry.blockHeight));
});

return transactionReceipts;
return transactionReceipts
// Sort descending by block height to slice the latest transactions.
.sort((a, b) => b.blockHeight - a.blockHeight)
// Slice by limit, or return all if limit is not set or invalid.
.slice(0, (!limit || limit < 0 || !Number.isFinite(limit)) ? transactionReceipts.length : limit)
// Reverse array to return transactions in ascending order.
.reverse();
}

/**
Expand Down

0 comments on commit 9b65cf9

Please sign in to comment.