Skip to content

Commit

Permalink
Merge pull request #260 from rajiabdul/indexer
Browse files Browse the repository at this point in the history
feat: startknet indexer
  • Loading branch information
fishonamos authored Dec 25, 2024
2 parents e94fdb3 + 1837c8f commit 4d51414
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 527 deletions.
2 changes: 1 addition & 1 deletion land-registry-indexer/.env.example
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
11 changes: 0 additions & 11 deletions land-registry-indexer/Dockerfile

This file was deleted.

27 changes: 0 additions & 27 deletions land-registry-indexer/docker-compose.yml

This file was deleted.

25 changes: 12 additions & 13 deletions land-registry-indexer/package.json
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"
}
}
63 changes: 50 additions & 13 deletions land-registry-indexer/src/config.ts
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;
};
Loading

0 comments on commit 4d51414

Please sign in to comment.