diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-24 03:35:44 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-28 04:05:23 +0800 |
commit | 2d561bc8a05e8d1fca91cde93bae2080d87be926 (patch) | |
tree | 10d785eff73c67ecae09a337ed3721ff6b6102a9 /packages/0x.js/contract_templates/partials | |
parent | f5275d3ad75d2a989556de99cdef82bcf2cd687c (diff) | |
download | dexon-sol-tools-2d561bc8a05e8d1fca91cde93bae2080d87be926.tar dexon-sol-tools-2d561bc8a05e8d1fca91cde93bae2080d87be926.tar.gz dexon-sol-tools-2d561bc8a05e8d1fca91cde93bae2080d87be926.tar.bz2 dexon-sol-tools-2d561bc8a05e8d1fca91cde93bae2080d87be926.tar.lz dexon-sol-tools-2d561bc8a05e8d1fca91cde93bae2080d87be926.tar.xz dexon-sol-tools-2d561bc8a05e8d1fca91cde93bae2080d87be926.tar.zst dexon-sol-tools-2d561bc8a05e8d1fca91cde93bae2080d87be926.zip |
Allow users to specify the contracts backend in abi-gen
Diffstat (limited to 'packages/0x.js/contract_templates/partials')
-rw-r--r-- | packages/0x.js/contract_templates/partials/call.handlebars | 20 | ||||
-rw-r--r-- | packages/0x.js/contract_templates/partials/tx.handlebars | 36 |
2 files changed, 35 insertions, 21 deletions
diff --git a/packages/0x.js/contract_templates/partials/call.handlebars b/packages/0x.js/contract_templates/partials/call.handlebars index 0475136f0..c533712b7 100644 --- a/packages/0x.js/contract_templates/partials/call.handlebars +++ b/packages/0x.js/contract_templates/partials/call.handlebars @@ -4,12 +4,20 @@ public {{this.name}} = { defaultBlock?: Web3.BlockParam, ): Promise<{{> return_type outputs=outputs}}> { const self = this as {{contractName}}Contract; - const result = await promisify<{{> return_type outputs=outputs}}>( - self._web3ContractInstance.{{this.name}}.call, - self._web3ContractInstance, - )( + const inputAbi = _.find(this._abi, {name: '{{this.name}}'}).inputs; + [{{> params inputs=inputs}}] = BaseContract._transformABIData(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(this)); + const callDescription = self._ethersInterface.functions.{{this.name}}( {{> params inputs=inputs}} - ); - return result; + ) as ethersContracts.CallDescription; + const callData = await self._applyDefaultsToTxDataAsync( + { + data: callDescription.data, + } + ) + const rawCallResult = await self._web3Wrapper.callAsync(callData); + let resultArray = callDescription.parse(rawCallResult); + const outputAbi = _.find(this._abi, {name: '{{this.name}}'}).outputs; + resultArray = BaseContract._transformABIData(outputAbi, resultArray, BaseContract._lowercaseAddress.bind(this)); + return resultArray{{#singleReturnValue}}[0]{{/singleReturnValue}}; }, }; diff --git a/packages/0x.js/contract_templates/partials/tx.handlebars b/packages/0x.js/contract_templates/partials/tx.handlebars index 9df83266a..aae9aa404 100644 --- a/packages/0x.js/contract_templates/partials/tx.handlebars +++ b/packages/0x.js/contract_templates/partials/tx.handlebars @@ -9,19 +9,22 @@ public {{this.name}} = { {{/this.payable}} ): Promise<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 data = this._ethersInterface.functions.{{this.name}}( + {{> params inputs=inputs}} + ).data const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( - txData, + { + ...txData, + data, + }, self.{{this.name}}.estimateGasAsync.bind( self, {{> params inputs=inputs}} ), ); - const txHash = await promisify<string>( - self._web3ContractInstance.{{this.name}}, self._web3ContractInstance, - )( - {{> params inputs=inputs}} - txDataWithDefaults, - ); + const txHash = await this._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, async estimateGasAsync( @@ -29,15 +32,16 @@ public {{this.name}} = { txData: TxData = {}, ): Promise<number> { const self = this as {{contractName}}Contract; - const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( - txData, - ); - const gas = await promisify<number>( - self._web3ContractInstance.{{this.name}}.estimateGas, self._web3ContractInstance, - )( + const data = this._ethersInterface.functions.{{this.name}}( {{> params inputs=inputs}} - txDataWithDefaults, + ).data + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { + ...txData, + data, + } ); + const gas = await this._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, getABIEncodedTransactionData( @@ -45,7 +49,9 @@ public {{this.name}} = { txData: TxData = {}, ): string { const self = this as {{contractName}}Contract; - const abiEncodedTransactionData = self._web3ContractInstance.{{this.name}}.getData(); + const abiEncodedTransactionData = this._ethersInterface.functions.{{this.name}}( + {{> params inputs=inputs}} + ).data return abiEncodedTransactionData; }, }; |