Update codegen docs (#258)

Co-authored-by: prathamesh <prathamesh.musale0@gmail.com>
This commit is contained in:
Ashwin Phatak 2021-09-30 10:44:30 +05:30 committed by GitHub
parent d456a3f676
commit a9067c4374
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,12 +2,20 @@
## Setup ## Setup
* Run the following command to install required packages: * In root of the repository:
* Install required packages:
```bash ```bash
yarn yarn
``` ```
* Build files:
```bash
yarn build
```
## Run ## Run
* Run the following command to generate a watcher from a contract file: * Run the following command to generate a watcher from a contract file:
@ -28,56 +36,84 @@
Examples: Examples:
Generate code in both `eth_call` and `storage` mode, `active` kind. Generate code in both `eth_call` and `storage` mode, `active` kind.
```bash ```bash
yarn codegen --input-file ./test/examples/contracts/ERC20.sol --contract-name ERC20 --output-folder ../my-erc20-watcher --mode all --kind active yarn codegen --input-file ./test/examples/contracts/ERC20.sol --contract-name ERC20 --output-folder ../my-erc20-watcher --mode all --kind active
``` ```
Generate code in `eth_call` mode using a contract provided by an URL. Generate code in `eth_call` mode using a contract provided by an URL.
```bash ```bash
yarn codegen --input-file https://git.io/Jupci --contract-name ERC721 --output-folder ../my-erc721-watcher --mode eth_call yarn codegen --input-file https://git.io/Jupci --contract-name ERC721 --output-folder ../my-erc721-watcher --mode eth_call
``` ```
Generate code in `storage` mode, `lazy` kind. Generate code in `storage` mode, `lazy` kind.
```bash ```bash
yarn codegen --input-file ./test/examples/contracts/ERC721.sol --contract-name ERC721 --output-folder ../my-erc721-watcher --mode storage --kind lazy yarn codegen --input-file ./test/examples/contracts/ERC721.sol --contract-name ERC721 --output-folder ../my-erc721-watcher --mode storage --kind lazy
``` ```
## Demo Generate code for `ERC721` contract in both `eth_call` and `storage` mode, `active` kind:
* In root of the repository: ```bash
yarn codegen --input-file ../../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol --contract-name ERC721 --output-folder ../demo-erc721-watcher --mode all --kind active
```
* Install required packages: This will create a folder called `demo-erc721-watcher` containing the generated code at the specified path. Follow the steps in [Run Generated Watcher](#run-generated-watcher) to setup and run the generated watcher.
## Run Generated Watcher
### Setup
* Run the following command to install required packages:
```bash ```bash
yarn yarn
``` ```
* Build files: * Create the databases configured in `environments/local.toml`.
### Customize
* Indexing on an event:
* Edit the custom hook function `handleEvent` (triggered on an event) in `src/hooks.ts` to perform corresponding indexing using the `Indexer` object.
* Refer to `src/hooks.example.ts` for an example hook function for events in an ERC20 contract.
### Run
* Run lint:
```bash ```bash
yarn build yarn lint
``` ```
* Generate a watcher from a contract file: * Run the watcher:
```bash ```bash
yarn codegen --input-file ../../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol --contract-name ERC20 --output-folder ../demo-erc20-watcher --mode eth_call --kind active yarn server
``` ```
This will create a folder called `demo-erc20-watcher` containing the generated code at the specified path. Follow the steps in `demo-erc20-watcher/README.md` to setup and run the generated watcher. * If the watcher is an `active` watcher:
* Generate a watcher from a flattened contract file from an URL: * Run the job-runner:
```bash ```bash
yarn codegen --input-file https://git.io/Jupci --contract-name ERC721 --output-folder ../demo-erc721-watcher --mode all --kind active yarn job-runner
``` ```
## References * To watch a contract:
* [ERC20 schema generation (eth_call mode).](https://git.io/JuhN2) ```bash
* [ERC20 schema generation (storage mode).](https://git.io/JuhNr) yarn watch:contract --address <contract-address> --kind ERC721 --starting-block [block-number]
* [ERC721 schema generation (eth_call mode).](https://git.io/JuhNK) ```
* [ERC721 schema generation (storage mode).](https://git.io/JuhN1)
* To fill a block range:
```bash
yarn fill --startBlock <from-block> --endBlock <to-block>
```
## Known Issues ## Known Issues