diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-24 04:20:59 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-28 04:05:23 +0800 |
commit | fe8f2d8d898e9909636366c9ceee37a5e9481573 (patch) | |
tree | 16be81a7d12e527c65084b972b39a4fe27c3267f /packages | |
parent | 2d561bc8a05e8d1fca91cde93bae2080d87be926 (diff) | |
download | dexon-sol-tools-fe8f2d8d898e9909636366c9ceee37a5e9481573.tar.gz dexon-sol-tools-fe8f2d8d898e9909636366c9ceee37a5e9481573.tar.zst dexon-sol-tools-fe8f2d8d898e9909636366c9ceee37a5e9481573.zip |
Add support for ABIv2 to abi-gen
Diffstat (limited to 'packages')
-rw-r--r-- | packages/0x.js/contract_templates/partials/event.handlebars | 2 | ||||
-rw-r--r-- | packages/0x.js/contract_templates/partials/return_type.handlebars | 4 | ||||
-rw-r--r-- | packages/0x.js/contract_templates/partials/typed_params.handlebars | 2 | ||||
-rw-r--r-- | packages/0x.js/package.json | 2 | ||||
-rw-r--r-- | packages/abi-gen/CHANGELOG.md | 1 | ||||
-rw-r--r-- | packages/abi-gen/src/utils.ts | 34 |
6 files changed, 35 insertions, 10 deletions
diff --git a/packages/0x.js/contract_templates/partials/event.handlebars b/packages/0x.js/contract_templates/partials/event.handlebars index 6d68d4c0f..3c6100e4f 100644 --- a/packages/0x.js/contract_templates/partials/event.handlebars +++ b/packages/0x.js/contract_templates/partials/event.handlebars @@ -1,5 +1,5 @@ export interface {{name}}ContractEventArgs { {{#each inputs}} - {{name}}: {{#returnType type}}{{/returnType}}; + {{name}}: {{#returnType type components}}{{/returnType}}; {{/each}} } diff --git a/packages/0x.js/contract_templates/partials/return_type.handlebars b/packages/0x.js/contract_templates/partials/return_type.handlebars index 383961a40..268ad15f7 100644 --- a/packages/0x.js/contract_templates/partials/return_type.handlebars +++ b/packages/0x.js/contract_templates/partials/return_type.handlebars @@ -1,6 +1,6 @@ {{#singleReturnValue}} -{{#returnType outputs.0.type}}{{/returnType}} +{{#returnType outputs.0.type outputs.0.components}}{{/returnType}} {{/singleReturnValue}} {{^singleReturnValue}} -[{{#each outputs}}{{#returnType type}}{{/returnType}}{{#unless @last}}, {{/unless}}{{/each}}] +[{{#each outputs}}{{#returnType type components}}{{/returnType}}{{#unless @last}}, {{/unless}}{{/each}}] {{/singleReturnValue}} diff --git a/packages/0x.js/contract_templates/partials/typed_params.handlebars b/packages/0x.js/contract_templates/partials/typed_params.handlebars index 3ea4b2e95..c100e58f7 100644 --- a/packages/0x.js/contract_templates/partials/typed_params.handlebars +++ b/packages/0x.js/contract_templates/partials/typed_params.handlebars @@ -1,3 +1,3 @@ {{#each inputs}} - {{name}}: {{#parameterType type}}{{/parameterType}}, + {{name}}: {{#parameterType type components}}{{/parameterType}}, {{/each}} diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 6a0a84cfc..78cba529a 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -17,7 +17,7 @@ "build": "run-p build:umd:prod build:commonjs; exit 0;", "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_DIR", "upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json", - "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template contract_templates/contract.handlebars --partials 'contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated && prettier --write 'src/contract_wrappers/generated/**.ts'", + "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template contract_templates/contract.handlebars --partials 'contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'", "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", "test:circleci": "run-s test:coverage report_test_coverage", "test": "run-s clean test:commonjs", diff --git a/packages/abi-gen/CHANGELOG.md b/packages/abi-gen/CHANGELOG.md index 7e589551e..17186570e 100644 --- a/packages/abi-gen/CHANGELOG.md +++ b/packages/abi-gen/CHANGELOG.md @@ -3,6 +3,7 @@ ## v0.2.3 - _TBD, 2018_ * Add a `backend` parameter that allows you to specify your backend (web3 or ethers). Ethers auto-converts small ints to numbers (#TBD) + * Add support for ABIv2 (#TBD) ## v0.2.1 - _February 9, 2018_ diff --git a/packages/abi-gen/src/utils.ts b/packages/abi-gen/src/utils.ts index dc2c5390e..349604aec 100644 --- a/packages/abi-gen/src/utils.ts +++ b/packages/abi-gen/src/utils.ts @@ -6,14 +6,20 @@ import * as Web3 from 'web3'; import { AbiType, ContractsBackend, ParamKind } from './types'; export const utils = { - solTypeToTsType(paramKind: ParamKind, backend: ContractsBackend, solType: string): string { + solTypeToTsType( + paramKind: ParamKind, + backend: ContractsBackend, + solType: string, + components?: Web3.DataItem[], + ): string { const trailingArrayRegex = /\[\d*\]$/; if (solType.match(trailingArrayRegex)) { const arrayItemSolType = solType.replace(trailingArrayRegex, ''); - const arrayItemTsType = utils.solTypeToTsType(paramKind, backend, arrayItemSolType); - const arrayTsType = utils.isUnionType(arrayItemTsType) - ? `Array<${arrayItemTsType}>` - : `${arrayItemTsType}[]`; + const arrayItemTsType = utils.solTypeToTsType(paramKind, backend, arrayItemSolType, components); + const arrayTsType = + utils.isUnionType(arrayItemTsType) || utils.isObjectType(arrayItemTsType) + ? `Array<${arrayItemTsType}>` + : `${arrayItemTsType}[]`; return arrayTsType; } else { const solTypeRegexToTsType = [ @@ -45,12 +51,30 @@ export const utils = { 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}}`; + 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); + }, log(...args: any[]): void { console.log(...args); // tslint:disable-line:no-console }, |