Skip to content

Commit 7464574

Browse files
authored
feat: tx index sorting (#642)
2 parents 2a59eff + c4b6c20 commit 7464574

File tree

6 files changed

+429
-11
lines changed

6 files changed

+429
-11
lines changed

api/src/main/java/org/cardanofoundation/rosetta/api/block/model/entity/TxnEntity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.math.BigInteger;
44
import java.util.List;
5+
import jakarta.annotation.Nullable;
56
import jakarta.persistence.Column;
67
import jakarta.persistence.ConstraintMode;
78
import jakarta.persistence.Entity;
@@ -50,6 +51,10 @@ public class TxnEntity {
5051
@Column(name = "fee")
5152
private BigInteger fee;
5253

54+
@Column(name = "tx_index")
55+
@Nullable
56+
private Integer txIndex;
57+
5358
@OneToMany(mappedBy = "txHash")
5459
private List<TxScriptEntity> script;
5560

api/src/main/java/org/cardanofoundation/rosetta/api/block/model/repository/TxRepositoryCustomBase.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public List<TxnEntity> findTransactionsByBlockHash(String blockHash) {
123123
TRANSACTION.OUTPUTS,
124124
TRANSACTION.FEE,
125125
TRANSACTION.SLOT,
126+
TRANSACTION.TX_INDEX,
126127
BLOCK.HASH.as("joined_block_hash"),
127128
BLOCK.NUMBER.as("joined_block_number"),
128129
BLOCK.SLOT.as("joined_block_slot"),
@@ -133,6 +134,7 @@ public List<TxnEntity> findTransactionsByBlockHash(String blockHash) {
133134
.leftJoin(BLOCK).on(TRANSACTION.BLOCK_HASH.eq(BLOCK.HASH))
134135
.leftJoin(TRANSACTION_SIZE).on(TRANSACTION.TX_HASH.eq(TRANSACTION_SIZE.TX_HASH))
135136
.where(TRANSACTION.BLOCK_HASH.eq(blockHash))
137+
.orderBy(TRANSACTION.TX_INDEX.asc())
136138
.fetch(queryBuilder::mapRecordToTxnEntity);
137139
}
138140

@@ -182,12 +184,12 @@ protected int executeCountQuery(Condition conditions, @Nullable Boolean isSucces
182184
* Ensures count and results queries use identical conditions and JOINs.
183185
* Currency conditions use EXISTS subqueries - no JOIN needed.
184186
*/
185-
protected List<? extends org.jooq.Record> executeResultsQuery(Condition conditions,
186-
@Nullable Boolean isSuccess,
187+
protected List<? extends org.jooq.Record> executeResultsQuery(Condition conditions,
188+
@Nullable Boolean isSuccess,
187189
OffsetBasedPageRequest offsetBasedPageRequest) {
188190
return buildBaseResultsQuery(isSuccess)
189191
.where(conditions)
190-
.orderBy(TRANSACTION.SLOT.desc())
192+
.orderBy(TRANSACTION.SLOT.desc(), TRANSACTION.TX_INDEX.desc())
191193
.limit(offsetBasedPageRequest.getLimit())
192194
.offset(offsetBasedPageRequest.getOffset())
193195
.fetch();

api/src/main/java/org/cardanofoundation/rosetta/api/block/model/repository/util/TxRepositoryQueryBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ public interface CurrencyConditionBuilder {
3636
Condition buildCurrencyCondition(Currency currency);
3737
}
3838

39-
public SelectJoinStep<Record11<String, String, JSONB, JSONB, Long, Long, String, Long, Long, Integer, Integer>> buildTransactionSelectQuery(DSLContext dsl) {
39+
public SelectJoinStep<Record12<String, String, JSONB, JSONB, Long, Long, Integer, String, Long, Long, Integer, Integer>> buildTransactionSelectQuery(DSLContext dsl) {
4040
return dsl.select(
4141
TRANSACTION.TX_HASH,
4242
TRANSACTION.BLOCK_HASH,
4343
TRANSACTION.INPUTS,
4444
TRANSACTION.OUTPUTS,
4545
TRANSACTION.FEE,
4646
TRANSACTION.SLOT,
47+
TRANSACTION.TX_INDEX,
4748
BLOCK.HASH.as("joined_block_hash"),
4849
BLOCK.NUMBER.as("joined_block_number"),
4950
BLOCK.SLOT.as("joined_block_slot"),
@@ -161,6 +162,8 @@ public TxnEntity mapRecordToTxnEntity(org.jooq.Record record) {
161162
@Nullable BigInteger fee = Optional.ofNullable(record.get(TRANSACTION.FEE))
162163
.map(BigInteger::valueOf).orElse(null);
163164

165+
@Nullable Integer txIndex = record.get(TRANSACTION.TX_INDEX);
166+
164167
@Nullable BlockEntity blockEntity = null;
165168
String blockHashFromRecord = record.get("joined_block_hash", String.class);
166169
if (blockHashFromRecord != null) {
@@ -178,6 +181,7 @@ public TxnEntity mapRecordToTxnEntity(org.jooq.Record record) {
178181
.inputKeys(readUtxoKeys(inputs, txHash))
179182
.outputKeys(readUtxoKeys(outputs, txHash))
180183
.fee(fee)
184+
.txIndex(txIndex)
181185
.build();
182186
}
183187

api/src/main/java/org/cardanofoundation/rosetta/api/jooq/tables/Transaction.java

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/src/main/java/org/cardanofoundation/rosetta/api/jooq/tables/records/TransactionRecord.java

Lines changed: 22 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)