From 4a2e4d2b55c89c91cebf434570feee91ccc449fa Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Wed, 13 Jun 2018 23:09:36 -0400 Subject: Document contract_templates --- packages/contract_templates/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 packages/contract_templates/README.md (limited to 'packages/contract_templates') diff --git a/packages/contract_templates/README.md b/packages/contract_templates/README.md new file mode 100644 index 000000000..39aa2d2c0 --- /dev/null +++ b/packages/contract_templates/README.md @@ -0,0 +1,15 @@ +These templates are used with [abi-gen](https://github.com/0xProject/0x-monorepo/tree/development/packages/abi-gen). + +To successfully compile the generated TypeScript contract wrappers, you must: +* Install the packages on which the main contract template directly depends: `yarn add @0xproject/base-contract @0xproject/sol-compiler @0xproject/types @0xproject/utils @0xproject/web3-wrapper ethers lodash` +* Install the packages on which the main contract template *in*directly depends: `yarn add @types/lodash` +* Ensure that your TypeScript configuration includes the following: +``` +"compilerOptions": { + "lib": ["ES2015"], + "typeRoots": [ + "node_modules/@0xproject/typescript-typings/types", + "node_modules/@types" + ] +} +``` -- cgit v1.2.3 From 15a63c4bc5e05583d15910a562d524ca9b1e4b9d Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Wed, 13 Jun 2018 23:09:59 -0400 Subject: workaround for TypeScript trailing comma bug before this change, TypeScript compilation of the generated contract wrapper was giving me the following errors: $ abi-gen --abis 'build/contracts/*.json' --out build/types --template contract_templates/contract.handlebars --partials 'contract_templates/partials/*.handlebars' Found 7 partial templates Found 1 ABI files Processing: Migrations... Created: build/types/migrations.ts $ tsc build/types/migrations.ts(81,23): error TS1013: A rest parameter or binding pattern may not have a trailing comma. build/types/migrations.ts(108,23): error TS1013: A rest parameter or binding pattern may not have a trailing comma. build/types/migrations.ts(130,23): error TS1013: A rest parameter or binding pattern may not have a trailing comma. build/types/migrations.ts(146,25): error TS1013: A rest parameter or binding pattern may not have a trailing comma. build/types/migrations.ts(173,25): error TS1013: A rest parameter or binding pattern may not have a trailing comma. build/types/migrations.ts(195,25): error TS1013: A rest parameter or binding pattern may not have a trailing comma. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. Here is the generated code around the first error: 74: public setCompleted = { 75: async sendTransactionAsync( 76: completed: BigNumber, 77: txData: Partial = {}, 78: ): Promise { 79: const self = this as any as MigrationsContract; 80: const inputAbi = self._lookupAbi('setCompleted(uint256)').inputs; 81: [completed, 82: ] = BaseContract._formatABIDataItemList(inputAbi, [completed, 83: ], BaseContract._bigNumberToString.bind(self)); All of the other errors are the same, a destructuring assignment with a single element but with a trailing comma. This is legal JavaScript but it is not allowed by the TypeScript compiler, apparently per the bug described at https://github.com/Microsoft/TypeScript/issues/24628 . While awaiting the 3.0 version of TypeScript, it's a simple enough change to have the template not append a trailing comma. --- packages/contract_templates/partials/params.handlebars | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contract_templates') diff --git a/packages/contract_templates/partials/params.handlebars b/packages/contract_templates/partials/params.handlebars index ac5d4ae85..2d9bb8ed9 100644 --- a/packages/contract_templates/partials/params.handlebars +++ b/packages/contract_templates/partials/params.handlebars @@ -1,3 +1,3 @@ {{#each inputs}} -{{name}}, +{{name}}{{#if @last}}{{else}},{{/if}} {{/each}} -- cgit v1.2.3 From f9e05d0cad9ab4624be2ce546e04aba109dec829 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Thu, 14 Jun 2018 09:38:18 -0400 Subject: remove mistaken comment It must have been left over from when an abi-gen output was modified to be the source of this template. --- packages/contract_templates/contract.handlebars | 4 ---- 1 file changed, 4 deletions(-) (limited to 'packages/contract_templates') diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars index 431359109..997088c8f 100644 --- a/packages/contract_templates/contract.handlebars +++ b/packages/contract_templates/contract.handlebars @@ -1,7 +1,3 @@ -/** - * This file is auto-generated using abi-gen. Don't edit directly. - * Templates can be found at https://github.com/0xProject/0x-monorepo/tree/development/packages/contract_templates. - */ // tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma whitespace // tslint:disable:no-unused-variable import { BaseContract } from '@0xproject/base-contract'; -- cgit v1.2.3 From 8bac1706a119c0c4c02bbca77553976080f5ee20 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Fri, 15 Jun 2018 10:37:37 -0400 Subject: change @0xproject/types to ethereum-types --- packages/contract_templates/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contract_templates') diff --git a/packages/contract_templates/README.md b/packages/contract_templates/README.md index 39aa2d2c0..9546506c5 100644 --- a/packages/contract_templates/README.md +++ b/packages/contract_templates/README.md @@ -1,7 +1,7 @@ These templates are used with [abi-gen](https://github.com/0xProject/0x-monorepo/tree/development/packages/abi-gen). To successfully compile the generated TypeScript contract wrappers, you must: -* Install the packages on which the main contract template directly depends: `yarn add @0xproject/base-contract @0xproject/sol-compiler @0xproject/types @0xproject/utils @0xproject/web3-wrapper ethers lodash` +* Install the packages on which the main contract template directly depends: `yarn add @0xproject/base-contract @0xproject/sol-compiler @0xproject/utils @0xproject/web3-wrapper ethereum-types ethers lodash` * Install the packages on which the main contract template *in*directly depends: `yarn add @types/lodash` * Ensure that your TypeScript configuration includes the following: ``` -- cgit v1.2.3