diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-07-06 05:16:34 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-07-06 05:18:46 +0800 |
commit | 9a9fd7d926a9f27fdd4da55f558ca46efdcc6912 (patch) | |
tree | 8dda13b115f944146c9c8b34285d4d22a5749c5c /src/0x.ts | |
parent | f2611d5b2be4c4c1b8bcfc9c964a13faf2329316 (diff) | |
download | dexon-sol-tools-9a9fd7d926a9f27fdd4da55f558ca46efdcc6912.tar dexon-sol-tools-9a9fd7d926a9f27fdd4da55f558ca46efdcc6912.tar.gz dexon-sol-tools-9a9fd7d926a9f27fdd4da55f558ca46efdcc6912.tar.bz2 dexon-sol-tools-9a9fd7d926a9f27fdd4da55f558ca46efdcc6912.tar.lz dexon-sol-tools-9a9fd7d926a9f27fdd4da55f558ca46efdcc6912.tar.xz dexon-sol-tools-9a9fd7d926a9f27fdd4da55f558ca46efdcc6912.tar.zst dexon-sol-tools-9a9fd7d926a9f27fdd4da55f558ca46efdcc6912.zip |
Move zeroEx.exchange.getAvailableContractAddressesAsync to zeroEx.getAvailableExchangeContractAddressesAsync and zeroEx.exchange.getProxyAuthorizedContractAddressesAsync to zeroEx.getProxyAuthorizedExchangeContractAddressesAsync
Diffstat (limited to 'src/0x.ts')
-rw-r--r-- | src/0x.ts | 44 |
1 files changed, 43 insertions, 1 deletions
@@ -20,6 +20,7 @@ import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider} from './type import {orderHashSchema} from './schemas/order_hash_schema'; import {orderSchema} from './schemas/order_schemas'; import {SchemaValidator} from './utils/schema_validator'; +import {ExchangeArtifactsByName} from './exchange_artifacts_by_name'; // Customize our BigNumber instances bigNumberConfigs.configure(); @@ -158,7 +159,7 @@ export class ZeroEx { this._web3Wrapper = new Web3Wrapper(provider); this.token = new TokenWrapper(this._web3Wrapper); this.proxy = new ProxyWrapper(this._web3Wrapper); - this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token, this.proxy); + this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token); this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper); this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token); } @@ -254,4 +255,45 @@ export class ZeroEx { } return ecSignature; } + /** + * Returns the ethereum addresses of all available exchange contracts + * on the network that the provided web3 instance is connected to + * @return The ethereum addresses of all available exchange contracts. + */ + public async getAvailableExchangeContractAddressesAsync(): Promise<string[]> { + const networkId = await this._web3Wrapper.getNetworkIdIfExistsAsync(); + if (_.isUndefined(networkId)) { + return []; + } else { + const exchangeArtifacts = _.values(ExchangeArtifactsByName); + const networkSpecificExchangeArtifacts = _.compact(_.map( + exchangeArtifacts, exchangeArtifact => exchangeArtifact.networks[networkId])); + const exchangeAddresses = _.map( + networkSpecificExchangeArtifacts, + networkSpecificExchangeArtifact => networkSpecificExchangeArtifact.address, + ); + return exchangeAddresses; + } + } + /** + * Returns the ethereum addresses of all available exchange contracts + * on the network that the provided web3 instance is connected to + * that are currently authorized on the Proxy contract + * @return The ethereum addresses of all available and authorized exchange contract. + */ + public async getProxyAuthorizedExchangeContractAddressesAsync(): Promise<string[]> { + const exchangeContractAddresses = await this.getAvailableExchangeContractAddressesAsync(); + const proxyAuthorizedExchangeContractAddresses = []; + for (const exchangeContractAddress of exchangeContractAddresses) { + const isAuthorized = await this._isExchangeContractAddressProxyAuthorizedAsync(exchangeContractAddress); + if (isAuthorized) { + proxyAuthorizedExchangeContractAddresses.push(exchangeContractAddress); + } + } + return proxyAuthorizedExchangeContractAddresses; + } + private async _isExchangeContractAddressProxyAuthorizedAsync(exchangeContractAddress: string): Promise<boolean> { + const isAuthorized = await this.proxy.isAuthorizedAsync(exchangeContractAddress); + return isAuthorized; + } } |