Skip to content

Commit

Permalink
get world abi client
Browse files Browse the repository at this point in the history
  • Loading branch information
karooolis committed Dec 11, 2024
1 parent 77d13fa commit 7cfc3e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/explorer/src/app/(explorer)/api/world-abi/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { fetchBlockLogs } from "@latticexyz/block-logs-stream";
import { helloStoreEvent } from "@latticexyz/store";
import { getWorldAbi } from "@latticexyz/store-sync/world";
import { helloWorldEvent } from "@latticexyz/world";
import { chainIdToName, supportedChainId, supportedChains, validateChainId } from "../../../../common";
import { getChainById, supportedChainId, validateChainId } from "../../../../common";

export const dynamic = "force-dynamic";

async function getClient(chainId: supportedChainId) {
const chain = supportedChains[chainIdToName[chainId]]; // TODO: fix types
const chain = getChainById(chainId);
const client = createClient({
chain,
transport: http(),
Expand All @@ -20,7 +20,7 @@ async function getClient(chainId: supportedChainId) {
}

function getIndexerUrl(chainId: supportedChainId) {
const chain = supportedChains[chainIdToName[chainId]!]; // TODO: fix types
const chain = getChainById(chainId);
return "indexerUrl" in chain ? chain.indexerUrl : undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/explorer/src/bin/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async function startStoreIndexer() {

await rm(indexerDatabasePath, { recursive: true, force: true });

console.log("Running SQLite indexer for anvil..."); // TODO: running for custom chain
console.log("Running SQLite indexer..."); // TODO: running for custom chain
indexerProcess = spawn("sh", ["node_modules/.bin/sqlite-indexer"], {
cwd: packageRoot,
stdio: "inherit",
Expand Down
10 changes: 10 additions & 0 deletions packages/explorer/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ export const getChain = (chainName: supportedChainName | string) => {
return null;
};

export const getChainById = (chainId: supportedChainId | number) => {
if (chainId === customChain?.id) {
return customChain;
} else if (chainId in supportedChains) {
// @ts-expect-error ignore for now TODO: fix types
return supportedChains[chainId];
}
return null;
};

export const chainIdToName = Object.fromEntries(
Object.entries(supportedChains).map(([chainName, chain]) => [chain.id, chainName]),
) as Record<supportedChainId, supportedChainName>;
Expand Down

0 comments on commit 7cfc3e2

Please sign in to comment.