From 8fe844bcc9e4298cc3ced58c1abcee78de4193b3 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 27 Feb 2018 12:01:12 -0800 Subject: Move BaseContract to web3Wrapper --- .../src/contract_wrappers/generated/.gitignore | 9 +-- .../contract_wrappers/generated/base_contract.ts | 70 ---------------------- 2 files changed, 1 insertion(+), 78 deletions(-) delete mode 100644 packages/contracts/src/contract_wrappers/generated/base_contract.ts (limited to 'packages/contracts/src') diff --git a/packages/contracts/src/contract_wrappers/generated/.gitignore b/packages/contracts/src/contract_wrappers/generated/.gitignore index b976a8737..72e8ffc0d 100644 --- a/packages/contracts/src/contract_wrappers/generated/.gitignore +++ b/packages/contracts/src/contract_wrappers/generated/.gitignore @@ -1,8 +1 @@ -dummy_token.ts -exchange.ts -multi_sig_wallet_with_time_lock_except_remove_authorized_address.ts -multi_sig_wallet_with_time_lock.ts -multi_sig_wallet.ts -token_registry.ts -token_transfer_proxy.ts -zrx_token.ts +* diff --git a/packages/contracts/src/contract_wrappers/generated/base_contract.ts b/packages/contracts/src/contract_wrappers/generated/base_contract.ts deleted file mode 100644 index a465ddc38..000000000 --- a/packages/contracts/src/contract_wrappers/generated/base_contract.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { TxData, TxDataPayable } from '@0xproject/types'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import * as ethersContracts from 'ethers-contracts'; -import * as _ from 'lodash'; -import * as Web3 from 'web3'; - -export class BaseContract { - protected _ethersInterface: ethersContracts.Interface; - protected _web3Wrapper: Web3Wrapper; - public abi: Web3.ContractAbi; - public address: string; - protected static _transformABIData( - abis: Web3.DataItem[], - values: any[], - transformation: (type: string, value: any) => any, - ): any { - return _.map(values, (value: any, i: number) => - BaseContract._transformTypedData(abis[i].type, value, transformation), - ); - } - protected static _lowercaseAddress(type: string, value: string): string { - return type === 'address' ? value.toLowerCase() : value; - } - protected static _bigNumberToString(type: string, value: string): string { - return _.isObject(value) && (value as any).isBigNumber ? value.toString() : value; - } - private static _transformTypedData( - type: string, - values: any, - transformation: (type: string, value: any) => any, - ): any { - const trailingArrayRegex = /\[\d*\]$/; - if (type.match(trailingArrayRegex)) { - const arrayItemType = type.replace(trailingArrayRegex, ''); - return _.map(values, (value: any, i: number) => - this._transformTypedData(arrayItemType, value, transformation), - ); - } else { - return transformation(type, values); - } - } - protected async _applyDefaultsToTxDataAsync>( - txData: T, - estimateGasAsync?: (txData: T) => Promise, - ): Promise { - // 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()), - ...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(web3Wrapper: Web3Wrapper, abi: Web3.ContractAbi, address: string) { - this._web3Wrapper = web3Wrapper; - this.abi = abi; - this.address = address; - this._ethersInterface = new ethersContracts.Interface(abi); - } -} -- cgit v1.2.3