Skip to content

Commit 67f67a4

Browse files
authored
🐛 Fix indexer ordering - DESC on height and index (#1017)
1 parent 5a768f4 commit 67f67a4

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/indexer.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,10 +1317,10 @@ mod test {
13171317
assert_json_include!(
13181318
actual: all_txs.json::<serde_json::Value>(),
13191319
expected: json!([
1320-
{ "index": 0, "transaction_type": "BlobTransaction", "transaction_status": "Success" },
1321-
{ "index": 1, "transaction_type": "BlobTransaction", "transaction_status": "Success" },
1320+
{ "index": 5, "transaction_type": "BlobTransaction", "transaction_status": "Sequenced" },
13221321
{ "index": 2, "transaction_type": "BlobTransaction", "transaction_status": "Success" },
1323-
{ "index": 5, "transaction_type": "BlobTransaction", "transaction_status": "Sequenced" }
1322+
{ "index": 1, "transaction_type": "BlobTransaction", "transaction_status": "Success" },
1323+
{ "index": 0, "transaction_type": "BlobTransaction", "transaction_status": "Success" },
13241324
])
13251325
);
13261326

@@ -1355,10 +1355,10 @@ mod test {
13551355
actual: proofs_response.json::<serde_json::Value>(),
13561356
expected: json!([
13571357
{ "index": 3, "transaction_type": "ProofTransaction", "transaction_status": "Success", "block_hash": block_2_hash },
1358-
{ "index": 3, "transaction_type": "ProofTransaction", "transaction_status": "Success" },
1359-
{ "index": 4, "transaction_type": "ProofTransaction", "transaction_status": "Success" },
1358+
{ "index": 7, "transaction_type": "ProofTransaction", "transaction_status": "Success" },
13601359
{ "index": 6, "transaction_type": "ProofTransaction", "transaction_status": "Success" },
1361-
{ "index": 7, "transaction_type": "ProofTransaction", "transaction_status": "Success" }
1360+
{ "index": 4, "transaction_type": "ProofTransaction", "transaction_status": "Success" },
1361+
{ "index": 3, "transaction_type": "ProofTransaction", "transaction_status": "Success" },
13621362
])
13631363
);
13641364

@@ -1367,10 +1367,10 @@ mod test {
13671367
assert_json_include!(
13681368
actual: proofs_by_height.json::<serde_json::Value>(),
13691369
expected: json!([
1370-
{ "index": 3, "transaction_type": "ProofTransaction", "transaction_status": "Success" },
1371-
{ "index": 4, "transaction_type": "ProofTransaction", "transaction_status": "Success" },
1370+
{ "index": 7, "transaction_type": "ProofTransaction", "transaction_status": "Success" },
13721371
{ "index": 6, "transaction_type": "ProofTransaction", "transaction_status": "Success" },
1373-
{ "index": 7, "transaction_type": "ProofTransaction", "transaction_status": "Success" }
1372+
{ "index": 4, "transaction_type": "ProofTransaction", "transaction_status": "Success" },
1373+
{ "index": 3, "transaction_type": "ProofTransaction", "transaction_status": "Success" },
13741374
])
13751375
);
13761376

src/indexer/api.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub async fn get_transactions(
152152
FROM transactions t
153153
LEFT JOIN blocks b ON t.block_hash = b.hash
154154
WHERE b.height <= $1 and b.height > $2 AND t.transaction_type = 'blob_transaction'
155-
ORDER BY b.height DESC, t.index ASC
155+
ORDER BY b.height DESC, t.index DESC
156156
LIMIT $3
157157
"#,
158158
)
@@ -165,7 +165,7 @@ pub async fn get_transactions(
165165
FROM transactions t
166166
LEFT JOIN blocks b ON t.block_hash = b.hash
167167
WHERE t.transaction_type = 'blob_transaction'
168-
ORDER BY b.height DESC, t.index ASC
168+
ORDER BY b.height DESC, t.index DESC
169169
LIMIT $1
170170
"#,
171171
)
@@ -203,7 +203,7 @@ pub async fn get_transactions_by_contract(
203203
JOIN blobs b ON t.tx_hash = b.tx_hash
204204
LEFT JOIN blocks bl ON t.block_hash = bl.hash
205205
WHERE b.contract_name = $1 AND bl.height <= $2 AND bl.height > $3 AND t.transaction_type = 'blob_transaction'
206-
ORDER BY bl.height DESC, t.index ASC
206+
ORDER BY bl.height DESC, t.index DESC
207207
LIMIT $4
208208
"#,
209209
)
@@ -217,7 +217,7 @@ pub async fn get_transactions_by_contract(
217217
FROM transactions t
218218
JOIN blobs b ON t.tx_hash = b.tx_hash AND t.parent_dp_hash = b.parent_dp_hash
219219
WHERE b.contract_name = $1 AND t.transaction_type = 'blob_transaction'
220-
ORDER BY t.block_hash DESC, t.index ASC
220+
ORDER BY t.block_hash DESC, t.index DESC
221221
LIMIT $2
222222
"#,
223223
)
@@ -255,7 +255,7 @@ pub async fn get_transactions_by_height(
255255
FROM transactions t
256256
JOIN blocks b ON t.block_hash = b.hash
257257
WHERE b.height = $1 AND t.transaction_type = 'blob_transaction'
258-
ORDER BY t.index ASC
258+
ORDER BY t.index DESC
259259
"#,
260260
)
261261
.bind(height)
@@ -287,7 +287,7 @@ pub async fn get_transaction_with_hash(
287287
SELECT tx_hash, version, transaction_type, transaction_status, parent_dp_hash, block_hash, index
288288
FROM transactions
289289
WHERE tx_hash = $1 AND transaction_type = 'blob_transaction'
290-
ORDER BY index ASC
290+
ORDER BY index DESC
291291
"#,
292292
)
293293
.bind(tx_hash)
@@ -641,7 +641,7 @@ pub async fn get_proofs(
641641
FROM transactions t
642642
LEFT JOIN blocks b ON t.block_hash = b.hash
643643
WHERE b.height <= $1 and b.height > $2 AND t.transaction_type = 'proof_transaction'
644-
ORDER BY b.height DESC, t.index ASC
644+
ORDER BY b.height DESC, t.index DESC
645645
LIMIT $3
646646
"#,
647647
)
@@ -654,7 +654,7 @@ pub async fn get_proofs(
654654
FROM transactions t
655655
LEFT JOIN blocks b ON t.block_hash = b.hash
656656
WHERE t.transaction_type = 'proof_transaction'
657-
ORDER BY b.height DESC, t.index ASC
657+
ORDER BY b.height DESC, t.index DESC
658658
LIMIT $1
659659
"#,
660660
)
@@ -689,7 +689,7 @@ pub async fn get_proofs_by_height(
689689
FROM transactions t
690690
JOIN blocks b ON t.block_hash = b.hash
691691
WHERE b.height = $1 AND t.transaction_type = 'proof_transaction'
692-
ORDER BY t.index ASC
692+
ORDER BY t.index DESC
693693
"#,
694694
)
695695
.bind(height)
@@ -721,7 +721,7 @@ pub async fn get_proof_with_hash(
721721
SELECT tx_hash, version, transaction_type, transaction_status, parent_dp_hash, block_hash, index
722722
FROM transactions
723723
WHERE tx_hash = $1 AND transaction_type = 'proof_transaction'
724-
ORDER BY index ASC
724+
ORDER BY index DESC
725725
"#,
726726
)
727727
.bind(tx_hash)

0 commit comments

Comments
 (0)