diff options
author | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
---|---|---|
committer | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
commit | 7ae38906926dc09bc10670c361af0d2bf0050426 (patch) | |
tree | 5fb10ae366b987db09e4ddb4bc3ba0f75404ad08 /packages/abi-gen | |
parent | b5fd3c72a08aaa6957917d74c333387a16edf66b (diff) | |
download | dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.gz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.bz2 dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.lz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.xz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.zst dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.zip |
Update dependency packages
Diffstat (limited to 'packages/abi-gen')
-rw-r--r-- | packages/abi-gen/.npmignore | 6 | ||||
-rw-r--r-- | packages/abi-gen/CHANGELOG.json | 398 | ||||
-rw-r--r-- | packages/abi-gen/CHANGELOG.md | 169 | ||||
-rw-r--r-- | packages/abi-gen/README.md | 104 | ||||
-rwxr-xr-x | packages/abi-gen/bin/abi-gen.js | 2 | ||||
-rw-r--r-- | packages/abi-gen/coverage/.gitkeep | 0 | ||||
-rw-r--r-- | packages/abi-gen/package.json | 68 | ||||
-rw-r--r-- | packages/abi-gen/src/globals.d.ts | 6 | ||||
-rw-r--r-- | packages/abi-gen/src/index.ts | 152 | ||||
-rw-r--r-- | packages/abi-gen/src/types.ts | 24 | ||||
-rw-r--r-- | packages/abi-gen/src/utils.ts | 119 | ||||
-rw-r--r-- | packages/abi-gen/test/utils_test.ts | 86 | ||||
-rw-r--r-- | packages/abi-gen/tsconfig.json | 8 | ||||
-rw-r--r-- | packages/abi-gen/tslint.json | 3 |
14 files changed, 0 insertions, 1145 deletions
diff --git a/packages/abi-gen/.npmignore b/packages/abi-gen/.npmignore deleted file mode 100644 index d645458f6..000000000 --- a/packages/abi-gen/.npmignore +++ /dev/null @@ -1,6 +0,0 @@ -.* -yarn-error.log -/src/ -/scripts/ -tsconfig.json -/lib/monorepo_scripts/ diff --git a/packages/abi-gen/CHANGELOG.json b/packages/abi-gen/CHANGELOG.json deleted file mode 100644 index 173617b65..000000000 --- a/packages/abi-gen/CHANGELOG.json +++ /dev/null @@ -1,398 +0,0 @@ -[ - { - "version": "2.0.0", - "changes": [ - { - "note": "Upgrade the bignumber.js to v8.0.2", - "pr": 1517 - } - ] - }, - { - "timestamp": 1547561734, - "version": "1.0.22", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547225310, - "version": "1.0.21", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547040760, - "version": "1.0.20", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "1.0.19", - "changes": [ - { - "note": "Dependencies updated" - } - ], - "timestamp": 1544739608 - }, - { - "version": "1.0.18", - "changes": [ - { - "note": "Dependencies updated" - } - ], - "timestamp": 1544570656 - }, - { - "timestamp": 1542821676, - "version": "1.0.17", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1542208198, - "version": "1.0.16", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "1.0.15", - "changes": [ - { - "note": "Dependencies updated" - } - ], - "timestamp": 1541740904 - }, - { - "timestamp": 1539871071, - "version": "1.0.14", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "1.0.13", - "changes": [ - { - "note": "Dependencies updated" - } - ], - "timestamp": 1538693146 - }, - { - "timestamp": 1538157789, - "version": "1.0.12", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1537907159, - "version": "1.0.11", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1537875740, - "version": "1.0.10", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1537541580, - "version": "1.0.9", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1536142250, - "version": "1.0.8", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1535377027, - "version": "1.0.7", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1535133899, - "version": "1.0.6", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1534210131, - "version": "1.0.5", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1532619515, - "version": "1.0.4", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1532614997, - "version": "1.0.3", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1532605697, - "version": "1.0.2", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "1.0.1", - "changes": [ - { - "note": "Fix the abi-gen entry point in package.json", - "pr": 901 - } - ], - "timestamp": 1532357734 - }, - { - "timestamp": 1532043000, - "version": "1.0.0", - "changes": [ - { - "note": "Convert e_r_c to erc in generated file names", - "pr": 822 - }, - { - "note": "Remove the output directory before writing to it", - "pr": 822 - }, - { - "note": "skip generation of wrappers that are already up to date", - "pr": 788 - } - ] - }, - { - "timestamp": 1531919263, - "version": "0.3.4", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1531149657, - "version": "0.3.3", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1529397769, - "version": "0.3.2", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "0.3.1", - "changes": [ - { - "note": "Incorrect publish that was unpublished" - } - ], - "timestamp": 1527810075 - }, - { - "version": "0.3.0", - "changes": [ - { - "note": "Properly export the executable binary", - "pr": 588 - } - ], - "timestamp": 1527008270 - }, - { - "timestamp": 1525477860, - "version": "0.2.13", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1525428773, - "version": "0.2.12", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1524044013, - "version": "0.2.11", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1523462196, - "version": "0.2.10", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1522673609, - "version": "0.2.9", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1522658513, - "version": "0.2.8", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "0.2.5", - "changes": [ - { - "note": "Consolidate all `console.log` calls into `logUtils` in the `@0xproject/utils` package", - "pr": 452 - } - ], - "timestamp": 1521298800 - }, - { - "version": "0.2.4", - "changes": [ - { - "note": "Add a `backend` parameter that allows you to specify the Ethereum library you use in your templates (`web3` or `ethers`). Ethers auto-converts small ints to numbers whereas Web3 doesn't. Defaults to `web3`", - "pr": 413 - }, - { - "note": "Add support for [tuple types](https://solidity.readthedocs.io/en/develop/abi-spec.html#handling-tuple-types)", - "pr": 413 - }, - { - "note": "Add `hasReturnValue` to context data", - "pr": 413 - } - ], - "timestamp": 1520089200 - }, - { - "version": "0.2.1", - "changes": [ - { - "note": "Fix publishing issue where .npmignore was not properly excluding undesired content", - "pr": 389 - } - ], - "timestamp": 1518102000 - }, - { - "version": "0.2.0", - "changes": [ - { - "note": "Added CLI options for explicit specifying location of partials and main template", - "pr": 346 - }, - { - "note": "Added CLI option to specify networkId, adding support for the JSON artifact format found in @0xproject/contracts", - "pr": 388 - } - ], - "timestamp": 1517929200 - }, - { - "version": "0.1.0", - "changes": [ - { - "note": "Fixed array typings with union types", - "pr": 295 - }, - { - "note": "Add event ABIs to context data passed to templates", - "pr": 302 - }, - { - "note": "Add constructor ABIs to context data passed to templates", - "pr": 304 - } - ], - "timestamp": 1515596400 - } -] diff --git a/packages/abi-gen/CHANGELOG.md b/packages/abi-gen/CHANGELOG.md deleted file mode 100644 index af74218b8..000000000 --- a/packages/abi-gen/CHANGELOG.md +++ /dev/null @@ -1,169 +0,0 @@ -<!-- -changelogUtils.file is auto-generated using the monorepo-scripts package. Don't edit directly. -Edit the package's CHANGELOG.json file only. ---> - -CHANGELOG - -## v1.0.22 - _January 15, 2019_ - - * Dependencies updated - -## v1.0.21 - _January 11, 2019_ - - * Dependencies updated - -## v1.0.20 - _January 9, 2019_ - - * Dependencies updated - -## v1.0.19 - _December 13, 2018_ - - * Dependencies updated - -## v1.0.18 - _December 11, 2018_ - - * Dependencies updated - -## v1.0.17 - _November 21, 2018_ - - * Dependencies updated - -## v1.0.16 - _November 14, 2018_ - - * Dependencies updated - -## v1.0.15 - _November 9, 2018_ - - * Dependencies updated - -## v1.0.14 - _October 18, 2018_ - - * Dependencies updated - -## v1.0.13 - _October 4, 2018_ - - * Dependencies updated - -## v1.0.12 - _September 28, 2018_ - - * Dependencies updated - -## v1.0.11 - _September 25, 2018_ - - * Dependencies updated - -## v1.0.10 - _September 25, 2018_ - - * Dependencies updated - -## v1.0.9 - _September 21, 2018_ - - * Dependencies updated - -## v1.0.8 - _September 5, 2018_ - - * Dependencies updated - -## v1.0.7 - _August 27, 2018_ - - * Dependencies updated - -## v1.0.6 - _August 24, 2018_ - - * Dependencies updated - -## v1.0.5 - _August 14, 2018_ - - * Dependencies updated - -## v1.0.4 - _July 26, 2018_ - - * Dependencies updated - -## v1.0.3 - _July 26, 2018_ - - * Dependencies updated - -## v1.0.2 - _July 26, 2018_ - - * Dependencies updated - -## v1.0.1 - _July 23, 2018_ - - * Fix the abi-gen entry point in package.json (#901) - -## v1.0.0 - _July 19, 2018_ - - * Convert e_r_c to erc in generated file names (#822) - * Remove the output directory before writing to it (#822) - * skip generation of wrappers that are already up to date (#788) - -## v0.3.4 - _July 18, 2018_ - - * Dependencies updated - -## v0.3.3 - _July 9, 2018_ - - * Dependencies updated - -## v0.3.2 - _June 19, 2018_ - - * Dependencies updated - -## v0.3.1 - _May 31, 2018_ - - * Incorrect publish that was unpublished - -## v0.3.0 - _May 22, 2018_ - - * Properly export the executable binary (#588) - -## v0.2.13 - _May 4, 2018_ - - * Dependencies updated - -## v0.2.12 - _May 4, 2018_ - - * Dependencies updated - -## v0.2.11 - _April 18, 2018_ - - * Dependencies updated - -## v0.2.10 - _April 11, 2018_ - - * Dependencies updated - -## v0.2.9 - _April 2, 2018_ - - * Dependencies updated - -## v0.2.8 - _April 2, 2018_ - - * Dependencies updated - -## v0.2.5 - _March 17, 2018_ - - * Consolidate all `console.log` calls into `logUtils` in the `@0xproject/utils` package (#452) - -## v0.2.4 - _March 3, 2018_ - - * Add a `backend` parameter that allows you to specify the Ethereum library you use in your templates (`web3` or `ethers`). Ethers auto-converts small ints to numbers whereas Web3 doesn't. Defaults to `web3` (#413) - * Add support for [tuple types](https://solidity.readthedocs.io/en/develop/abi-spec.html#handling-tuple-types) (#413) - * Add `hasReturnValue` to context data (#413) - -## v0.2.1 - _February 8, 2018_ - - * Fix publishing issue where .npmignore was not properly excluding undesired content (#389) - -## v0.2.0 - _February 6, 2018_ - - * Added CLI options for explicit specifying location of partials and main template (#346) - * Added CLI option to specify networkId, adding support for the JSON artifact format found in @0xproject/contracts (#388) - -## v0.1.0 - _January 10, 2018_ - - * Fixed array typings with union types (#295) - * Add event ABIs to context data passed to templates (#302) - * Add constructor ABIs to context data passed to templates (#304) diff --git a/packages/abi-gen/README.md b/packages/abi-gen/README.md deleted file mode 100644 index 214d8f257..000000000 --- a/packages/abi-gen/README.md +++ /dev/null @@ -1,104 +0,0 @@ -# ABI Gen - -This package allows you to generate TypeScript contract wrappers from ABI files. -It's heavily inspired by [Geth abigen](https://github.com/ethereum/go-ethereum/wiki/Native-DApps:-Go-bindings-to-Ethereum-contracts) but takes a different approach. -You can write your custom handlebars templates which will allow you to seamlessly integrate the generated code into your existing codebase with existing conventions. - -[Here](https://github.com/0xProject/0x-monorepo/tree/development/packages/0x.js/abi-gen-templates) are the templates used to generate the contract wrappers used by 0x.js.e - -## Installation - -`yarn add -g @0x/abi-gen` - -## Usage - -``` -abi-gen -Options: - --help Show help [boolean] - --version Show version number [boolean] - --abis Glob pattern to search for ABI JSON files - [string] [required] - --output, -o, --out Folder where to put the output files [string] [required] - --partials Glob pattern for the partial template files [string] - --template Path for the main template file that will be used to - generate each contract [string] [required] - --backend The backing Ethereum library your app uses. Either 'web3' - or 'ethers'. Ethers auto-converts small ints to numbers - whereas Web3 doesn't. - [string] [choices: "web3", "ethers"] [default: "web3"] - --network-id ID of the network where contract ABIs are nested in - artifacts [number] [default: 50] -``` - -You're required to pass a [glob](<https://en.wikipedia.org/wiki/Glob_(programming)>) template where your abi files are located. -TL;DR - here is the example from 0x.js. - -`--abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry).json` - -We could've just used `--abis 'src/artifacts/*.json` but we wanted to exclude some of the abi files. - -The abi file should be either a [Truffle](http://truffleframework.com/) contract artifact (a JSON object with an abi key) or a JSON abi array. - -You need to also specify the location of your main template used for every contract `--template` as well as the partial templates `--partials` that can later be used from the main one. - -## How to write custom templates? - -The best way to get started is to copy [0x.js templates](https://github.com/0xProject/0x-monorepo/tree/development/packages/abi-gen-templates) and start adjusting them for your needs. -We use [handlebars](http://handlebarsjs.com/) template engine under the hood. -You need to have a master template called `contract.mustache`. it will be used to generate each contract wrapper. Although - you don't need and probably shouldn't write all your logic in a single template file. You can write [partial templates](http://handlebarsjs.com/partials.html) and as long as they are within a partials folder - they will be registered and available. - -## Which data/context do I get in my templates? - -For now you don't get much on top of methods abi, some useful helpers and a contract name because it was enough for our use-case, but if you need something else - create a PR. -See the [type definition](https://github.com/0xProject/0x-monorepo/tree/development/packages/abi-gen/src/types.ts) of what we pass to the render method. - -## Output files - -Output files will be generated within an output folder with names converted to camel case and taken from abi file names. If you already have some files in that folder they will be overwritten. - -## Contributing - -We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository. - -Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started. - -### Install dependencies - -If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them: - -```bash -yarn config set workspaces-experimental true -``` - -Then install dependencies - -```bash -yarn install -``` - -### Build - -To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: - -```bash -PKG=@0x/abi-gen yarn build -``` - -Or continuously rebuild on change: - -```bash -PKG=@0x/abi-gen yarn watch -``` - -### Clean - -```bash -yarn clean -``` - -### Lint - -```bash -yarn lint -``` diff --git a/packages/abi-gen/bin/abi-gen.js b/packages/abi-gen/bin/abi-gen.js deleted file mode 100755 index 73ffe76ed..000000000 --- a/packages/abi-gen/bin/abi-gen.js +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env node -require('../lib/src/index.js'); diff --git a/packages/abi-gen/coverage/.gitkeep b/packages/abi-gen/coverage/.gitkeep deleted file mode 100644 index e69de29bb..000000000 --- a/packages/abi-gen/coverage/.gitkeep +++ /dev/null diff --git a/packages/abi-gen/package.json b/packages/abi-gen/package.json deleted file mode 100644 index 7f968893c..000000000 --- a/packages/abi-gen/package.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "name": "@0x/abi-gen", - "version": "1.0.22", - "engines": { - "node": ">=6.12" - }, - "description": "Generate contract wrappers from ABI and handlebars templates", - "main": "lib/src/index.js", - "types": "lib/src/index.d.ts", - "scripts": { - "lint": "tslint --format stylish --project .", - "clean": "shx rm -rf lib", - "build": "tsc -b", - "build:ci": "yarn build", - "test": "yarn run_mocha", - "run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js --bail --exit", - "test:circleci": "yarn test:coverage", - "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", - "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info" - }, - "bin": { - "abi-gen": "bin/abi-gen.js" - }, - "repository": { - "type": "git", - "url": "https://github.com/0xProject/0x-monorepo.git" - }, - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/0xProject/0x-monorepo/issues" - }, - "homepage": "https://github.com/0xProject/0x-monorepo/packages/abi-gen/README.md", - "dependencies": { - "@0x/typescript-typings": "^3.0.8", - "@0x/utils": "^3.0.1", - "chalk": "^2.3.0", - "ethereum-types": "^1.1.6", - "glob": "^7.1.2", - "handlebars": "^4.0.11", - "lodash": "^4.17.5", - "mkdirp": "^0.5.1", - "sleep": "^5.1.1", - "tmp": "^0.0.33", - "to-snake-case": "^1.0.0", - "yargs": "^10.0.3" - }, - "devDependencies": { - "@0x/tslint-config": "^2.0.2", - "@types/glob": "5.0.35", - "@types/handlebars": "^4.0.36", - "@types/mkdirp": "^0.5.1", - "@types/node": "*", - "@types/sleep": "^0.0.7", - "@types/tmp": "^0.0.33", - "@types/yargs": "^10.0.0", - "chai": "^4.1.2", - "dirty-chai": "^2.0.1", - "make-promises-safe": "^1.1.0", - "mocha": "^5.2.0", - "npm-run-all": "^4.1.2", - "shx": "^0.2.2", - "tslint": "5.11.0", - "typescript": "3.0.1" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/abi-gen/src/globals.d.ts b/packages/abi-gen/src/globals.d.ts deleted file mode 100644 index 94e63a32d..000000000 --- a/packages/abi-gen/src/globals.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -declare module '*.json' { - const json: any; - /* tslint:disable */ - export default json; - /* tslint:enable */ -} diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts deleted file mode 100644 index 6e0ca2c87..000000000 --- a/packages/abi-gen/src/index.ts +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env node - -import { AbiEncoder, abiUtils, logUtils } from '@0x/utils'; -import chalk from 'chalk'; -import { AbiDefinition, ConstructorAbi, EventAbi, MethodAbi } from 'ethereum-types'; -import { sync as globSync } from 'glob'; -import * as Handlebars from 'handlebars'; -import * as _ from 'lodash'; -import * as mkdirp from 'mkdirp'; -import * as yargs from 'yargs'; - -import { ContextData, ContractsBackend, ParamKind } from './types'; -import { utils } from './utils'; - -const ABI_TYPE_CONSTRUCTOR = 'constructor'; -const ABI_TYPE_METHOD = 'function'; -const ABI_TYPE_EVENT = 'event'; -const DEFAULT_NETWORK_ID = 50; -const DEFAULT_BACKEND = 'web3'; - -const args = yargs - .option('abis', { - describe: 'Glob pattern to search for ABI JSON files', - type: 'string', - demandOption: true, - }) - .option('output', { - alias: ['o', 'out'], - describe: 'Folder where to put the output files', - type: 'string', - normalize: true, - demandOption: true, - }) - .option('partials', { - describe: 'Glob pattern for the partial template files', - type: 'string', - implies: 'template', - }) - .option('template', { - describe: 'Path for the main template file that will be used to generate each contract', - type: 'string', - demandOption: true, - normalize: true, - }) - .option('backend', { - describe: `The backing Ethereum library your app uses. Either 'web3' or 'ethers'. Ethers auto-converts small ints to numbers whereas Web3 doesn't.`, - type: 'string', - choices: [ContractsBackend.Web3, ContractsBackend.Ethers], - default: DEFAULT_BACKEND, - }) - .option('network-id', { - describe: 'ID of the network where contract ABIs are nested in artifacts', - type: 'number', - default: DEFAULT_NETWORK_ID, - }) - .example( - "$0 --abis 'src/artifacts/**/*.json' --out 'src/contracts/generated/' --partials 'src/templates/partials/**/*.handlebars' --template 'src/templates/contract.handlebars'", - 'Full usage example', - ).argv; - -function registerPartials(partialsGlob: string): void { - const partialTemplateFileNames = globSync(partialsGlob); - logUtils.log(`Found ${chalk.green(`${partialTemplateFileNames.length}`)} ${chalk.bold('partial')} templates`); - for (const partialTemplateFileName of partialTemplateFileNames) { - const namedContent = utils.getNamedContent(partialTemplateFileName); - Handlebars.registerPartial(namedContent.name, namedContent.content); - } -} - -Handlebars.registerHelper('parameterType', utils.solTypeToTsType.bind(utils, ParamKind.Input, args.backend)); -Handlebars.registerHelper('returnType', utils.solTypeToTsType.bind(utils, ParamKind.Output, args.backend)); -if (args.partials) { - registerPartials(args.partials); -} -const mainTemplate = utils.getNamedContent(args.template); -const template = Handlebars.compile<ContextData>(mainTemplate.content); -const abiFileNames = globSync(args.abis); - -if (_.isEmpty(abiFileNames)) { - logUtils.log(`${chalk.red(`No ABI files found.`)}`); - logUtils.log(`Please make sure you've passed the correct folder name and that the files have - ${chalk.bold('*.json')} extensions`); - process.exit(1); -} else { - logUtils.log(`Found ${chalk.green(`${abiFileNames.length}`)} ${chalk.bold('ABI')} files`); - mkdirp.sync(args.output); -} -for (const abiFileName of abiFileNames) { - const namedContent = utils.getNamedContent(abiFileName); - logUtils.log(`Processing: ${chalk.bold(namedContent.name)}...`); - const parsedContent = JSON.parse(namedContent.content); - let ABI; - if (_.isArray(parsedContent)) { - ABI = parsedContent; // ABI file - } else if (!_.isUndefined(parsedContent.abi)) { - ABI = parsedContent.abi; // Truffle artifact - } else if (!_.isUndefined(parsedContent.compilerOutput.abi)) { - ABI = parsedContent.compilerOutput.abi; // 0x artifact - } - if (_.isUndefined(ABI)) { - logUtils.log(`${chalk.red(`ABI not found in ${abiFileName}.`)}`); - logUtils.log( - `Please make sure your ABI file is either an array with ABI entries or a truffle artifact or 0x sol-compiler artifact`, - ); - process.exit(1); - } - - const outFileName = utils.makeOutputFileName(namedContent.name); - const outFilePath = `${args.output}/${outFileName}.ts`; - - if (utils.isOutputFileUpToDate(abiFileName, outFilePath)) { - logUtils.log(`Already up to date: ${chalk.bold(outFilePath)}`); - continue; - } - - let ctor = ABI.find((abi: AbiDefinition) => abi.type === ABI_TYPE_CONSTRUCTOR) as ConstructorAbi; - if (_.isUndefined(ctor)) { - ctor = utils.getEmptyConstructor(); // The constructor exists, but it's implicit in JSON's ABI definition - } - - const methodAbis = ABI.filter((abi: AbiDefinition) => abi.type === ABI_TYPE_METHOD) as MethodAbi[]; - const sanitizedMethodAbis = abiUtils.renameOverloadedMethods(methodAbis) as MethodAbi[]; - const methodsData = _.map(methodAbis, (methodAbi, methodAbiIndex: number) => { - _.forEach(methodAbi.inputs, (input, inputIndex: number) => { - if (_.isEmpty(input.name)) { - // Auto-generated getters don't have parameter names - input.name = `index_${inputIndex}`; - } - }); - // This will make templates simpler - const methodData = { - ...methodAbi, - singleReturnValue: methodAbi.outputs.length === 1, - hasReturnValue: methodAbi.outputs.length !== 0, - tsName: sanitizedMethodAbis[methodAbiIndex].name, - functionSignature: new AbiEncoder.Method(methodAbi).getSignature(), - }; - return methodData; - }); - - const eventAbis = ABI.filter((abi: AbiDefinition) => abi.type === ABI_TYPE_EVENT) as EventAbi[]; - - const contextData = { - contractName: namedContent.name, - ctor, - methods: methodsData, - events: eventAbis, - }; - const renderedTsCode = template(contextData); - utils.writeOutputFile(outFilePath, renderedTsCode); - logUtils.log(`Created: ${chalk.bold(outFilePath)}`); -} diff --git a/packages/abi-gen/src/types.ts b/packages/abi-gen/src/types.ts deleted file mode 100644 index 68765b04d..000000000 --- a/packages/abi-gen/src/types.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { EventAbi, MethodAbi } from 'ethereum-types'; - -export enum ParamKind { - Input = 'input', - Output = 'output', -} - -export enum ContractsBackend { - Web3 = 'web3', - Ethers = 'ethers', -} - -export interface Method extends MethodAbi { - singleReturnValue: boolean; - hasReturnValue: boolean; - tsName: string; - functionSignature: string; -} - -export interface ContextData { - contractName: string; - methods: Method[]; - events: EventAbi[]; -} diff --git a/packages/abi-gen/src/utils.ts b/packages/abi-gen/src/utils.ts deleted file mode 100644 index 56b996ce3..000000000 --- a/packages/abi-gen/src/utils.ts +++ /dev/null @@ -1,119 +0,0 @@ -import { AbiType, ConstructorAbi, DataItem } from 'ethereum-types'; -import * as fs from 'fs'; -import * as _ from 'lodash'; -import * as path from 'path'; -import toSnakeCase = require('to-snake-case'); - -import { ContractsBackend, ParamKind } from './types'; - -export const utils = { - solTypeToTsType(paramKind: ParamKind, backend: ContractsBackend, solType: string, components?: DataItem[]): string { - const trailingArrayRegex = /\[\d*\]$/; - if (solType.match(trailingArrayRegex)) { - const arrayItemSolType = solType.replace(trailingArrayRegex, ''); - const arrayItemTsType = utils.solTypeToTsType(paramKind, backend, arrayItemSolType, components); - const arrayTsType = - utils.isUnionType(arrayItemTsType) || utils.isObjectType(arrayItemTsType) - ? `Array<${arrayItemTsType}>` - : `${arrayItemTsType}[]`; - return arrayTsType; - } else { - const solTypeRegexToTsType = [ - { regex: '^string$', tsType: 'string' }, - { regex: '^address$', tsType: 'string' }, - { regex: '^bool$', tsType: 'boolean' }, - { regex: '^u?int\\d*$', tsType: 'BigNumber' }, - { regex: '^bytes\\d*$', tsType: 'string' }, - ]; - if (paramKind === ParamKind.Input) { - // web3 and ethers allow to pass those as numbers instead of bignumbers - solTypeRegexToTsType.unshift({ - regex: '^u?int(8|16|32)?$', - tsType: 'number|BigNumber', - }); - } - if (backend === ContractsBackend.Ethers && paramKind === ParamKind.Output) { - // ethers-contracts automatically converts small BigNumbers to numbers - solTypeRegexToTsType.unshift({ - regex: '^u?int(8|16|32|48)?$', - tsType: 'number', - }); - } - for (const regexAndTxType of solTypeRegexToTsType) { - const { regex, tsType } = regexAndTxType; - if (solType.match(regex)) { - return tsType; - } - } - const TUPLE_TYPE_REGEX = '^tuple$'; - if (solType.match(TUPLE_TYPE_REGEX)) { - const componentsType = _.map(components, component => { - const componentValueType = utils.solTypeToTsType( - paramKind, - backend, - component.type, - component.components, - ); - const componentType = `${component.name}: ${componentValueType}`; - return componentType; - }); - const tsType = `{${componentsType.join(';')}}`; - return tsType; - } - throw new Error(`Unknown Solidity type found: ${solType}`); - } - }, - isUnionType(tsType: string): boolean { - return tsType === 'number|BigNumber'; - }, - isObjectType(tsType: string): boolean { - return /^{.*}$/.test(tsType); - }, - getPartialNameFromFileName(filename: string): string { - const name = path.parse(filename).name; - return name; - }, - getNamedContent(filename: string): { name: string; content: string } { - const name = utils.getPartialNameFromFileName(filename); - try { - const content = fs.readFileSync(filename).toString(); - return { - name, - content, - }; - } catch (err) { - throw new Error(`Failed to read ${filename}: ${err}`); - } - }, - getEmptyConstructor(): ConstructorAbi { - return { - type: AbiType.Constructor, - stateMutability: 'nonpayable', - payable: false, - inputs: [], - }; - }, - makeOutputFileName(name: string): string { - let fileName = toSnakeCase(name); - // HACK: Snake case doesn't make a lot of sense for abbreviated names but we can't reliably detect abbreviations - // so we special-case the abbreviations we use. - fileName = fileName.replace('z_r_x', 'zrx').replace('e_r_c', 'erc'); - return fileName; - }, - writeOutputFile(filePath: string, renderedTsCode: string): void { - fs.writeFileSync(filePath, renderedTsCode); - }, - isOutputFileUpToDate(abiFile: string, outputFile: string): boolean { - const abiFileModTimeMs = fs.statSync(abiFile).mtimeMs; - try { - const outFileModTimeMs = fs.statSync(outputFile).mtimeMs; - return outFileModTimeMs > abiFileModTimeMs; - } catch (err) { - if (err.code === 'ENOENT') { - return false; - } else { - throw err; - } - } - }, -}; diff --git a/packages/abi-gen/test/utils_test.ts b/packages/abi-gen/test/utils_test.ts deleted file mode 100644 index 820c0c675..000000000 --- a/packages/abi-gen/test/utils_test.ts +++ /dev/null @@ -1,86 +0,0 @@ -import * as chai from 'chai'; -import * as dirtyChai from 'dirty-chai'; -import * as fs from 'fs'; -import 'mocha'; -import * as tmp from 'tmp'; - -import { utils } from '../src/utils'; - -tmp.setGracefulCleanup(); // remove tmp files even if there are failures - -chai.use(dirtyChai); - -const expect = chai.expect; - -describe('makeOutputFileName()', () => { - it('should handle Metacoin usage', () => { - expect(utils.makeOutputFileName('Metacoin')).to.equal('metacoin'); - }); - it('should handle special zrx_token case', () => { - expect(utils.makeOutputFileName('ZRXToken')).to.equal('zrx_token'); - }); - it('should handle special erc_token case', () => { - expect(utils.makeOutputFileName('ERC20Token')).to.equal('erc20_token'); - }); -}); - -describe('writeOutputFile()', () => { - let tempFilePath: string; - before(() => { - tempFilePath = tmp.fileSync( - { discardDescriptor: true }, // close file (so we can update it) - ).name; - }); - it('should write content to output file', () => { - const content = 'hello world'; - - utils.writeOutputFile(tempFilePath, content); - - expect(fs.readFileSync(tempFilePath).toString()).to.equal(content); - }); -}); - -describe('isOutputFileUpToDate()', () => { - it('should throw ENOENT when there is no abi file', () => { - expect(utils.isOutputFileUpToDate.bind('nonexistant1', 'nonexistant2')).to.throw('ENOENT'); - }); - - describe('when the abi input file exists', () => { - let abiFile: string; - before(() => { - abiFile = tmp.fileSync( - { discardDescriptor: true }, // close file (set timestamp) - ).name; - }); - - describe('without an existing output file', () => { - it('should return false', () => { - expect(utils.isOutputFileUpToDate(abiFile, 'nonexistant_file')).to.be.false(); - }); - }); - - describe('with an existing output file', () => { - let outputFile: string; - before(() => { - outputFile = tmp.fileSync( - { discardDescriptor: true }, // close file (set timestamp) - ).name; - const abiFileModTimeMs = fs.statSync(abiFile).mtimeMs; - const outfileModTimeMs = abiFileModTimeMs + 1; - fs.utimesSync(outputFile, outfileModTimeMs, outfileModTimeMs); - }); - - it('should return true when output file is newer than abi file', async () => { - expect(utils.isOutputFileUpToDate(abiFile, outputFile)).to.be.true(); - }); - - it('should return false when output file exists but is older than abi file', () => { - const outFileModTimeMs = fs.statSync(outputFile).mtimeMs; - const abiFileModTimeMs = outFileModTimeMs + 1; - fs.utimesSync(abiFile, abiFileModTimeMs, abiFileModTimeMs); - - expect(utils.isOutputFileUpToDate(abiFile, outputFile)).to.be.false(); - }); - }); - }); -}); diff --git a/packages/abi-gen/tsconfig.json b/packages/abi-gen/tsconfig.json deleted file mode 100644 index 2ee711adc..000000000 --- a/packages/abi-gen/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "rootDir": "." - }, - "include": ["./src/**/*", "./test/**/*"] -} diff --git a/packages/abi-gen/tslint.json b/packages/abi-gen/tslint.json deleted file mode 100644 index dd9053357..000000000 --- a/packages/abi-gen/tslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": ["@0x/tslint-config"] -} |