Skip to content

Commit

Permalink
fix(store-sync): improve TransactionReceiptNotFoundError error catchi…
Browse files Browse the repository at this point in the history
…ng in waitForTransaction (latticexyz#1833)
  • Loading branch information
CryptoSpaces authored and CryptoSpaces committed Sep 1, 2024
1 parent 0738d29 commit 95bb96c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/store-sync/src/createStoreSync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { storeEventsAbi } from "@latticexyz/store";
import { Hex, TransactionReceiptNotFoundError } from "viem";
import { Hex } from "viem";
import {
StorageAdapter,
StorageAdapterBlock,
Expand Down Expand Up @@ -34,6 +34,7 @@ import { bigIntMax, chunk, isDefined, waitForIdle } from "@latticexyz/common/uti
import { getSnapshot } from "./getSnapshot";
import { fetchAndStoreLogs } from "./fetchAndStoreLogs";
import { Store as StoreConfig } from "@latticexyz/store";
import { isViemTransactionReceiptNotFoundError } from "@latticexyz/store-sync/isViemTransactionReceiptNotFoundError";

const debug = parentDebug.extend("createStoreSync");

Expand Down Expand Up @@ -291,7 +292,7 @@ export async function createStoreSync<config extends StoreConfig = StoreConfig>(
return { status, blockNumber, transactionHash };
}
} catch (error) {
if (error instanceof TransactionReceiptNotFoundError) {
if (isViemTransactionReceiptNotFoundError(error)) {
return;
}
throw error;
Expand Down
16 changes: 16 additions & 0 deletions packages/store-sync/src/isViemTransactionReceiptNotFoundError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TransactionReceiptNotFoundErrorType } from "viem";

type PartialViemError = Partial<TransactionReceiptNotFoundErrorType>;

export function isViemTransactionReceiptNotFoundError(error: unknown): error is Error & PartialViemError {
if (!(error instanceof Error)) {
return false;
}

const maybeTransactionReceiptNotFoundErrorType = error as PartialViemError;

return (
maybeTransactionReceiptNotFoundErrorType.name === "TransactionReceiptNotFoundError" &&
!!maybeTransactionReceiptNotFoundErrorType.version?.match(/Version: viem@\d+\.\d+\.\d+/gi)
);
}

0 comments on commit 95bb96c

Please sign in to comment.