Make zeroEx.tokenRegistry.getContractAddress non-async

This commit is contained in:
Leonid Logvinov
2017-11-22 13:15:48 -06:00
parent 8935146240
commit c72745b0b2

View File

@@ -1,7 +1,7 @@
import * as _ from 'lodash'; import * as _ from 'lodash';
import {Web3Wrapper} from '../web3_wrapper'; import {Web3Wrapper} from '../web3_wrapper';
import {assert} from '../utils/assert'; import {assert} from '../utils/assert';
import {Token, TokenRegistryContract, TokenMetadata} from '../types'; import {Token, TokenRegistryContract, TokenMetadata, ZeroExError} from '../types';
import {constants} from '../utils/constants'; import {constants} from '../utils/constants';
import {ContractWrapper} from './contract_wrapper'; import {ContractWrapper} from './contract_wrapper';
import {artifacts} from '../artifacts'; import {artifacts} from '../artifacts';
@@ -89,10 +89,17 @@ export class TokenRegistryWrapper extends ContractWrapper {
* that the user-passed web3 provider is connected to. * that the user-passed web3 provider is connected to.
* @returns The Ethereum address of the TokenRegistry contract being used. * @returns The Ethereum address of the TokenRegistry contract being used.
*/ */
public async getContractAddressAsync(): Promise<string> { public getContractAddress(): string {
const tokenRegistryInstance = await this._getTokenRegistryContractAsync(); const networkId = this._web3Wrapper.getNetworkId();
const tokenRegistryAddress = tokenRegistryInstance.address; if (_.isUndefined(this._contractAddressIfExists)) {
return tokenRegistryAddress; const contractAddress = artifacts.TokenRegistryArtifact.networks[networkId].address;
if (_.isUndefined(contractAddress)) {
throw new Error(ZeroExError.ExchangeContractDoesNotExist);
}
return contractAddress;
} else {
return this._contractAddressIfExists;
}
} }
private _createTokenFromMetadata(metadata: TokenMetadata): Token|undefined { private _createTokenFromMetadata(metadata: TokenMetadata): Token|undefined {
if (metadata[0] === constants.NULL_ADDRESS) { if (metadata[0] === constants.NULL_ADDRESS) {