Add zeroEx.tokenRegistry.getTokenAddressesAsync()

This commit is contained in:
Leonid Logvinov
2017-08-23 20:09:09 +02:00
parent e216f2ff6d
commit 82ef8b19f0

View File

@@ -21,7 +21,7 @@ export class TokenRegistryWrapper extends ContractWrapper {
public async getTokensAsync(): Promise<Token[]> {
const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const addresses = await tokenRegistryContract.getTokenAddresses.call();
const addresses = await this.getTokenAddressesAsync();
const tokenPromises: Array<Promise<Token|undefined>> = _.map(
addresses,
(address: string) => (this.getTokenIfExistsAsync(address)),
@@ -29,6 +29,15 @@ export class TokenRegistryWrapper extends ContractWrapper {
const tokens = await Promise.all(tokenPromises);
return tokens as Token[];
}
/**
* Retrieves all the addresses of the tokens currently listed in the Token Registry smart contract
* @return An array of token addresses.
*/
public async getTokenAddressesAsync(): Promise<string[]> {
const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const addresses = await tokenRegistryContract.getTokenAddresses.call();
return addresses;
}
/**
* Retrieves a token by address currently listed in the Token Registry smart contract
* @return An object that conforms to the Token interface or undefined if token not found.