From d72b7299c66ea6d63eb14595b06456c02b2ad99b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 27 Mar 2018 15:19:23 +0200 Subject: Move common types out of web3 types --- packages/contract_templates/contract.handlebars | 4 ++-- .../partials/callAsync.handlebars | 19 ++++++--------- packages/contract_templates/partials/tx.handlebars | 27 +++++++++++----------- 3 files changed, 22 insertions(+), 28 deletions(-) (limited to 'packages/contract_templates') diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars index 132cd60cc..08310c8f2 100644 --- a/packages/contract_templates/contract.handlebars +++ b/packages/contract_templates/contract.handlebars @@ -5,7 +5,7 @@ // tslint:disable:no-consecutive-blank-lines // tslint:disable-next-line:no-unused-variable import { BaseContract } from '@0xproject/base-contract'; -import { TxData, TxDataPayable } from '@0xproject/types'; +import { BlockParam, BlockParamLiteral, CallData, ContractAbi, DataItem, MethodAbi, TxData, TxDataPayable } from '@0xproject/types'; import { BigNumber, classUtils, promisify } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as ethersContracts from 'ethers-contracts'; @@ -40,7 +40,7 @@ export class {{contractName}}Contract extends BaseContract { {{> tx contractName=../contractName}} {{/this.constant}} {{/each}} - constructor(web3Wrapper: Web3Wrapper, abi: Web3.ContractAbi, address: string) { + constructor(web3Wrapper: Web3Wrapper, abi: ContractAbi, address: string) { super(web3Wrapper, abi, address); classUtils.bindAll(this, ['_ethersInterface', 'address', 'abi', '_web3Wrapper']); } diff --git a/packages/contract_templates/partials/callAsync.handlebars b/packages/contract_templates/partials/callAsync.handlebars index 93d347145..2d9028ad5 100644 --- a/packages/contract_templates/partials/callAsync.handlebars +++ b/packages/contract_templates/partials/callAsync.handlebars @@ -1,27 +1,22 @@ {{#hasReturnValue}} async callAsync( {{> typed_params inputs=inputs}} -{{#this.payable}} - txData: TxDataPayable = {}, -{{/this.payable}} -{{^this.payable}} - txData: TxData = {}, -{{/this.payable}} - defaultBlock?: Web3.BlockParam, + callData: Partial = {}, + defaultBlock?: BlockParam, ): Promise<{{> return_type outputs=outputs}}> { const self = this as {{contractName}}Contract; - const inputAbi = _.find(this.abi, {name: '{{this.name}}'}).inputs; - [{{> params inputs=inputs}}] = BaseContract._transformABIData(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(this)); + const inputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).inputs; + [{{> params inputs=inputs}}] = BaseContract._transformABIData(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self)); const encodedData = self._ethersInterface.functions.{{this.name}}( {{> params inputs=inputs}} ).data; - const callData = await self._applyDefaultsToTxDataAsync( + const callDataWithDefaults = await self._applyDefaultsToTxDataAsync( { data: encodedData, } ) - const rawCallResult = await self._web3Wrapper.callAsync(callData, defaultBlock); - const outputAbi = _.find(this.abi, {name: '{{this.name}}'}).outputs as Web3.DataItem[]; + const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + const outputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).outputs as DataItem[]; const outputParamsTypes = _.map(outputAbi, 'type'); let resultArray = ethersContracts.Interface.decodeParams(outputParamsTypes, rawCallResult) as any; resultArray = BaseContract._transformABIData(outputAbi, resultArray, BaseContract._lowercaseAddress.bind(this)); diff --git a/packages/contract_templates/partials/tx.handlebars b/packages/contract_templates/partials/tx.handlebars index d517a9f7f..f76de3a70 100644 --- a/packages/contract_templates/partials/tx.handlebars +++ b/packages/contract_templates/partials/tx.handlebars @@ -2,16 +2,16 @@ public {{this.name}} = { async sendTransactionAsync( {{> typed_params inputs=inputs}} {{#this.payable}} - txData: TxDataPayable = {}, + txData: Partial = {}, {{/this.payable}} {{^this.payable}} - txData: TxData = {}, + txData: Partial = {}, {{/this.payable}} ): Promise { const self = this as {{contractName}}Contract; - const inputAbi = _.find(this.abi, {name: '{{this.name}}'}).inputs; - [{{> params inputs=inputs}}] = BaseContract._transformABIData(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(this)); - const encodedData = this._ethersInterface.functions.{{this.name}}( + const inputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).inputs; + [{{> params inputs=inputs}}] = BaseContract._transformABIData(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self)); + const encodedData = self._ethersInterface.functions.{{this.name}}( {{> params inputs=inputs}} ).data const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( @@ -24,17 +24,17 @@ public {{this.name}} = { {{> params inputs=inputs}} ), ); - const txHash = await this._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, async estimateGasAsync( {{> typed_params inputs=inputs}} - txData: TxData = {}, + txData: Partial = {}, ): Promise { const self = this as {{contractName}}Contract; - const inputAbi = _.find(this.abi, {name: '{{this.name}}'}).inputs; + const inputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).inputs; [{{> params inputs=inputs}}] = BaseContract._transformABIData(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(this)); - const encodedData = this._ethersInterface.functions.{{this.name}}( + const encodedData = self._ethersInterface.functions.{{this.name}}( {{> params inputs=inputs}} ).data const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( @@ -43,17 +43,16 @@ public {{this.name}} = { data: encodedData, } ); - const gas = await this._web3Wrapper.estimateGasAsync(txDataWithDefaults); + const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, getABIEncodedTransactionData( {{> typed_params inputs=inputs}} - txData: TxData = {}, ): string { const self = this as {{contractName}}Contract; - const inputAbi = _.find(this.abi, {name: '{{this.name}}'}).inputs; - [{{> params inputs=inputs}}] = BaseContract._transformABIData(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(this)); - const abiEncodedTransactionData = this._ethersInterface.functions.{{this.name}}( + const inputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).inputs; + [{{> params inputs=inputs}}] = BaseContract._transformABIData(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self)); + const abiEncodedTransactionData = self._ethersInterface.functions.{{this.name}}( {{> params inputs=inputs}} ).data return abiEncodedTransactionData; -- cgit v1.2.3