diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-09-05 00:14:48 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-09-05 00:14:48 +0800 |
commit | 1ad395cf86b2006c09bdae814607c2baf9790b91 (patch) | |
tree | d05ed1febd8979b7967a42faaed45c3dd10356dd /src/contract_wrappers/contract_wrapper.ts | |
parent | 1c2d4cbb1af9a5d4442857def622dc8068086953 (diff) | |
download | dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.tar dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.tar.gz dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.tar.bz2 dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.tar.lz dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.tar.xz dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.tar.zst dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.zip |
Make the functions immidiately return txHash instead of awaiting for a transaction to be mined
Diffstat (limited to 'src/contract_wrappers/contract_wrapper.ts')
-rw-r--r-- | src/contract_wrappers/contract_wrapper.ts | 47 |
1 files changed, 7 insertions, 40 deletions
diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index 28df82cee..3de26148f 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -1,7 +1,7 @@ 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 { @@ -11,43 +11,10 @@ export class ContractWrapper { 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; } } |