diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-05-10 21:02:32 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-05-10 23:47:38 +0800 |
commit | 7eb9444458f8c86cbc9c7be47879802c52ece57a (patch) | |
tree | 749c90f1bc547dfb7795057bc2b6aadf709b7319 /packages | |
parent | ebc296ea3150672c6998fcbdefbbb18433030719 (diff) | |
download | dexon-sol-tools-7eb9444458f8c86cbc9c7be47879802c52ece57a.tar.gz dexon-sol-tools-7eb9444458f8c86cbc9c7be47879802c52ece57a.tar.zst dexon-sol-tools-7eb9444458f8c86cbc9c7be47879802c52ece57a.zip |
Remove _applyDefaultsToDeployTxDataAsync
Diffstat (limited to 'packages')
-rw-r--r-- | packages/base-contract/src/index.ts | 23 | ||||
-rw-r--r-- | packages/contract_templates/contract.handlebars | 2 | ||||
-rw-r--r-- | packages/contract_templates/partials/callAsync.handlebars | 5 | ||||
-rw-r--r-- | packages/contract_templates/partials/tx.handlebars | 8 |
4 files changed, 13 insertions, 25 deletions
diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 8558bceea..2b39029d5 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -60,37 +60,22 @@ export class BaseContract { protected static _bnToBigNumber(type: string, value: any): any { return _.isObject(value) && value._bn ? new BigNumber(value.toString()) : value; } - protected static async _applyDefaultsToDeployTxDataAsync<T extends Partial<TxData | TxDataPayable>>( + protected static async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>( txData: T, defaults: Partial<TxData>, estimateGasAsync?: (txData: T) => Promise<number>, ): Promise<TxData> { - const txDataWithDefaults: TxData = { - ...defaults, - ...(txData as any), - }; - if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) { - const estimatedGas = await estimateGasAsync(txData); - txDataWithDefaults.gas = estimatedGas; - } - return txDataWithDefaults; - } - protected async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>( - txData: T, - estimateGasAsync?: (txData: T) => Promise<number>, - ): Promise<TxData> { // Gas amount sourced with the following priorities: // 1. Optional param passed in to public method call // 2. Global config passed in at library instantiation // 3. Gas estimate calculation + safety margin const removeUndefinedProperties = _.pickBy; - const txDataWithDefaults = ({ - to: this.address, - ...removeUndefinedProperties(this._web3Wrapper.getContractDefaults()), + const txDataWithDefaults: TxData = { + ...removeUndefinedProperties(defaults), ...removeUndefinedProperties(txData as any), // HACK: TS can't prove that T is spreadable. // Awaiting https://github.com/Microsoft/TypeScript/pull/13288 to be merged - } as any) as TxData; + } as any; if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) { const estimatedGas = await estimateGasAsync(txData); txDataWithDefaults.gas = estimatedGas; diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars index af9f15c69..0f6151690 100644 --- a/packages/contract_templates/contract.handlebars +++ b/packages/contract_templates/contract.handlebars @@ -65,7 +65,7 @@ export class {{contractName}}Contract extends BaseContract { ); const txData = ethers.Contract.getDeployTransaction(bytecode, abi, {{> params inputs=ctor.inputs}}); const web3Wrapper = new Web3Wrapper(provider); - const txDataWithDefaults = await BaseContract._applyDefaultsToDeployTxDataAsync( + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( txData, defaults, web3Wrapper.estimateGasAsync.bind(web3Wrapper), diff --git a/packages/contract_templates/partials/callAsync.handlebars b/packages/contract_templates/partials/callAsync.handlebars index 58fb2f09c..904936173 100644 --- a/packages/contract_templates/partials/callAsync.handlebars +++ b/packages/contract_templates/partials/callAsync.handlebars @@ -12,10 +12,11 @@ async callAsync( {{> params inputs=inputs}} ) as ethers.CallDescription; const encodedData = ethersFunction.data; - const callDataWithDefaults = await self._applyDefaultsToTxDataAsync( + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( { data: encodedData, - } + }, + this._web3Wrapper.getContractDefaults(), ) const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); let resultArray = ethersFunction.parse(rawCallResult); diff --git a/packages/contract_templates/partials/tx.handlebars b/packages/contract_templates/partials/tx.handlebars index feefd3870..f72078a4e 100644 --- a/packages/contract_templates/partials/tx.handlebars +++ b/packages/contract_templates/partials/tx.handlebars @@ -14,11 +14,12 @@ public {{this.tsName}} = { const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}( {{> params inputs=inputs}} ).data; - const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( { ...txData, data: encodedData, }, + this._web3Wrapper.getContractDefaults(), self.{{this.tsName}}.estimateGasAsync.bind( self, {{> params inputs=inputs}} @@ -37,11 +38,12 @@ public {{this.tsName}} = { const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}( {{> params inputs=inputs}} ).data; - const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( { ...txData, data: encodedData, - } + }, + this._web3Wrapper.getContractDefaults(), ); const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; |