diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-09-06 16:35:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-06 16:35:19 +0800 |
commit | 35c133caeda613121d7d90f3f1347ebdc8087d66 (patch) | |
tree | 6156865472010078a9f27b905bcaec7782f6521c /src/contract_wrappers/contract_wrapper.ts | |
parent | 18a52a1ea758ee5640680f1097eba1ce9a9e81fc (diff) | |
parent | f0a5ad2d2063fe8ba4682147ec2f73e2763b0275 (diff) | |
download | dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.tar dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.tar.gz dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.tar.bz2 dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.tar.lz dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.tar.xz dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.tar.zst dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.zip |
Merge branch 'development' into fix/signature-verification
Diffstat (limited to 'src/contract_wrappers/contract_wrapper.ts')
-rw-r--r-- | src/contract_wrappers/contract_wrapper.ts | 51 |
1 files changed, 8 insertions, 43 deletions
diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index 28df82cee..ca19342f3 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -1,53 +1,18 @@ import * as _ from 'lodash'; -import contract = require('truffle-contract'); +import * as Web3 from 'web3'; import {Web3Wrapper} from '../web3_wrapper'; -import {ZeroExError, Artifact, ContractInstance} from '../types'; +import {ZeroExError} from '../types'; import {utils} from '../utils/utils'; export class ContractWrapper { protected _web3Wrapper: Web3Wrapper; - private _gasPrice?: BigNumber.BigNumber; - constructor(web3Wrapper: Web3Wrapper, gasPrice?: BigNumber.BigNumber) { + constructor(web3Wrapper: Web3Wrapper) { this._web3Wrapper = web3Wrapper; - this._gasPrice = gasPrice; } - protected async _instantiateContractIfExistsAsync(artifact: Artifact, address?: string): Promise<ContractInstance> { - const c = await contract(artifact); - c.defaults({ - gasPrice: this._gasPrice, - }); - const providerObj = this._web3Wrapper.getCurrentProvider(); - c.setProvider(providerObj); - - const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); - const artifactNetworkConfigs = _.isUndefined(networkIdIfExists) ? - undefined : - artifact.networks[networkIdIfExists]; - let contractAddress; - if (!_.isUndefined(address)) { - contractAddress = address; - } else if (!_.isUndefined(artifactNetworkConfigs)) { - contractAddress = artifactNetworkConfigs.address.toLowerCase(); - } - - if (!_.isUndefined(contractAddress)) { - const doesContractExist = await this._web3Wrapper.doesContractExistAtAddressAsync(contractAddress); - if (!doesContractExist) { - throw new Error(ZeroExError.ContractDoesNotExist); - } - } - - try { - const contractInstance = _.isUndefined(address) ? await c.deployed() : await c.at(address); - return contractInstance; - } catch (err) { - const errMsg = `${err}`; - if (_.includes(errMsg, 'not been deployed to detected network')) { - throw new Error(ZeroExError.ContractDoesNotExist); - } else { - utils.consoleLog(`Notice: Error encountered: ${err} ${err.stack}`); - throw new Error(ZeroExError.UnhandledError); - } - } + protected async _instantiateContractIfExistsAsync<A extends Web3.ContractInstance>(artifact: Artifact, + address?: string): Promise<A> { + const contractInstance = + await this._web3Wrapper.getContractInstanceFromArtifactAsync<A>(artifact, address); + return contractInstance; } } |