From 12ae7c009d548c2b7241b3a3896b159f1829a500 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 19 Apr 2018 11:21:32 +1000 Subject: Support Tuples from function returns --- .../contract_templates/partials/callAsync.handlebars | 19 +++++++++++-------- .../partials/return_type.handlebars | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'packages/contract_templates/partials') diff --git a/packages/contract_templates/partials/callAsync.handlebars b/packages/contract_templates/partials/callAsync.handlebars index a6f4abdf2..3cc16ccc6 100644 --- a/packages/contract_templates/partials/callAsync.handlebars +++ b/packages/contract_templates/partials/callAsync.handlebars @@ -5,22 +5,25 @@ async callAsync( defaultBlock?: BlockParam, ): Promise<{{> return_type outputs=outputs}}> { const self = this as any as {{contractName}}Contract; - const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs; + const functionSignature = '{{this.functionSignature}}'; + const inputAbi = self._lookupAbi(functionSignature).inputs; [{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self)); - const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}( + const ethersFunction = self._lookupEthersInterface(functionSignature).functions.{{this.name}}( {{> params inputs=inputs}} - ).data; + ) as ethers.CallDescription; + const encodedData = ethersFunction.data; const callDataWithDefaults = await self._applyDefaultsToTxDataAsync( { data: encodedData, } ) const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + let result = ethersFunction.parse(rawCallResult); + const outputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).outputs; - const outputParamsTypes = _.map(outputAbi, 'type'); - let resultArray = ethersContracts.Interface.decodeParams(outputParamsTypes, rawCallResult) as any; - resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._lowercaseAddress.bind(this)); - resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._bnToBigNumber.bind(this)); - return resultArray{{#singleReturnValue}}[0]{{/singleReturnValue}}; + result = BaseContract._formatABIDataItemList(outputAbi, result, BaseContract._lowercaseAddress.bind(this)); + result = BaseContract._formatABIDataItemList(outputAbi, result, BaseContract._bnToBigNumber.bind(this)); + + return result{{#singleReturnValue}}[0]{{/singleReturnValue}}; }, {{/hasReturnValue}} diff --git a/packages/contract_templates/partials/return_type.handlebars b/packages/contract_templates/partials/return_type.handlebars index 9dd509953..77d96e8c4 100644 --- a/packages/contract_templates/partials/return_type.handlebars +++ b/packages/contract_templates/partials/return_type.handlebars @@ -1,6 +1,6 @@ {{#if outputs.length}} {{#singleReturnValue}} -{{#returnType outputs.0.type components}}{{/returnType}} +{{#returnType outputs.0.type outputs.0.components}}{{/returnType}} {{/singleReturnValue}} {{^singleReturnValue}} [{{#each outputs}}{{#returnType type components}}{{/returnType}}{{#unless @last}}, {{/unless}}{{/each}}] -- cgit v1.2.3 From 5c232b6a8d3920ed987fcc9b158a17a62a953172 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 19 Apr 2018 16:54:42 +1000 Subject: Update CHANGELOGs --- packages/contract_templates/partials/callAsync.handlebars | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'packages/contract_templates/partials') diff --git a/packages/contract_templates/partials/callAsync.handlebars b/packages/contract_templates/partials/callAsync.handlebars index 3cc16ccc6..58fb2f09c 100644 --- a/packages/contract_templates/partials/callAsync.handlebars +++ b/packages/contract_templates/partials/callAsync.handlebars @@ -18,12 +18,10 @@ async callAsync( } ) const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); - let result = ethersFunction.parse(rawCallResult); - + let resultArray = ethersFunction.parse(rawCallResult); const outputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).outputs; - result = BaseContract._formatABIDataItemList(outputAbi, result, BaseContract._lowercaseAddress.bind(this)); - result = BaseContract._formatABIDataItemList(outputAbi, result, BaseContract._bnToBigNumber.bind(this)); - - return result{{#singleReturnValue}}[0]{{/singleReturnValue}}; + resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._lowercaseAddress.bind(this)); + resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._bnToBigNumber.bind(this)); + return resultArray{{#singleReturnValue}}[0]{{/singleReturnValue}}; }, {{/hasReturnValue}} -- cgit v1.2.3