diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-23 01:53:04 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-24 05:13:36 +0800 |
commit | 4fe28ec53c4e84544c3c21853dff57c4c6a4e45d (patch) | |
tree | 4b44732136d006aa550bef0f8c4c60a980e18771 /packages/0x.js/src | |
parent | efe8e07854ac5527725350e871dab370d022ae01 (diff) | |
download | dexon-sol-tools-4fe28ec53c4e84544c3c21853dff57c4c6a4e45d.tar dexon-sol-tools-4fe28ec53c4e84544c3c21853dff57c4c6a4e45d.tar.gz dexon-sol-tools-4fe28ec53c4e84544c3c21853dff57c4c6a4e45d.tar.bz2 dexon-sol-tools-4fe28ec53c4e84544c3c21853dff57c4c6a4e45d.tar.lz dexon-sol-tools-4fe28ec53c4e84544c3c21853dff57c4c6a4e45d.tar.xz dexon-sol-tools-4fe28ec53c4e84544c3c21853dff57c4c6a4e45d.tar.zst dexon-sol-tools-4fe28ec53c4e84544c3c21853dff57c4c6a4e45d.zip |
Make zeroEx.exchange.getContractAddress non-async
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r-- | packages/0x.js/src/contract_wrappers/exchange_wrapper.ts | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index 96b642a90..9ab03454c 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -664,7 +664,7 @@ export class ExchangeWrapper extends ContractWrapper { assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.isFunction('callback', callback); - const exchangeContractAddress = await this.getContractAddressAsync(); + const exchangeContractAddress = this.getContractAddress(); const subscriptionToken = this._subscribe<ArgsType>( exchangeContractAddress, eventName, indexFilterValues, artifacts.ExchangeArtifact.abi, callback, ); @@ -691,7 +691,7 @@ export class ExchangeWrapper extends ContractWrapper { assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents); assert.doesConformToSchema('subscriptionOpts', subscriptionOpts, schemas.subscriptionOptsSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); - const exchangeContractAddress = await this.getContractAddressAsync(); + const exchangeContractAddress = this.getContractAddress(); const logs = await this._getLogsAsync<ArgsType>( exchangeContractAddress, eventName, subscriptionOpts, indexFilterValues, artifacts.ExchangeArtifact.abi, ); @@ -702,10 +702,17 @@ export class ExchangeWrapper extends ContractWrapper { * that the user-passed web3 provider is connected to. * @returns The Ethereum address of the Exchange contract being used. */ - public async getContractAddressAsync(): Promise<string> { - const exchangeInstance = await this._getExchangeContractAsync(); - const exchangeAddress = exchangeInstance.address; - return exchangeAddress; + public getContractAddress(): string { + const networkId = this._web3Wrapper.getNetworkId(); + if (_.isUndefined(this._contractAddressIfExists)) { + const contractAddress = artifacts.ExchangeArtifact.networks[networkId].address; + if (_.isUndefined(contractAddress)) { + throw new Error(ZeroExError.ExchangeContractDoesNotExist); + } + return contractAddress; + } else { + return this._contractAddressIfExists; + } } /** * Checks if order is still fillable and throws an error otherwise. Useful for orderbook |