Skip to content

Commit

Permalink
Fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
cwastche committed Jul 21, 2024
1 parent 8509d2a commit 51a902c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions indexer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ export default async function transform({
// This is typically the case if there are multiple Kakarot contracts on the same chain.
.filter((event) => isKakarotTransaction(event.transaction))
// Skip if the transaction_executed event contains "eth validation failed".
.filter((event) => !ethValidationFailed(event))
.filter((event) => !ethValidationFailed(event.event))
.map((event) => ({
event: event,
typedEthTx: toTypedEthTx(event.transaction),
typedEthTx: toTypedEthTx({ transaction: event.transaction }),
}))
// Can be null if:
// 1. The transaction is missing calldata.
Expand All @@ -107,10 +107,10 @@ export default async function transform({
// 4. The chain id is not encoded in the v param of the signature for a
// Legacy transaction.
// 5. The deserialization of the transaction fails.
.filter((eventExtended) => eventExtended.typedEthTx)
.filter((eventExtended) => eventExtended.typedEthTx !== null)
.map((eventExtended) => {
const ethTx = typedTransactionToEthTx({
typedTransaction: eventExtended.typedEthTx,
typedTransaction: eventExtended.typedEthTx!,
receipt: eventExtended.event.receipt,
blockNumber,
blockHash,
Expand All @@ -121,7 +121,11 @@ export default async function transform({
})
// Can be null if:
// 1. The typed transaction if missing a signature param (v, r, s).
.filter((eventExtended) => eventExtended.ethTx)
.filter((
eventExtended,
): eventExtended is typeof eventExtended & {
ethTx: NonNullable<typeof eventExtended.ethTx>;
} => eventExtended.ethTx !== null)
.map((eventExtended) => {
const ethLogs = eventExtended.event.receipt.events
.map((e) =>
Expand Down Expand Up @@ -152,7 +156,7 @@ export default async function transform({
const ethReceipt = toEthReceipt({
transaction: eventExtended.ethTx,
logs: ethLogsIndexed,
event: eventExtended.event,
event: eventExtended.event.event,
cumulativeGasUsed,
blockNumber,
blockHash,
Expand Down Expand Up @@ -197,7 +201,7 @@ export default async function transform({
.map((eventExtended) =>
createTrieData({
transactionIndex: Number(eventExtended.ethTx.transactionIndex),
typedTransaction: eventExtended.typedEthTx,
typedTransaction: eventExtended.typedEthTx!,
receipt: eventExtended.ethReceipt,
})
)
Expand Down Expand Up @@ -248,13 +252,13 @@ export default async function transform({
const revertedTransactionCumulativeGasUsed =
cumulativeGasUsages.find((gas, i) => {
return (
Number(transactionWithReceiptExtended.ethTx.transactionIndex) >=
Number(transactionWithReceiptExtended.ethTx!.transactionIndex) >=
cumulativeGasUsages.length - 1 - i && gas
);
}) ?? 0n;

const ethReceipt = toRevertedOutOfResourcesReceipt({
transaction: transactionWithReceiptExtended.ethTx,
transaction: transactionWithReceiptExtended.ethTx!,
blockNumber,
blockHash,
cumulativeGasUsed: revertedTransactionCumulativeGasUsed,
Expand All @@ -270,7 +274,7 @@ export default async function transform({
filteredTransactions.forEach((transaction) => {
store.push({
collection: Collection.Transactions,
data: { tx: transaction.ethTx },
data: { tx: transaction.ethTx! },
});
store.push({
collection: Collection.Receipts,
Expand Down

0 comments on commit 51a902c

Please sign in to comment.