Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/transactions/decoders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ export const decodeTransaction = (tx: GenLayerRawTransaction): GenLayerTransacti
txData: txData,
txDataDecoded: txDataDecoded,

// Same identifier exposed under both names; the on-chain Solidity struct
// uses `txId`, the legacy localnet RPC used `hash`. Populate both so
// consumers can rely on either.
hash: tx.txId,
txId: tx.txId,

currentTimestamp: tx.currentTimestamp.toString(),
numOfInitialValidators: numOfInitialValidators?.toString() ?? "0",
txSlot: tx.txSlot.toString(),
Expand Down Expand Up @@ -241,6 +247,11 @@ export const simplifyTransactionReceipt = (tx: GenLayerTransaction): GenLayerTra
};

export const decodeLocalnetTransaction = (tx: GenLayerTransaction): GenLayerTransaction => {
// Mirror the testnet decoder: expose the identifier under both `hash`
// (legacy localnet name) and `txId` (on-chain Solidity name).
if (tx.hash && !tx.txId) tx.txId = tx.hash;
else if (tx.txId && !tx.hash) tx.hash = tx.txId;

if (!tx.data) return tx;
try {
const leaderReceipt = tx.consensus_data?.leader_receipt;
Expand Down
4 changes: 3 additions & 1 deletion src/types/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ export type GenLayerTransaction = {
status?: TransactionStatus | number;
statusName?: TransactionStatus;

// hash: localnet // txId: testnet// hash: localnet // txId: testnet
// The same identifier is exposed under both names: `txId` matches the
// on-chain Solidity struct field; `hash` is kept for back-compat with the
// legacy localnet RPC. Decoders populate both, so consumers can use either.
hash?: TransactionHash;
txId?: TransactionHash;

Expand Down
6 changes: 6 additions & 0 deletions tests/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ describe("decodeTransaction", () => {
const names = (decoded.lastRound as any)?.validatorVotesName;
expect(names).toEqual(["AGREE", "AGREE", "AGREE"]);
});

it("should expose the identifier under both `txId` and `hash`", () => {
const decoded = decodeTransaction(makeRawTx());
expect(decoded.txId).toBe("0x" + "ff".repeat(32));
expect(decoded.hash).toBe(decoded.txId);
});
});

describe("simplifyTransactionReceipt", () => {
Expand Down
Loading