diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-12-02 12:43:45 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-12-02 13:31:11 +0800 |
commit | 0fc356740aa59cdef0ec193a83468ef0f261ca6b (patch) | |
tree | d0981bba8986295fe5f76f7fb3dea75abd53b711 /packages/0x.js/src/contract_wrappers/generated/base_contract.ts | |
parent | f285a46d05c8d30e516459b243106659c7351f6f (diff) | |
download | dexon-0x-contracts-0fc356740aa59cdef0ec193a83468ef0f261ca6b.tar dexon-0x-contracts-0fc356740aa59cdef0ec193a83468ef0f261ca6b.tar.gz dexon-0x-contracts-0fc356740aa59cdef0ec193a83468ef0f261ca6b.tar.bz2 dexon-0x-contracts-0fc356740aa59cdef0ec193a83468ef0f261ca6b.tar.lz dexon-0x-contracts-0fc356740aa59cdef0ec193a83468ef0f261ca6b.tar.xz dexon-0x-contracts-0fc356740aa59cdef0ec193a83468ef0f261ca6b.tar.zst dexon-0x-contracts-0fc356740aa59cdef0ec193a83468ef0f261ca6b.zip |
Add generated contract wrappers
Diffstat (limited to 'packages/0x.js/src/contract_wrappers/generated/base_contract.ts')
-rw-r--r-- | packages/0x.js/src/contract_wrappers/generated/base_contract.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/packages/0x.js/src/contract_wrappers/generated/base_contract.ts b/packages/0x.js/src/contract_wrappers/generated/base_contract.ts new file mode 100644 index 000000000..e5f536448 --- /dev/null +++ b/packages/0x.js/src/contract_wrappers/generated/base_contract.ts @@ -0,0 +1,36 @@ +import * as _ from 'lodash'; +import * as Web3 from 'web3'; + +import {TxData, TxDataPayable} from '../../types'; + +// TODO: Gas Margin +// TODO: Abi check +export class BaseContract { + 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 speadable. + // 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.web3ContractInstance = web3ContractInstance; + this.defaults = defaults; + } +} |