Skip to content

Commit

Permalink
Fix event details parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
lorcan-codes committed Jan 15, 2024
1 parent 540ff57 commit d7ca396
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion indexer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"bunyan": "^1.8.15",
"dotenv": "^16.3.1",
"pg": "^8.7.3",
"starknet": "^5.24.3",
"starknet": "^5.24.5",
"typeorm": "^0.3.6"
},
"devDependencies": {
Expand Down
11 changes: 6 additions & 5 deletions indexer/src/indexer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppDataSource } from "./utils/db";
import { Block } from "./entity/block";
import { requiredEnv, toBool } from "./utils/envs";
import { requiredEnv} from "./utils/envs";
import { BlockIdentifier, GetBlockResponse, RpcProvider } from "starknet";
import { Event } from "./entity/event";
import { Transaction } from "./entity/transaction";
Expand Down Expand Up @@ -36,6 +36,7 @@ const contractAddress = BigInt(requiredEnv("CONTRACT_ADDRESS"));
// const useMainnet = toBool(requiredEnv("USE_MAINNET"));
const starknet = new RpcProvider({
nodeUrl: process.env.RPC_NODE_URL,
// nodeUrl: "https://free-rpc.nethermind.io/goerli-juno",
});

const mapBlock = (block: ReturnedBlock): Block => {
Expand All @@ -56,7 +57,8 @@ tx.events.filter(e => BigInt(e.from_address) === contractAddress).map((e, eventI
event.txIndex = tx.transaction_index;
event.block = block;
event.blockIndex = block.blockIndex;
const processed = deserializeEvent(e.keys[0], e.data);
const [functName, ...initialData] = e.keys
const processed = deserializeEvent(functName, [...initialData, ...e.data]);
event.name = processed.name;
event.content = processed.value;
return event;
Expand All @@ -77,7 +79,8 @@ const mapBlockEvents = (events: any[], block: Block): Event[] =>
event.block = block;
event.blockIndex = e.block_number;

const processed = deserializeEvent(e.keys[0], e.data);
const [functName, ...initialData] = e.keys
const processed = deserializeEvent(functName, [...initialData, ...e.data]);
if(processed){
event.name = eventNames[processed.name] || processed.name;
event.content = processed.value;
Expand Down Expand Up @@ -188,15 +191,13 @@ const getBlockEvents = async (block: Block) => {
while (continuationToken) {
const eventsRes: any = await starknet.getEvents({
address: contractAddressString,
// keys: [[block.block_hash]],
chunk_size: 10,
from_block: { block_number: block.blockIndex },
to_block: { block_number: block.blockIndex },
// from_block: { block_number: 925922},
// to_block: { block_number: 925922 },
continuation_token: continuationToken === 'initial' ? undefined : continuationToken,
});
// const nbEvents = eventsRes.events.length;
continuationToken = eventsRes.continuation_token;
allEvents = [...allEvents, ...eventsRes.events]
}
Expand Down
3 changes: 2 additions & 1 deletion indexer/src/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const { getSelectorFromName } = selector;
type Field = { name: string, type: string };
type StructsDefinition = Record<string, Field[]>;
const structs = abi.filter(entry => entry.type === "struct").reduce<StructsDefinition>((acc, entry) => {
acc[entry.name] = entry.members!;
// @ts-ignore
acc[entry.name] = entry.data || entry.members!;
return acc;
}, {});

Expand Down
45 changes: 20 additions & 25 deletions indexer/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,30 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@noble/curves@~1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35"
integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==
"@noble/curves@~1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.3.0.tgz#01be46da4fd195822dab821e72f71bf4aeec635e"
integrity sha512-t01iSXPuN+Eqzb4eBX0S5oubSqXbK/xXa1Ne18Hj8f9pStxztHCE2gfboSp/dZRLSqfuLpRK2nDXDK+W9puocA==
dependencies:
"@noble/hashes" "1.3.2"
"@noble/hashes" "1.3.3"

"@noble/[email protected]":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39"
integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==

"@noble/hashes@~1.3.2":
"@noble/[email protected]", "@noble/hashes@~1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.3.tgz#39908da56a4adc270147bb07968bf3b16cfe1699"
integrity sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==

"@scure/base@^1.1.3":
"@scure/base@~1.1.3":
version "1.1.5"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.5.tgz#1d85d17269fe97694b9c592552dd9e5e33552157"
integrity sha512-Brj9FiG2W1MRQSTB212YVPRrcbjkv48FoZi/u4l/zds/ieRrqsh7aUf6CLwkAq61oKXr/ZlTzlY66gLIj3TFTQ==

"@scure/starknet@~0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@scure/starknet/-/starknet-0.3.0.tgz#b8273a42fc721025f8098b1f1d96368a7067e1c4"
integrity sha512-Ma66yZlwa5z00qI5alSxdWtIpky5LBhy22acVFdoC5kwwbd9uDyMWEYzWHdNyKmQg9t5Y2UOXzINMeb3yez+Gw==
"@scure/starknet@~1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@scure/starknet/-/starknet-1.0.0.tgz#4419bc2fdf70f3dd6cb461d36c878c9ef4419f8c"
integrity sha512-o5J57zY0f+2IL/mq8+AYJJ4Xpc1fOtDhr+mFQKbHnYFmm3WQrC+8zj2HEgxak1a+x86mhmBC1Kq305KUpVf0wg==
dependencies:
"@noble/curves" "~1.2.0"
"@noble/hashes" "~1.3.2"
"@noble/curves" "~1.3.0"
"@noble/hashes" "~1.3.3"

"@sqltools/formatter@^1.2.2":
version "1.2.3"
Expand Down Expand Up @@ -766,14 +761,14 @@ split2@^4.1.0:
resolved "https://registry.yarnpkg.com/split2/-/split2-4.1.0.tgz#101907a24370f85bb782f08adaabe4e281ecf809"
integrity sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ==

starknet@^5.24.3:
version "5.24.3"
resolved "https://registry.yarnpkg.com/starknet/-/starknet-5.24.3.tgz#1d8a84047783ea122a6cf4f2dac59bfa6d628154"
integrity sha512-v0TuaNc9iNtHdbIRzX372jfQH1vgx2rwBHQDMqK4DqjJbwFEE5dog8Go6rGiZVW750NqRSWrZ7ahqyRNc3bscg==
starknet@^5.24.5:
version "5.25.0"
resolved "https://registry.yarnpkg.com/starknet/-/starknet-5.25.0.tgz#b8cc6992477899385d754ff0b46c8b9dca190826"
integrity sha512-ja5pV610voxTCw/MzXhZoZcwe+XZ5RVWkpa/Fhxsy0OP635DxKDbnPQSKCLWXmSi/BkfkpeefXXv4IUvYJo4kw==
dependencies:
"@noble/curves" "~1.2.0"
"@scure/base" "^1.1.3"
"@scure/starknet" "~0.3.0"
"@noble/curves" "~1.3.0"
"@scure/base" "~1.1.3"
"@scure/starknet" "~1.0.0"
isomorphic-fetch "^3.0.0"
lossless-json "^2.0.8"
pako "^2.0.4"
Expand Down

0 comments on commit d7ca396

Please sign in to comment.