Skip to content

Commit

Permalink
cli: add starknet indexer in cli playground (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
fracek authored Aug 8, 2024
2 parents 2bec324 + d48edde commit 2bb0ed4
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 70 deletions.
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"pnpm-lock.yaml",
"generated.js",
"generated.d.ts",
"src/proto"
"src/proto",
"**/.apibara"
]
}
}
4 changes: 3 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@
"playground:prepare": "pnpm playground prepare --dir playground",
"playground:dev": "pnpm playground dev --dir playground",
"playground:build": "pnpm playground build --dir playground",
"playground:start": "jiti ./playground/.apibara/build/main.mjs"
"playground:start": "JITI_ESM_RESOLVE=1 NODE_OPTIONS=\"--enable-source-maps\" jiti ./playground/.apibara/build/main.mjs"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.14.0",
"jiti": "^1.21.0",
"starknet": "^6.11.0",
"unbuild": "^2.0.0",
"viem": "^2.12.4",
"vitest": "^1.6.0"
Expand All @@ -62,6 +63,7 @@
"@apibara/evm": "workspace:*",
"@apibara/indexer": "workspace:*",
"@apibara/protocol": "workspace:*",
"@apibara/starknet": "workspace:*",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
Expand Down
30 changes: 0 additions & 30 deletions packages/cli/playground/indexers/simple.indexer.ts

This file was deleted.

42 changes: 42 additions & 0 deletions packages/cli/playground/indexers/starknet.indexer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { defineIndexer } from "@apibara/indexer";
import { StarknetStream } from "@apibara/starknet";
import type { ApibaraRuntimeConfig } from "apibara/types";
import consola from "consola";
import { hash } from "starknet";

export default function indexer(runtimeConfig: ApibaraRuntimeConfig) {
consola.log("--> Starknet Indexer Runtime Config: ", runtimeConfig);
return defineIndexer(StarknetStream)({
streamUrl: "http://mainnet-v2.starknet.a5a.ch:7007",
finality: "accepted",
startingCursor: {
orderKey: 80_000n,
},
filter: {
events: [
{
fromAddress:
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
keys: [hash.getSelectorFromName("Transfer") as `0x${string}`],
includeReceipt: true,
},
],
},
async transform({ block: { header, events } }) {
return [
{
blockNumber: header.blockNumber,
events,
},
];
},
hooks: {
"sink:write"({ data }) {
consola.log("Wrote:", data[0].events.length, "Tranfer events");
},
"sink:flush"({ endCursor }) {
consola.log("Flushing", endCursor.orderKey);
},
},
});
}
35 changes: 0 additions & 35 deletions packages/cli/playground/indexers/with-config.indexer.ts

This file was deleted.

5 changes: 3 additions & 2 deletions packages/cli/src/rollup/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const command = defineCommand({
const sink = sinkFunction();
try {
consola.log("Running Indexer: ", name);
consola.log("Running Indexer: ", name);
await run(client, indexer, sink);
} catch (error) {
consola.error(\`Error in indexer \${name}:\`, error);
Expand Down Expand Up @@ -188,7 +188,8 @@ runMain(command);
onwarn(warning, rollupWarn) {
if (
!["CIRCULAR_DEPENDENCY", "EVAL"].includes(warning.code || "") &&
!warning.message.includes("Unsupported source map comment")
!warning.message.includes("Unsupported source map comment") &&
!warning.message.includes("@__PURE__")
) {
rollupWarn(warning);
}
Expand Down
Loading

0 comments on commit 2bb0ed4

Please sign in to comment.