Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: add starknet indexer in cli playground #96

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for?

Copy link
Member Author

@jaipaljadeja jaipaljadeja Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually one library was using some invalid annotations, which rollup ignores and emits a warning every time you build. For reference check this and also this

) {
rollupWarn(warning);
}
Expand Down
Loading
Loading