aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-05-30 18:37:45 +0800
committerFabio Berger <me@fabioberger.com>2017-05-30 18:37:45 +0800
commite8a52ce1da454ab3a30b6f7d314aa85cf9534a05 (patch)
tree530fb9f1d2173d19b76b96ae48a6cff90bdc9925 /src/contract_wrappers
parentd15002a1109ea00f4d92c7ae6259b5b657f5e4b3 (diff)
parent911ab437b8f9371f70e835f680d799b7c62fb140 (diff)
downloaddexon-sol-tools-e8a52ce1da454ab3a30b6f7d314aa85cf9534a05.tar
dexon-sol-tools-e8a52ce1da454ab3a30b6f7d314aa85cf9534a05.tar.gz
dexon-sol-tools-e8a52ce1da454ab3a30b6f7d314aa85cf9534a05.tar.bz2
dexon-sol-tools-e8a52ce1da454ab3a30b6f7d314aa85cf9534a05.tar.lz
dexon-sol-tools-e8a52ce1da454ab3a30b6f7d314aa85cf9534a05.tar.xz
dexon-sol-tools-e8a52ce1da454ab3a30b6f7d314aa85cf9534a05.tar.zst
dexon-sol-tools-e8a52ce1da454ab3a30b6f7d314aa85cf9534a05.zip
Merge branch 'master' into dontReinstantiateContractInstances
Diffstat (limited to 'src/contract_wrappers')
-rw-r--r--src/contract_wrappers/token_registry_wrapper.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts
new file mode 100644
index 000000000..8dd79171e
--- /dev/null
+++ b/src/contract_wrappers/token_registry_wrapper.ts
@@ -0,0 +1,33 @@
+import * as _ from 'lodash';
+import {Web3Wrapper} from '../web3_wrapper';
+import {Token, TokenRegistryContract, TokenMetadata} 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<Token[]> {
+ const contractInstance = await this.instantiateContractIfExistsAsync((TokenRegistryArtifacts as any));
+ const tokenRegistryContract = contractInstance as TokenRegistryContract;
+
+ const addresses = await tokenRegistryContract.getTokenAddresses.call();
+ const tokenMetadataPromises: Array<Promise<TokenMetadata>> = _.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;
+ }
+}