diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-07-04 03:28:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-04 03:28:34 +0800 |
commit | d4cef89587ef8ea0f7fbab1146c4524e8f588eac (patch) | |
tree | 93dcf602b5a738bad03c121384707fcf19518310 /src/0x.ts | |
parent | d506a1f98562dd11ecff5e936a93fce6d14e48a9 (diff) | |
parent | 8204409c6d6bf773aa8ebb38006a3975ed43a684 (diff) | |
download | dexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.tar dexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.tar.gz dexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.tar.bz2 dexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.tar.lz dexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.tar.xz dexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.tar.zst dexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.zip |
Merge pull request #82 from 0xProject/add-exchange-address-to-order-struct
Allow multiple Exchange contracts and multiple artifacts
Diffstat (limited to 'src/0x.ts')
-rw-r--r-- | src/0x.ts | 26 |
1 files changed, 8 insertions, 18 deletions
@@ -15,8 +15,8 @@ import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper'; import {EtherTokenWrapper} from './contract_wrappers/ether_token_wrapper'; import {ecSignatureSchema} from './schemas/ec_signature_schema'; import {TokenWrapper} from './contract_wrappers/token_wrapper'; +import {ProxyWrapper} from './contract_wrappers/proxy_wrapper'; import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider} from './types'; -import * as ExchangeArtifacts from './artifacts/Exchange.json'; import {orderSchema} from './schemas/order_schemas'; // Customize our BigNumber instances @@ -52,6 +52,7 @@ export class ZeroEx { * wrapped ETH ERC20 token smart contract. */ public etherToken: EtherTokenWrapper; + private _proxyWrapper: ProxyWrapper; private _web3Wrapper: Web3Wrapper; /** * Verifies that the elliptic curve signature `signature` was generated @@ -149,7 +150,8 @@ export class ZeroEx { constructor(provider: Web3Provider) { this._web3Wrapper = new Web3Wrapper(provider); this.token = new TokenWrapper(this._web3Wrapper); - this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token); + this._proxyWrapper = new ProxyWrapper(this._web3Wrapper); + this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token, this._proxyWrapper); this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper); this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token); } @@ -160,9 +162,10 @@ export class ZeroEx { */ public async setProviderAsync(provider: Web3Provider) { this._web3Wrapper.setProvider(provider); - await this.exchange.invalidateContractInstanceAsync(); + await this.exchange.invalidateContractInstancesAsync(); this.tokenRegistry.invalidateContractInstance(); this.token.invalidateContractInstances(); + this._proxyWrapper.invalidateContractInstance(); } /** * Get user Ethereum addresses available through the supplied web3 instance available for sending transactions. @@ -177,11 +180,9 @@ export class ZeroEx { * @param order An object that conforms to the Order or SignedOrder interface definitions. * @return The resulting orderHash from hashing the supplied order. */ - public async getOrderHashHexAsync(order: Order|SignedOrder): Promise<string> { + public getOrderHashHex(order: Order|SignedOrder): string { assert.doesConformToSchema('order', order, orderSchema); - - const exchangeContractAddr = await this._getExchangeAddressAsync(); - const orderHashHex = utils.getOrderHashHex(order, exchangeContractAddr); + const orderHashHex = utils.getOrderHashHex(order); return orderHashHex; } /** @@ -245,15 +246,4 @@ export class ZeroEx { } return ecSignature; } - private async _getExchangeAddressAsync() { - const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); - const exchangeNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ? - undefined : - (ExchangeArtifacts as any).networks[networkIdIfExists]; - if (_.isUndefined(exchangeNetworkConfigsIfExists)) { - throw new Error(ZeroExError.CONTRACT_NOT_DEPLOYED_ON_NETWORK); - } - const exchangeAddress = exchangeNetworkConfigsIfExists.address; - return exchangeAddress; - } } |