Skip to content

Commit 328ed5c

Browse files
authored
fix(decoders): guard against undefined fields on Bradbury testnet (#144)
1 parent d65446b commit 328ed5c

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/transactions/decoders.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,20 @@ export const decodeTransaction = (tx: GenLayerRawTransaction): GenLayerTransacti
8181
txData: tx.txData,
8282
txDataDecoded: txDataDecoded,
8383

84-
currentTimestamp: tx.currentTimestamp.toString(),
85-
numOfInitialValidators: tx.numOfInitialValidators.toString(),
86-
txSlot: tx.txSlot.toString(),
87-
createdTimestamp: tx.createdTimestamp.toString(),
88-
lastVoteTimestamp: tx.lastVoteTimestamp.toString(),
89-
queuePosition: tx.queuePosition.toString(),
90-
numOfRounds: tx.numOfRounds.toString(),
84+
currentTimestamp: tx.currentTimestamp?.toString() ?? "0",
85+
// Bradbury uses `initialRotations`; older chains use `numOfInitialValidators`
86+
numOfInitialValidators: (tx.numOfInitialValidators ?? (tx as any).initialRotations)?.toString() ?? "0",
87+
txSlot: tx.txSlot?.toString() ?? "0",
88+
createdTimestamp: tx.createdTimestamp?.toString() ?? "0",
89+
lastVoteTimestamp: tx.lastVoteTimestamp?.toString() ?? "0",
90+
queuePosition: tx.queuePosition?.toString() ?? "0",
91+
numOfRounds: tx.numOfRounds?.toString() ?? "0",
9192

9293
readStateBlockRange: {
9394
...tx.readStateBlockRange,
94-
activationBlock: tx.readStateBlockRange.activationBlock.toString(),
95-
processingBlock: tx.readStateBlockRange.processingBlock.toString(),
96-
proposalBlock: tx.readStateBlockRange.proposalBlock.toString(),
95+
activationBlock: tx.readStateBlockRange?.activationBlock?.toString() ?? "0",
96+
processingBlock: tx.readStateBlockRange?.processingBlock?.toString() ?? "0",
97+
proposalBlock: tx.readStateBlockRange?.proposalBlock?.toString() ?? "0",
9798
},
9899

99100
statusName:
@@ -103,13 +104,13 @@ export const decodeTransaction = (tx: GenLayerRawTransaction): GenLayerTransacti
103104

104105
lastRound: {
105106
...tx.lastRound,
106-
round: tx.lastRound.round.toString(),
107-
leaderIndex: tx.lastRound.leaderIndex.toString(),
108-
votesCommitted: tx.lastRound.votesCommitted.toString(),
109-
votesRevealed: tx.lastRound.votesRevealed.toString(),
110-
appealBond: tx.lastRound.appealBond.toString(),
111-
rotationsLeft: tx.lastRound.rotationsLeft.toString(),
112-
validatorVotesName: tx.lastRound.validatorVotes.map(
107+
round: tx.lastRound?.round?.toString() ?? "0",
108+
leaderIndex: tx.lastRound?.leaderIndex?.toString() ?? "0",
109+
votesCommitted: tx.lastRound?.votesCommitted?.toString() ?? "0",
110+
votesRevealed: tx.lastRound?.votesRevealed?.toString() ?? "0",
111+
appealBond: tx.lastRound?.appealBond?.toString() ?? "0",
112+
rotationsLeft: tx.lastRound?.rotationsLeft?.toString() ?? "0",
113+
validatorVotesName: (tx.lastRound?.validatorVotes ?? []).map(
113114
vote => voteTypeNumberToName[String(vote) as keyof typeof voteTypeNumberToName],
114115
) as VoteType[],
115116
},

src/types/transactions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ export type GenLayerRawTransaction = {
276276
currentTimestamp: bigint;
277277
sender: Address;
278278
recipient: Address;
279-
numOfInitialValidators: bigint;
279+
numOfInitialValidators?: bigint; // undefined on Bradbury — use `initialRotations` instead
280+
initialRotations?: bigint; // Bradbury equivalent of `numOfInitialValidators`
280281
txSlot: bigint;
281282
createdTimestamp: bigint;
282283
lastVoteTimestamp: bigint;

0 commit comments

Comments
 (0)