diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-12-08 17:51:46 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-12-08 17:51:46 +0800 |
commit | b362e2c28e9cafa7335bced17ec61fba93b018e6 (patch) | |
tree | 6a6c65f2a3a17ff93b566fa0c0e7d92032d1a7a0 /packages/0x.js/src | |
parent | 5401c69163f8fd384038a3ef8c760ec95c661035 (diff) | |
download | dexon-0x-contracts-b362e2c28e9cafa7335bced17ec61fba93b018e6.tar.gz dexon-0x-contracts-b362e2c28e9cafa7335bced17ec61fba93b018e6.tar.zst dexon-0x-contracts-b362e2c28e9cafa7335bced17ec61fba93b018e6.zip |
Refactor networkId out of web3Wrapper
Diffstat (limited to 'packages/0x.js/src')
7 files changed, 27 insertions, 19 deletions
diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 1cbfaed0c..935e4ac1a 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -179,24 +179,31 @@ export class ZeroEx { const defaults = { gasPrice: config.gasPrice, }; - this._web3Wrapper = new Web3Wrapper(provider, config.networkId, defaults); + this._web3Wrapper = new Web3Wrapper(provider, defaults); this.proxy = new TokenTransferProxyWrapper( this._web3Wrapper, + config.networkId, config.tokenTransferProxyContractAddress, ); this.token = new TokenWrapper( this._web3Wrapper, + config.networkId, this._abiDecoder, this.proxy, ); this.exchange = new ExchangeWrapper( this._web3Wrapper, + config.networkId, this._abiDecoder, this.token, config.exchangeContractAddress, ); - this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper, config.tokenRegistryContractAddress); - this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token, config.etherTokenContractAddress); + this.tokenRegistry = new TokenRegistryWrapper( + this._web3Wrapper, config.networkId, config.tokenRegistryContractAddress, + ); + this.etherToken = new EtherTokenWrapper( + this._web3Wrapper, config.networkId, this.token, config.etherTokenContractAddress, + ); this.orderStateWatcher = new OrderStateWatcher( this._web3Wrapper, this._abiDecoder, this.token, this.exchange, config.orderWatcherConfig, ); diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index 0b6fc031a..d56b8632d 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -32,6 +32,7 @@ const CONTRACT_NAME_TO_NOT_FOUND_ERROR: {[contractName: string]: ZeroExError} = export class ContractWrapper { protected _web3Wrapper: Web3Wrapper; + private _networkId: number; private _abiDecoder?: AbiDecoder; private _blockAndLogStreamer: BlockAndLogStreamer|undefined; private _blockAndLogStreamInterval: NodeJS.Timer; @@ -39,8 +40,9 @@ export class ContractWrapper { private _filterCallbacks: {[filterToken: string]: EventCallback<ContractEventArgs>}; private _onLogAddedSubscriptionToken: string|undefined; private _onLogRemovedSubscriptionToken: string|undefined; - constructor(web3Wrapper: Web3Wrapper, abiDecoder?: AbiDecoder) { + constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder?: AbiDecoder) { this._web3Wrapper = web3Wrapper; + this._networkId = networkId; this._abiDecoder = abiDecoder; this._filters = {}; this._filterCallbacks = {}; @@ -104,11 +106,10 @@ export class ContractWrapper { ): Promise<Web3.ContractInstance> { let contractAddress: string; if (_.isUndefined(addressIfExists)) { - const networkId = this._web3Wrapper.getNetworkId(); - if (_.isUndefined(artifact.networks[networkId])) { + if (_.isUndefined(artifact.networks[this._networkId])) { throw new Error(ZeroExError.ContractNotDeployedOnNetwork); } - contractAddress = artifact.networks[networkId].address.toLowerCase(); + contractAddress = artifact.networks[this._networkId].address.toLowerCase(); } else { contractAddress = addressIfExists; } @@ -123,8 +124,7 @@ export class ContractWrapper { } protected _getContractAddress(artifact: Artifact, addressIfExists?: string): string { if (_.isUndefined(addressIfExists)) { - const networkId = this._web3Wrapper.getNetworkId(); - const contractAddress = artifact.networks[networkId].address; + const contractAddress = artifact.networks[this._networkId].address; if (_.isUndefined(contractAddress)) { throw new Error(ZeroExError.ExchangeContractDoesNotExist); } diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts index 685ae9a9e..896cfde3d 100644 --- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts @@ -18,8 +18,9 @@ export class EtherTokenWrapper extends ContractWrapper { private _etherTokenContractIfExists?: EtherTokenContract; private _tokenWrapper: TokenWrapper; private _contractAddressIfExists?: string; - constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper, contractAddressIfExists?: string) { - super(web3Wrapper); + constructor(web3Wrapper: Web3Wrapper, networkId: number, tokenWrapper: TokenWrapper, + contractAddressIfExists?: string) { + super(web3Wrapper, networkId); this._tokenWrapper = tokenWrapper; this._contractAddressIfExists = contractAddressIfExists; } diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index 433d99e4c..1e9865395 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -84,9 +84,9 @@ export class ExchangeWrapper extends ContractWrapper { ]; return [orderAddresses, orderValues]; } - constructor(web3Wrapper: Web3Wrapper, abiDecoder: AbiDecoder, + constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder: AbiDecoder, tokenWrapper: TokenWrapper, contractAddressIfExists?: string) { - super(web3Wrapper, abiDecoder); + super(web3Wrapper, networkId, abiDecoder); this._tokenWrapper = tokenWrapper; this._orderValidationUtils = new OrderValidationUtils(tokenWrapper, this); this._contractAddressIfExists = contractAddressIfExists; diff --git a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts index 80b4c0f85..064b826d8 100644 --- a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts @@ -27,8 +27,8 @@ export class TokenRegistryWrapper extends ContractWrapper { }; return token; } - constructor(web3Wrapper: Web3Wrapper, contractAddressIfExists?: string) { - super(web3Wrapper); + constructor(web3Wrapper: Web3Wrapper, networkId: number, contractAddressIfExists?: string) { + super(web3Wrapper, networkId); this._contractAddressIfExists = contractAddressIfExists; } /** diff --git a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts index 7d6943aea..1a16e3540 100644 --- a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts @@ -13,8 +13,8 @@ import {TokenTransferProxyContract} from './generated/token_transfer_proxy'; export class TokenTransferProxyWrapper extends ContractWrapper { private _tokenTransferProxyContractIfExists?: TokenTransferProxyContract; private _contractAddressIfExists?: string; - constructor(web3Wrapper: Web3Wrapper, contractAddressIfExists?: string) { - super(web3Wrapper); + constructor(web3Wrapper: Web3Wrapper, networkId: number, contractAddressIfExists?: string) { + super(web3Wrapper, networkId); this._contractAddressIfExists = contractAddressIfExists; } /** diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts index 1ae26edaa..684f291a5 100644 --- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts @@ -34,9 +34,9 @@ export class TokenWrapper extends ContractWrapper { public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; private _tokenContractsByAddress: {[address: string]: TokenContract}; private _tokenTransferProxyWrapper: TokenTransferProxyWrapper; - constructor(web3Wrapper: Web3Wrapper, abiDecoder: AbiDecoder, + constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder: AbiDecoder, tokenTransferProxyWrapper: TokenTransferProxyWrapper) { - super(web3Wrapper, abiDecoder); + super(web3Wrapper, networkId, abiDecoder); this._tokenContractsByAddress = {}; this._tokenTransferProxyWrapper = tokenTransferProxyWrapper; } |