Skip to content

Commit e7beba3

Browse files
committed
Order UTXO query result by "blockNumber", "transactionIndex", and "transactionOutputIndex"
The indexer should sort UTXOs after queries. Sorting results by the `id` field is not a good option. Let's think about a UTXO that is created by a pending transaction. It's ` id` field could be lower than UTXOs created by mined transactions. Using [`blockNumber`, `transactionIndex`, and `transactionOutputIndex`] makes a total order. This commit changes the UTXOs query use the three columns as the ORDER BY condition.
1 parent 45d9962 commit e7beba3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/models/logic/utxo.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ export async function getUTXO(params: {
262262
where: {
263263
[Sequelize.Op.and]: query
264264
},
265-
order: [["id", "DESC"]],
265+
order: [
266+
["blockNumber", "DESC"],
267+
["transactionIndex", "DESC"],
268+
["transactionOutputIndex", "DESC"]
269+
],
266270
limit: itemsPerPage!,
267271
offset: (page! - 1) * itemsPerPage!,
268272
include: includeArray

0 commit comments

Comments
 (0)