diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-06 23:39:45 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-02-07 09:27:47 +0800 |
commit | 0c2ab2265624eb0dc18244b263fed3c8788b5c09 (patch) | |
tree | c3e4ecd36e3242e23b2caa2b991a7a103a3994b0 /packages/contracts/src/contract_wrappers | |
parent | 47adad5122cea7c2bac54c6e6b83be55a2b6609a (diff) | |
download | dexon-sol-tools-0c2ab2265624eb0dc18244b263fed3c8788b5c09.tar dexon-sol-tools-0c2ab2265624eb0dc18244b263fed3c8788b5c09.tar.gz dexon-sol-tools-0c2ab2265624eb0dc18244b263fed3c8788b5c09.tar.bz2 dexon-sol-tools-0c2ab2265624eb0dc18244b263fed3c8788b5c09.tar.lz dexon-sol-tools-0c2ab2265624eb0dc18244b263fed3c8788b5c09.tar.xz dexon-sol-tools-0c2ab2265624eb0dc18244b263fed3c8788b5c09.tar.zst dexon-sol-tools-0c2ab2265624eb0dc18244b263fed3c8788b5c09.zip |
Add base_contract.ts
Diffstat (limited to 'packages/contracts/src/contract_wrappers')
-rw-r--r-- | packages/contracts/src/contract_wrappers/generated/base_contract.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/packages/contracts/src/contract_wrappers/generated/base_contract.ts b/packages/contracts/src/contract_wrappers/generated/base_contract.ts new file mode 100644 index 000000000..2d77b3ab1 --- /dev/null +++ b/packages/contracts/src/contract_wrappers/generated/base_contract.ts @@ -0,0 +1,35 @@ +import {TxData, TxDataPayable} from '@0xproject/types'; +import * as _ from 'lodash'; +import * as Web3 from 'web3'; + +export class BaseContract { + public address: string; + protected _web3ContractInstance: Web3.ContractInstance; + protected _defaults: Partial<TxData>; + protected async _applyDefaultsToTxDataAsync<T extends 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 = { + ...removeUndefinedProperties(this._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 + }; + if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) { + const estimatedGas = await estimateGasAsync(txData); + txDataWithDefaults.gas = estimatedGas; + } + return txDataWithDefaults; + } + constructor(web3ContractInstance: Web3.ContractInstance, defaults?: Partial<TxData>) { + this.address = web3ContractInstance.address; + this._web3ContractInstance = web3ContractInstance; + this._defaults = defaults || {}; + } +} |