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 a5c7bbe
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 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,11 @@ class FullChain extends BaseChain {
transactionReceipts.push(new TransactionReceipt(entry.transactionHash, entry.blockHash, entry.blockHeight));
});

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

/**
Expand Down

0 comments on commit a5c7bbe

Please sign in to comment.