-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate erc721-watcher using codegen
- Loading branch information
1 parent
71d3433
commit 99aaa9a
Showing
70 changed files
with
5,190 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Don't lint build output. | ||
dist |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": [ | ||
"semistandard", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 12, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/explicit-module-boundary-types": [ | ||
"warn", | ||
{ | ||
"allowArgumentsExplicitlyTypedAsAny": true | ||
} | ||
] | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,189 @@ | ||
# erc721-watcher | ||
|
||
## Setup | ||
|
||
* Run the following command to install required packages: | ||
|
||
```bash | ||
yarn | ||
``` | ||
|
||
* Run the IPFS (go-ipfs version 0.12.2) daemon: | ||
|
||
```bash | ||
ipfs daemon | ||
``` | ||
|
||
* Create a postgres12 database for the watcher: | ||
|
||
```bash | ||
sudo su - postgres | ||
createdb erc721-watcher | ||
``` | ||
|
||
* If the watcher is an `active` watcher: | ||
|
||
Create database for the job queue and enable the `pgcrypto` extension on them (https://github.com/timgit/pg-boss/blob/master/docs/usage.md#intro): | ||
|
||
``` | ||
createdb erc721-watcher-job-queue | ||
``` | ||
|
||
``` | ||
postgres@tesla:~$ psql -U postgres -h localhost erc721-watcher-job-queue | ||
Password for user postgres: | ||
psql (12.7 (Ubuntu 12.7-1.pgdg18.04+1)) | ||
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off) | ||
Type "help" for help. | ||
erc721-watcher-job-queue=# CREATE EXTENSION pgcrypto; | ||
CREATE EXTENSION | ||
erc721-watcher-job-queue=# exit | ||
``` | ||
|
||
* In the [config file](./environments/local.toml): | ||
|
||
* Update the database connection settings. | ||
|
||
* Update the `upstream` config and provide the `ipld-eth-server` GQL API endpoint. | ||
|
||
* Update the `server` config with state checkpoint settings and provide the IPFS API address. | ||
|
||
## Customize | ||
|
||
* Indexing on an event: | ||
|
||
* Edit the custom hook function `handleEvent` (triggered on an event) in [hooks.ts](./src/hooks.ts) to perform corresponding indexing using the `Indexer` object. | ||
|
||
* While using the indexer storage methods for indexing, pass `diff` as true if default state is desired to be generated using the state variables being indexed. | ||
|
||
* Generating state: | ||
|
||
* Edit the custom hook function `createInitialState` (triggered if the watcher passes the start block, checkpoint: `true`) in [hooks.ts](./src/hooks.ts) to save an initial state `IPLDBlock` using the `Indexer` object. | ||
|
||
* Edit the custom hook function `createStateDiff` (triggered on a block) in [hooks.ts](./src/hooks.ts) to save the state in a `diff` `IPLDBlock` using the `Indexer` object. The default state (if exists) is updated. | ||
|
||
* Edit the custom hook function `createStateCheckpoint` (triggered just before default and CLI checkpoint) in [hooks.ts](./src/hooks.ts) to save the state in a `checkpoint` `IPLDBlock` using the `Indexer` object. | ||
|
||
## Run | ||
|
||
* Run the watcher: | ||
|
||
```bash | ||
yarn server | ||
``` | ||
|
||
GQL console: http://localhost:3006/graphql | ||
|
||
* If the watcher is an `active` watcher: | ||
|
||
* Run the job-runner: | ||
|
||
```bash | ||
yarn job-runner | ||
``` | ||
|
||
* To watch a contract: | ||
|
||
```bash | ||
yarn watch:contract --address <contract-address> --kind <contract-kind> --checkpoint <true | false> --starting-block [block-number] | ||
``` | ||
|
||
* `address`: Address or identifier of the contract to be watched. | ||
* `kind`: Kind of the contract. | ||
* `checkpoint`: Turn checkpointing on (`true` | `false`). | ||
* `starting-block`: Starting block for the contract (default: `1`). | ||
|
||
Examples: | ||
|
||
Watch a contract with its address and checkpointing on: | ||
|
||
```bash | ||
yarn watch:contract --address 0x1F78641644feB8b64642e833cE4AFE93DD6e7833 --kind ERC20 --checkpoint true | ||
``` | ||
|
||
Watch a contract with its identifier and checkpointing on: | ||
|
||
```bash | ||
yarn watch:contract --address MyProtocol --kind protocol --checkpoint true | ||
``` | ||
|
||
* To fill a block range: | ||
|
||
```bash | ||
yarn fill --start-block <from-block> --end-block <to-block> | ||
``` | ||
|
||
* `start-block`: Block number to start filling from. | ||
* `end-block`: Block number till which to fill. | ||
|
||
* To create a checkpoint for a contract: | ||
|
||
```bash | ||
yarn checkpoint --address <contract-address> --block-hash [block-hash] | ||
``` | ||
|
||
* `address`: Address or identifier of the contract for which to create a checkpoint. | ||
* `block-hash`: Hash of a block (in the pruned region) at which to create the checkpoint (default: latest canonical block hash). | ||
|
||
* To reset the watcher to a previous block number: | ||
|
||
* Reset state: | ||
|
||
```bash | ||
yarn reset state --block-number <previous-block-number> | ||
``` | ||
|
||
* Reset job-queue: | ||
|
||
```bash | ||
yarn reset job-queue --block-number <previous-block-number> | ||
``` | ||
|
||
* `block-number`: Block number to which to reset the watcher. | ||
|
||
* To export and import the watcher state: | ||
|
||
* In source watcher, export watcher state: | ||
|
||
```bash | ||
yarn export-state --export-file [export-file-path] | ||
``` | ||
|
||
* `export-file`: Path of JSON file to which to export the watcher data. | ||
|
||
* In target watcher, run job-runner: | ||
|
||
```bash | ||
yarn job-runner | ||
``` | ||
|
||
* Import watcher state: | ||
|
||
```bash | ||
yarn import-state --import-file <import-file-path> | ||
``` | ||
|
||
* `import-file`: Path of JSON file from which to import the watcher data. | ||
|
||
* Run fill: | ||
|
||
```bash | ||
yarn fill --start-block <snapshot-block> --end-block <to-block> | ||
``` | ||
|
||
* `snapshot-block`: Block number at which the watcher state was exported. | ||
|
||
* Run server: | ||
|
||
```bash | ||
yarn server | ||
``` | ||
|
||
* To inspect a CID: | ||
|
||
```bash | ||
yarn inspect-cid --cid <cid> | ||
``` | ||
|
||
* `cid`: CID to be inspected. |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
[server] | ||
host = "127.0.0.1" | ||
port = 3006 | ||
kind = "active" | ||
|
||
# Checkpointing state. | ||
checkpointing = true | ||
|
||
# Checkpoint interval in number of blocks. | ||
checkpointInterval = 2000 | ||
|
||
# IPFS API address (can be taken from the output on running the IPFS daemon). | ||
# ipfsApiAddr = "/ip4/127.0.0.1/tcp/5001" | ||
|
||
|
||
[database] | ||
type = "postgres" | ||
host = "localhost" | ||
port = 5432 | ||
database = "erc721-watcher" | ||
username = "postgres" | ||
password = "postgres" | ||
synchronize = true | ||
logging = false | ||
|
||
[upstream] | ||
[upstream.ethServer] | ||
gqlApiEndpoint = "http://127.0.0.1:8082/graphql" | ||
rpcProviderEndpoint = "http://127.0.0.1:8081" | ||
blockDelayInMilliSecs = 2000 | ||
|
||
[upstream.cache] | ||
name = "requests" | ||
enabled = false | ||
deleteOnStart = false | ||
|
||
[jobQueue] | ||
dbConnectionString = "postgres://postgres:postgres@localhost/erc721-watcher-job-queue" | ||
maxCompletionLagInSecs = 300 | ||
jobDelayInMilliSecs = 100 | ||
eventsInBatch = 50 |
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"name": "@vulcanize/erc721-watcher", | ||
"version": "0.1.0", | ||
"description": "erc721-watcher", | ||
"private": true, | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"build": "tsc", | ||
"server": "DEBUG=vulcanize:* ts-node src/server.ts", | ||
"job-runner": "DEBUG=vulcanize:* ts-node src/job-runner.ts", | ||
"watch:contract": "DEBUG=vulcanize:* ts-node src/cli/watch-contract.ts", | ||
"fill": "DEBUG=vulcanize:* ts-node src/fill.ts", | ||
"reset": "DEBUG=vulcanize:* ts-node src/cli/reset.ts", | ||
"checkpoint": "DEBUG=vulcanize:* ts-node src/cli/checkpoint.ts", | ||
"export-state": "DEBUG=vulcanize:* ts-node src/cli/export-state.ts", | ||
"import-state": "DEBUG=vulcanize:* ts-node src/cli/import-state.ts", | ||
"inspect-cid": "DEBUG=vulcanize:* ts-node src/cli/inspect-cid.ts" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vulcanize/watcher-ts.git" | ||
}, | ||
"author": "", | ||
"license": "AGPL-3.0", | ||
"bugs": { | ||
"url": "https://github.com/vulcanize/watcher-ts/issues" | ||
}, | ||
"homepage": "https://github.com/vulcanize/watcher-ts#readme", | ||
"dependencies": { | ||
"@apollo/client": "^3.3.19", | ||
"@ethersproject/providers": "5.3.0", | ||
"@ipld/dag-cbor": "^6.0.12", | ||
"@vulcanize/ipld-eth-client": "^0.1.0", | ||
"@vulcanize/solidity-mapper": "^0.1.0", | ||
"@vulcanize/util": "^0.1.0", | ||
"@vulcanize/graph-node": "^0.1.0", | ||
"apollo-server-express": "^2.25.0", | ||
"apollo-type-bigint": "^0.1.3", | ||
"debug": "^4.3.1", | ||
"ethers": "^5.2.0", | ||
"express": "^4.17.1", | ||
"graphql": "^15.5.0", | ||
"graphql-import-node": "^0.0.4", | ||
"json-bigint": "^1.0.0", | ||
"reflect-metadata": "^0.1.13", | ||
"typeorm": "^0.2.32", | ||
"yargs": "^17.0.1", | ||
"decimal.js": "^10.3.1" | ||
}, | ||
"devDependencies": { | ||
"@ethersproject/abi": "^5.3.0", | ||
"@types/express": "^4.17.11", | ||
"@types/yargs": "^17.0.0", | ||
"@typescript-eslint/eslint-plugin": "^4.25.0", | ||
"@typescript-eslint/parser": "^4.25.0", | ||
"eslint": "^7.27.0", | ||
"eslint-config-semistandard": "^15.0.1", | ||
"eslint-config-standard": "^16.0.3", | ||
"eslint-plugin-import": "^2.23.3", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^5.1.0", | ||
"eslint-plugin-standard": "^5.0.0", | ||
"ts-node": "^10.0.0", | ||
"typescript": "^4.3.2" | ||
} | ||
} |
Oops, something went wrong.