aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/0x.js/src/contract_wrappers/contract_wrapper.ts')
-rw-r--r--packages/0x.js/src/contract_wrappers/contract_wrapper.ts37
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);