-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #260 from rajiabdul/indexer
feat: startknet indexer
- Loading branch information
Showing
12 changed files
with
321 additions
and
527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
STARTING_BLOCK=0 | ||
LAND_REGISTRY_ADDRESS=0x5a4054a1b1389dcd48b650637977280d32f1ad8b3027bc6c7eb606bf7e28bf5 | ||
DATABASE_URL=postgresql://username:password@localhost:5432/land_registry | ||
APIBARA_URL= | ||
APIBARA_URL=https://goerli.starknet.a5a.ch |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
{ | ||
"name": "land-registry-indexer", | ||
"version": "1.0.0", | ||
"description": "Apibara indexer for Land Registry events", | ||
"main": "src/index.ts", | ||
"main": "dist/indexer.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"start": "node dist/index.js", | ||
"dev": "ts-node src/index.ts" | ||
"start": "node dist/indexer.js", | ||
"dev": "ts-node src/indexer.ts" | ||
}, | ||
"dependencies": { | ||
"@apibara/indexer": "^0.3.0", | ||
"@apibara/protocol": "^0.4.0", | ||
"@apibara/starknet": "^0.3.0", | ||
"dotenv": "^16.0.3", | ||
"pg": "^8.11.0", | ||
"typescript": "^5.0.4" | ||
"@apibara/protocol": "^2.0.0-beta.28", | ||
"@apibara/starknet": "^2.0.0-beta.28", | ||
"pg": "^8.11.3", | ||
"dotenv": "^16.3.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.2.5", | ||
"@types/pg": "^8.10.1", | ||
"ts-node": "^10.9.1" | ||
"@types/node": "^20.8.0", | ||
"@types/pg": "^8.10.3", | ||
"@types/dotenv": "^8.2.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.2.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,53 @@ | ||
/** | ||
* Configuration settings for the Land Registry Indexer | ||
* | ||
* This module loads environment variables from a .env file and provides | ||
* configuration constants used throughout the application. | ||
*/ | ||
import { createClient } from "@apibara/protocol"; | ||
import { Filter, StarknetStream } from "@apibara/starknet"; | ||
import * as dotenv from "dotenv"; | ||
|
||
import dotenv from 'dotenv'; | ||
dotenv.config(); | ||
|
||
export const config = { | ||
startingBlock: Number(process.env.STARTING_BLOCK || 0), | ||
landRegistryAddress: process.env.LAND_REGISTRY_ADDRESS || '', | ||
pgConnection: process.env.DATABASE_URL || '', | ||
apibaraUrl: process.env.APIBARA_URL || '', | ||
}; | ||
// Helper function to convert hex string to decimal string | ||
const hexToDec = (hex: string): string => { | ||
return BigInt(hex).toString(10); | ||
}; | ||
|
||
// Event keys for the Land Registry contract | ||
export const EVENT_KEYS = { | ||
LAND_REGISTERED: hexToDec("0x0000000000000000000000000000000000000000000000000000000000000001"), | ||
LAND_TRANSFERRED: hexToDec("0x0000000000000000000000000000000000000000000000000000000000000002"), | ||
LAND_VERIFIED: hexToDec("0x0000000000000000000000000000000000000000000000000000000000000003"), | ||
LAND_UPDATED: hexToDec("0x0000000000000000000000000000000000000000000000000000000000000004"), | ||
INSPECTOR_ADDED: hexToDec("0x0000000000000000000000000000000000000000000000000000000000000005"), | ||
INSPECTOR_REMOVED: hexToDec("0x0000000000000000000000000000000000000000000000000000000000000006"), | ||
LAND_LISTED: hexToDec("0x0000000000000000000000000000000000000000000000000000000000000007"), | ||
LISTING_UPDATED: hexToDec("0x0000000000000000000000000000000000000000000000000000000000000008"), | ||
LAND_SOLD: hexToDec("0x0000000000000000000000000000000000000000000000000000000000000009"), | ||
}; | ||
|
||
export const createIndexerConfig = () => { | ||
const filter = Filter.make({ | ||
header: "unknown", | ||
events: [{ | ||
address: process.env.LAND_REGISTRY_ADDRESS as `0x${string}`, | ||
keys: Object.values(EVENT_KEYS).map((key) => `0x${key.toString()}` as `0x${string}`), | ||
transactionStatus: "succeeded", | ||
}], | ||
}); | ||
|
||
const request = StarknetStream.Request.make({ | ||
filter: [filter], | ||
finality: "accepted", | ||
startingCursor: { | ||
orderKey: BigInt(process.env.STARTING_BLOCK || "0"), | ||
}, | ||
}); | ||
|
||
return { | ||
client: createClient(StarknetStream, process.env.APIBARA_URL || ""), | ||
request, | ||
dbUrl: process.env.DATABASE_URL || "", | ||
}; | ||
}; | ||
|
||
export type IndexerMessage = { | ||
_tag: "data" | "invalidate"; | ||
data?: any; | ||
}; |
Oops, something went wrong.