From 919585cd7972bae1667f67c9fa034251f27b14a8 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 29 May 2017 23:51:27 +0200 Subject: Add TokenRegistryWrapper and getTokensAsync method --- src/contract_wrappers/token_registry_wrapper.ts | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/contract_wrappers/token_registry_wrapper.ts (limited to 'src/contract_wrappers') diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts new file mode 100644 index 000000000..4d6eacb51 --- /dev/null +++ b/src/contract_wrappers/token_registry_wrapper.ts @@ -0,0 +1,33 @@ +import * as _ from 'lodash'; +import {Web3Wrapper} from '../web3_wrapper'; +import {ZeroExError, Token, TokenRegistryContract} from '../types'; +import {assert} from '../utils/assert'; +import {ContractWrapper} from './contract_wrapper'; +import * as TokenRegistryArtifacts from '../artifacts/TokenRegistry.json'; + +export class TokenRegistryWrapper extends ContractWrapper { + constructor(web3Wrapper: Web3Wrapper) { + super(web3Wrapper); + } + public async getTokensAsync(): Promise { + const contractInstance = await this.instantiateContractIfExistsAsync((TokenRegistryArtifacts as any)); + const tokenRegistryContract = contractInstance as TokenRegistryContract; + + const addresses = await tokenRegistryContract.getTokenAddresses.call(); + const tokenMetadataPromises: Array> = _.map( + addresses, + (address: string) => (tokenRegistryContract.getTokenMetaData.call(address)), + ); + const tokensMetadata = await Promise.all(tokenMetadataPromises); + const tokens = _.map(tokensMetadata, metadata => { + return { + address: metadata[0], + name: metadata[1], + symbol: metadata[2], + url: metadata[3], + decimals: metadata[4].toNumber(), + }; + }); + return tokens; + } +} -- cgit v1.2.3