mirror of
https://github.com/cerc-io/watcher-ts
synced 2024-10-02 22:22:37 +00:00
f9934675b2
* Add schema generation. * Use yargs and add a script to generate schema. * Add command to generate schema to README.md * Remove use of arrow functions in visitor. * Add function to export schema in visitor. * Create Event union while adding to it. * Add bool to typemappings. * Add method descriptions and remove output type mappings. * Add storage mode. * Add URL support and a flattening script. * Fix parameter for flattening in README.md. * Add setup and references to README.md. Co-authored-by: prathamesh <prathamesh.musale0@gmail.com> |
||
---|---|---|
.. | ||
src | ||
.eslintignore | ||
.eslintrc.json | ||
package.json | ||
README.md | ||
tsconfig.json |
Code Generator
Setup
-
Run the following command to install required packages:
yarn
Run
-
Run the following command to generate a flattened contract file from a contract file:
yarn codegen:flatten <input-file-path> [output-dir]
input-file-path
: Input contract file path (absolute) (required). Note: Currently, relative path doesn't work.output-dir
: Directory to store the flattened contract output file (default:./out
).
Example:
yarn codegen:flatten ~/watcher-ts/node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol ./flattened
This will generate file
ERC20_flat.sol
in./flattened
. -
Run the following command to generate schema from a contract file:
yarn codegen:gql --input-file <input-file-path> --output-file [output-file-path] --mode [eth_call | storage]
input-file
: Input contract (must be a flattened contract) file path or an URL (required).output-file
: Schema output file path (logs output usingstdout
if not provided).mode
: Contract variables access mode (default:storage
).
Examples:
yarn codegen:gql --input-file ./test/examples/contracts/ERC20-flat.sol --output-file ./ERC20-schema.gql --mode eth_call
yarn codegen:gql --input-file https://git.io/Jupci --output-file ./ERC721-schema.gql --mode storage
Demo
-
Install required packages:
yarn
-
Flatten a contract file:
# Note: Currently, relative path for input-file-path doesn't work. Use absolute path. yarn codegen:flatten ~/watcher-ts/node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol ./flattened
-
Generate schema from the flattened contract file:
yarn codegen:gql --input-file ./flattened/ERC20_flat.sol --output-file ./ERC20-schema.gql --mode storage
-
Generate schema from the flattened contract file from an URL:
yarn codegen:gql --input-file https://git.io/Jupci --output-file ./ERC721-schema.gql --mode eth_call