diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-28 07:15:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-28 07:15:18 +0800 |
commit | 54ef916b93ba0939dcb8824149c9a9fb74df4f2e (patch) | |
tree | 6559179e99d077ae8d78350580a082e75d50a7c8 /packages/0x.js/src/contract_wrappers/contract_wrapper.ts | |
parent | 4a770dee84ee49e8038da7dd32ce26338176bf36 (diff) | |
parent | f862a2af6d9802c2c75f813025517e0c52cd513c (diff) | |
download | dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.tar dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.tar.gz dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.tar.bz2 dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.tar.lz dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.tar.xz dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.tar.zst dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.zip |
Merge pull request #233 from 0xProject/feature/passNetworkId
Forces the users of 0x.js to pass the network id
Diffstat (limited to 'packages/0x.js/src/contract_wrappers/contract_wrapper.ts')
-rw-r--r-- | packages/0x.js/src/contract_wrappers/contract_wrapper.ts | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index c1c95c6db..8c92931b4 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -1,24 +1,25 @@ +import {Block, BlockAndLogStreamer} from 'ethereumjs-blockstream'; import * as _ from 'lodash'; import * as Web3 from 'web3'; -import {BlockAndLogStreamer, Block} from 'ethereumjs-blockstream'; -import {Web3Wrapper} from '../web3_wrapper'; -import {AbiDecoder} from '../utils/abi_decoder'; + import { - ZeroExError, - InternalZeroExError, Artifact, + BlockParamLiteral, + ContractEventArgs, + ContractEvents, + EventCallback, + IndexedFilterValues, + InternalZeroExError, LogWithDecodedArgs, RawLog, - ContractEvents, SubscriptionOpts, - IndexedFilterValues, - EventCallback, - BlockParamLiteral, - ContractEventArgs, + ZeroExError, } from '../types'; +import {AbiDecoder} from '../utils/abi_decoder'; import {constants} from '../utils/constants'; -import {intervalUtils} from '../utils/interval_utils'; import {filterUtils} from '../utils/filter_utils'; +import {intervalUtils} from '../utils/interval_utils'; +import {Web3Wrapper} from '../web3_wrapper'; export class ContractWrapper { protected _web3Wrapper: Web3Wrapper; @@ -95,6 +96,18 @@ export class ContractWrapper { await this._web3Wrapper.getContractInstanceFromArtifactAsync<ContractType>(artifact, addressIfExists); return contractInstance; } + protected _getContractAddress(artifact: Artifact, addressIfExists?: string): string { + if (_.isUndefined(addressIfExists)) { + const networkId = this._web3Wrapper.getNetworkId(); + const contractAddress = artifact.networks[networkId].address; + if (_.isUndefined(contractAddress)) { + throw new Error(ZeroExError.ExchangeContractDoesNotExist); + } + return contractAddress; + } else { + return addressIfExists; + } + } private _onLogStateChanged<ArgsType extends ContractEventArgs>(isRemoved: boolean, log: Web3.LogEntry): void { _.forEach(this._filters, (filter: Web3.FilterObject, filterToken: string) => { if (filterUtils.matchesFilter(log, filter)) { @@ -140,7 +153,7 @@ export class ContractWrapper { // We need to coerce to Block type cause Web3.Block includes types for mempool blocks if (!_.isUndefined(this._blockAndLogStreamer)) { // If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined - this._blockAndLogStreamer.reconcileNewBlock(latestBlock as any as Block); + await this._blockAndLogStreamer.reconcileNewBlock(latestBlock as any as Block); } } catch (err) { const filterTokens = _.keys(this._filterCallbacks); |