-
Notifications
You must be signed in to change notification settings - Fork 7
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
example: add factory mode and pglite persistence #123
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ dist | |
.turbo | ||
bun.lockb | ||
.vscode | ||
.apibara | ||
.apibara | ||
.persistence |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "cli: add @electric-sql/pglite as external dependency", | ||
"packageName": "apibara", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { defineIndexer } from "@apibara/indexer"; | ||
import { useLogger } from "@apibara/indexer/plugins/logger"; | ||
import { StarknetStream } from "@apibara/starknet"; | ||
import type { ApibaraRuntimeConfig } from "apibara/types"; | ||
import { hash } from "starknet"; | ||
|
||
const PAIR_CREATED = hash.getSelectorFromName("PairCreated") as `0x${string}`; | ||
const SWAP = hash.getSelectorFromName("Swap") as `0x${string}`; | ||
const shortAddress = (addr?: string) => | ||
addr ? `${addr.slice(0, 6)}...${addr.slice(-4)}` : ""; | ||
|
||
export default function (runtimeConfig: ApibaraRuntimeConfig) { | ||
return defineIndexer(StarknetStream)({ | ||
streamUrl: "https://starknet.preview.apibara.org", | ||
finality: "accepted", | ||
startingCursor: { | ||
orderKey: 800_000n, | ||
}, | ||
filter: { | ||
header: "always", | ||
events: [ | ||
{ | ||
address: | ||
"0x00dad44c139a476c7a17fc8141e6db680e9abc9f56fe249a105094c44382c2fd", | ||
keys: [PAIR_CREATED], | ||
}, | ||
], | ||
}, | ||
async factory({ block: { events } }) { | ||
const logger = useLogger(); | ||
|
||
const poolEvents = (events ?? []).flatMap((event) => { | ||
const pairAddress = event.data?.[2]; | ||
|
||
logger.log( | ||
"Factory: PairAddress : ", | ||
`\x1b[35m${pairAddress}\x1b[0m`, | ||
); | ||
return { | ||
address: pairAddress, | ||
keys: [SWAP], | ||
}; | ||
}); | ||
return { | ||
filter: { | ||
events: poolEvents, | ||
}, | ||
}; | ||
}, | ||
async transform({ block, endCursor }) { | ||
const logger = useLogger(); | ||
const { events } = block; | ||
|
||
logger.log("Transforming... : ", endCursor?.orderKey); | ||
for (const event of events) { | ||
logger.log( | ||
"Event Address : ", | ||
shortAddress(event.address), | ||
"| Txn hash :", | ||
shortAddress(event.transactionHash), | ||
); | ||
} | ||
}, | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import { appConfig } from "./plugins/config"; | |
import { esmShim } from "./plugins/esm-shim"; | ||
import { indexers } from "./plugins/indexers"; | ||
|
||
const runtimeDependencies = ["better-sqlite3"]; | ||
const runtimeDependencies = ["better-sqlite3", "@electric-sql/pglite"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Missing required dependency @electric-sql/pglite The dependency @electric-sql/pglite is listed in runtimeDependencies but is not declared in the package.json dependencies. This needs to be added to ensure proper package installation and functionality.
🔗 Analysis chainVerify pglite dependency declaration The addition of @electric-sql/pglite looks correct, but ensure it's properly declared in package.json. Let me check the package.json in the cli package directory since the file under review is in packages/cli. Let me check if it might be in devDependencies or if there are any other references to this package in package.json files. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Check if dependency is declared in package.json
jq '.dependencies["@electric-sql/pglite"]' package.json
Length of output: 62 Script: #!/bin/bash
# Check if dependency is declared in cli package.json
jq '.dependencies["@electric-sql/pglite"]' packages/cli/package.json
Length of output: 75 Script: #!/bin/bash
# Check both dependencies and devDependencies in cli package.json
echo "CLI package.json contents:"
cat packages/cli/package.json
# Search for any package.json files referencing pglite
echo -e "\nSearching for pglite in all package.json files:"
rg -l "@electric-sql/pglite" "**/package.json"
Length of output: 3396 |
||
|
||
export function getRollupConfig(apibara: Apibara): RollupConfig { | ||
const extensions: string[] = [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Avoid hardcoding persistence path
The persistence path should be configurable through runtime configuration rather than hardcoded.