Skip to content

Commit

Permalink
Regenerate watcher with latest code generator (#40)
Browse files Browse the repository at this point in the history
* Regenerate watcher with latest codegen

* Update watcher version and repo URL

* Update yarn lock file
  • Loading branch information
prathamesh0 authored Jun 6, 2024
1 parent e184d16 commit 34e56ad
Show file tree
Hide file tree
Showing 7 changed files with 860 additions and 408 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ out/

.vscode
.idea

gql-logs/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

To enable GQL requests caching:

* Update the `server.gqlCache` config with required settings.
* Update the `server.gql.cache` config with required settings.

* In the GQL [schema file](./src/schema.gql), use the `cacheControl` directive to apply cache hints at schema level.

Expand Down
32 changes: 19 additions & 13 deletions environments/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
host = "127.0.0.1"
port = 3008
kind = "active"
gqlPath = "/"

# Checkpointing state.
checkpointing = true
Expand All @@ -22,23 +21,30 @@
# Interval in number of blocks at which to clear entities cache.
clearEntitiesCacheInterval = 1000

# Max block range for which to return events in eventsInRange GQL query.
# Use -1 for skipping check on block range.
maxEventsBlockRange = 1000

# Flag to specify whether RPC endpoint supports block hash as block tag parameter
rpcSupportsBlockHashParam = false

# GQL cache settings
[server.gqlCache]
enabled = true
# Server GQL config
[server.gql]
path = "/graphql"

# Max block range for which to return events in eventsInRange GQL query.
# Use -1 for skipping check on block range.
maxEventsBlockRange = 1000

# Log directory for GQL requests
logDir = "./gql-logs"

# GQL cache settings
[server.gql.cache]
enabled = true

# Max in-memory cache size (in bytes) (default 8 MB)
# maxCacheSize
# Max in-memory cache size (in bytes) (default 8 MB)
# maxCacheSize

# GQL cache-control max-age settings (in seconds)
maxAge = 15
timeTravelMaxAge = 86400 # 1 day
# GQL cache-control max-age settings (in seconds)
maxAge = 15
timeTravelMaxAge = 86400 # 1 day

[metrics]
host = "127.0.0.1"
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/sushiswap-v3-watcher-ts",
"version": "0.1.12",
"version": "0.1.13",
"description": "sushiswap-v3-watcher-ts",
"private": true,
"main": "dist/index.js",
Expand Down Expand Up @@ -29,7 +29,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/cerc-io/watcher-ts.git"
"url": "https://github.com/cerc-io/sushiswap-v3-watcher-ts"
},
"author": "",
"license": "AGPL-3.0",
Expand All @@ -39,11 +39,11 @@
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@apollo/client": "^3.3.19",
"@cerc-io/cli": "^0.2.92",
"@cerc-io/ipld-eth-client": "^0.2.92",
"@cerc-io/solidity-mapper": "^0.2.92",
"@cerc-io/util": "^0.2.92",
"@cerc-io/graph-node": "^0.2.92",
"@cerc-io/cli": "^0.2.94",
"@cerc-io/ipld-eth-client": "^0.2.94",
"@cerc-io/solidity-mapper": "^0.2.94",
"@cerc-io/util": "^0.2.94",
"@cerc-io/graph-node": "^0.2.94",
"@ethersproject/providers": "^5.4.4",
"debug": "^4.3.1",
"decimal.js": "^10.3.1",
Expand Down Expand Up @@ -71,6 +71,7 @@
"eslint-plugin-standard": "^5.0.0",
"husky": "^7.0.2",
"ts-node": "^10.2.1",
"typescript": "^5.0.2"
"typescript": "^5.0.2",
"winston": "^3.13.0"
}
}
26 changes: 20 additions & 6 deletions src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,20 +395,34 @@ export class Indexer implements IndexerInterface {
console.timeEnd('time:indexer#processBlockAfterEvents-dump_subgraph_state');
}

parseEventNameAndArgs (kind: string, logObj: any): any {
parseEventNameAndArgs (kind: string, logObj: any): { eventParsed: boolean, eventDetails: any } {
const { topics, data } = logObj;

const contract = this._contractMap.get(kind);
assert(contract);

const logDescription = contract.parseLog({ data, topics });
let logDescription: ethers.utils.LogDescription;
try {
logDescription = contract.parseLog({ data, topics });
} catch (err) {
// Return if no matching event found
if ((err as Error).message.includes('no matching event')) {
log(`WARNING: Skipping event for contract ${kind} as no matching event found in the ABI`);
return { eventParsed: false, eventDetails: {} };
}

throw err;
}

const { eventName, eventInfo, eventSignature } = this._baseIndexer.parseEvent(logDescription);

return {
eventName,
eventInfo,
eventSignature
eventParsed: true,
eventDetails: {
eventName,
eventInfo,
eventSignature
}
};
}

Expand Down Expand Up @@ -518,7 +532,7 @@ export class Indexer implements IndexerInterface {
}

async getEventsInRange (fromBlockNumber: number, toBlockNumber: number): Promise<Array<Event>> {
return this._baseIndexer.getEventsInRange(fromBlockNumber, toBlockNumber, this._serverConfig.maxEventsBlockRange);
return this._baseIndexer.getEventsInRange(fromBlockNumber, toBlockNumber, this._serverConfig.gql.maxEventsBlockRange);
}

async getSyncStatus (): Promise<SyncStatus | undefined> {
Expand Down
Loading

0 comments on commit 34e56ad

Please sign in to comment.