aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-07-07 05:51:44 +0800
committerGitHub <noreply@github.com>2017-07-07 05:51:44 +0800
commit18050b7ea3eae19626a7976c004b237287ff5363 (patch)
treebde30c03faf91a4385cfa1393a143c2281ee97b1 /src
parentf2611d5b2be4c4c1b8bcfc9c964a13faf2329316 (diff)
parent9f89dbc8e4f3159e5fb80ea8d977911c404dd3bc (diff)
downloaddexon-sol-tools-18050b7ea3eae19626a7976c004b237287ff5363.tar
dexon-sol-tools-18050b7ea3eae19626a7976c004b237287ff5363.tar.gz
dexon-sol-tools-18050b7ea3eae19626a7976c004b237287ff5363.tar.bz2
dexon-sol-tools-18050b7ea3eae19626a7976c004b237287ff5363.tar.lz
dexon-sol-tools-18050b7ea3eae19626a7976c004b237287ff5363.tar.xz
dexon-sol-tools-18050b7ea3eae19626a7976c004b237287ff5363.tar.zst
dexon-sol-tools-18050b7ea3eae19626a7976c004b237287ff5363.zip
Merge pull request #94 from 0xProject/moveExchangeAddressGetters
Moves exchange contract address getters to zeroEx top level
Diffstat (limited to 'src')
-rw-r--r--src/0x.ts45
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts47
-rw-r--r--src/utils/assert.ts4
3 files changed, 46 insertions, 50 deletions
diff --git a/src/0x.ts b/src/0x.ts
index 49bd31f2d..95935c258 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -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,12 +159,12 @@ 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);
}
/**
- * Sets a new provider for the web3 instance used by 0x.js. Updating the provider will stop all
+ * Sets a new web3 provider for 0x.js. Updating the provider will stop all
* subscriptions so you will need to re-subscribe to all events relevant to your app after this call.
* @param provider The Web3Provider you would like the 0x.js library to use from now on.
*/
@@ -176,7 +177,7 @@ export class ZeroEx {
(this.etherToken as any)._invalidateContractInstance();
}
/**
- * Get user Ethereum addresses available through the supplied web3 instance available for sending transactions.
+ * Get user Ethereum addresses available through the supplied web3 provider available for sending transactions.
* @return An array of available user Ethereum addresses.
*/
public async getAvailableAddressesAsync(): Promise<string[]> {
@@ -254,4 +255,42 @@ export class ZeroEx {
}
return ecSignature;
}
+ /**
+ * Returns the ethereum addresses of all available exchange contracts
+ * supported by this library on the network that the supplied web3
+ * provider 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
+ * supported by this library on the network that the supplied web3
+ * provider is connected to that are currently authorized by 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.proxy.isAuthorizedAsync(exchangeContractAddress);
+ if (isAuthorized) {
+ proxyAuthorizedExchangeContractAddresses.push(exchangeContractAddress);
+ }
+ }
+ return proxyAuthorizedExchangeContractAddresses;
+ }
}
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index 5a2da4a98..2353c826a 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -37,7 +37,6 @@ import {utils} from '../utils/utils';
import {eventUtils} from '../utils/event_utils';
import {ContractWrapper} from './contract_wrapper';
import {ProxyWrapper} from './proxy_wrapper';
-import {ExchangeArtifactsByName} from '../exchange_artifacts_by_name';
import {ecSignatureSchema} from '../schemas/ec_signature_schema';
import {signedOrdersSchema} from '../schemas/signed_orders_schema';
import {subscriptionOptsSchema} from '../schemas/subscription_opts_schema';
@@ -50,6 +49,7 @@ import {signedOrderSchema, orderSchema} from '../schemas/order_schemas';
import {constants} from '../utils/constants';
import {TokenWrapper} from './token_wrapper';
import {decorators} from '../utils/decorators';
+import {ExchangeArtifactsByName} from '../exchange_artifacts_by_name';
/**
* This class includes all the functionality related to calling methods and subscribing to
@@ -67,7 +67,6 @@ export class ExchangeWrapper extends ContractWrapper {
private _exchangeContractByAddress: ExchangeContractByAddress;
private _exchangeLogEventEmitters: ContractEventEmitter[];
private _tokenWrapper: TokenWrapper;
- private _proxyWrapper: ProxyWrapper;
private static _getOrderAddressesAndValues(order: Order): [OrderAddresses, OrderValues] {
const orderAddresses: OrderAddresses = [
order.maker,
@@ -86,10 +85,9 @@ export class ExchangeWrapper extends ContractWrapper {
];
return [orderAddresses, orderValues];
}
- constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper, proxyWrapper: ProxyWrapper) {
+ constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper) {
super(web3Wrapper);
this._tokenWrapper = tokenWrapper;
- this._proxyWrapper = proxyWrapper;
this._exchangeLogEventEmitters = [];
this._exchangeContractByAddress = {};
}
@@ -610,43 +608,6 @@ export class ExchangeWrapper extends ContractWrapper {
return eventEmitter;
}
/**
- * 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 getAvailableContractAddressesAsync(): 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 getProxyAuthorizedContractAddressesAsync(): Promise<string[]> {
- const exchangeContractAddresses = await this.getAvailableContractAddressesAsync();
- const proxyAuthorizedExchangeContractAddresses = [];
- for (const exchangeContractAddress of exchangeContractAddresses) {
- const isAuthorized = await this._isExchangeContractAddressProxyAuthorizedAsync(exchangeContractAddress);
- if (isAuthorized) {
- proxyAuthorizedExchangeContractAddresses.push(exchangeContractAddress);
- }
- }
- return proxyAuthorizedExchangeContractAddresses;
- }
- /**
* Stops watching for all exchange events
*/
public async stopWatchingAllEventsAsync(): Promise<void> {
@@ -659,10 +620,6 @@ export class ExchangeWrapper extends ContractWrapper {
await this.stopWatchingAllEventsAsync();
this._exchangeContractByAddress = {};
}
- private async _isExchangeContractAddressProxyAuthorizedAsync(exchangeContractAddress: string): Promise<boolean> {
- const isAuthorized = await this._proxyWrapper.isAuthorizedAsync(exchangeContractAddress);
- return isAuthorized;
- }
private async _isValidSignatureUsingContractCallAsync(dataHex: string, ecSignature: ECSignature,
signerAddressHex: string,
exchangeContractAddress: string): Promise<boolean> {
diff --git a/src/utils/assert.ts b/src/utils/assert.ts
index b3c30c11d..00415602d 100644
--- a/src/utils/assert.ts
+++ b/src/utils/assert.ts
@@ -43,12 +43,12 @@ export const assert = {
assert.isETHAddressHex(variableName, senderAddressHex);
const isSenderAddressAvailable = await web3Wrapper.isSenderAddressAvailableAsync(senderAddressHex);
assert.assert(isSenderAddressAvailable,
- `Specified ${variableName} ${senderAddressHex} isn't available through the supplied web3 instance`,
+ `Specified ${variableName} ${senderAddressHex} isn't available through the supplied web3 provider`,
);
},
async isUserAddressAvailableAsync(web3Wrapper: Web3Wrapper): Promise<void> {
const availableAddresses = await web3Wrapper.getAvailableAddressesAsync();
- this.assert(!_.isEmpty(availableAddresses), 'No addresses were available on the provided web3 instance');
+ this.assert(!_.isEmpty(availableAddresses), 'No addresses were available on the provided web3 provider');
},
hasAtMostOneUniqueValue(value: any[], errMsg: string): void {
this.assert(_.uniq(value).length <= 1, errMsg);