aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-08-24 02:28:48 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-08-24 15:59:10 +0800
commite4f5b9cdb3021a7af1fa97c2ef0233bdf59af62c (patch)
treea73fa5ef968c34f1668a1a7acef147abee656a10
parent0d7b75801a4594ebbf2d712441d04418473a51f5 (diff)
downloaddexon-sol-tools-e4f5b9cdb3021a7af1fa97c2ef0233bdf59af62c.tar
dexon-sol-tools-e4f5b9cdb3021a7af1fa97c2ef0233bdf59af62c.tar.gz
dexon-sol-tools-e4f5b9cdb3021a7af1fa97c2ef0233bdf59af62c.tar.bz2
dexon-sol-tools-e4f5b9cdb3021a7af1fa97c2ef0233bdf59af62c.tar.lz
dexon-sol-tools-e4f5b9cdb3021a7af1fa97c2ef0233bdf59af62c.tar.xz
dexon-sol-tools-e4f5b9cdb3021a7af1fa97c2ef0233bdf59af62c.tar.zst
dexon-sol-tools-e4f5b9cdb3021a7af1fa97c2ef0233bdf59af62c.zip
Add all public tokenRegistry functions
-rw-r--r--src/contract_wrappers/token_registry_wrapper.ts38
-rw-r--r--src/types.ts12
2 files changed, 50 insertions, 0 deletions
diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts
index ddfbc35ae..207259fcd 100644
--- a/src/contract_wrappers/token_registry_wrapper.ts
+++ b/src/contract_wrappers/token_registry_wrapper.ts
@@ -47,6 +47,44 @@ export class TokenRegistryWrapper extends ContractWrapper {
const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const metadata = await tokenRegistryContract.getTokenMetaData.call(address);
+ const token = this._getTokenByMetadata(metadata);
+ return token;
+ }
+ public async getTokenAddressBySymbolIfExistsAsync(symbol: string): Promise<string|undefined> {
+ assert.isString('symbol', symbol);
+ const tokenRegistryContract = await this._getTokenRegistryContractAsync();
+ const addressIfExists = await tokenRegistryContract.getTokenAddressBySymbol.call(symbol);
+ if (addressIfExists === constants.NULL_ADDRESS) {
+ return undefined;
+ } else {
+ return addressIfExists;
+ }
+ }
+ public async getTokenAddressByNameIfExistsAsync(symbol: string): Promise<string|undefined> {
+ assert.isString('name', name);
+ const tokenRegistryContract = await this._getTokenRegistryContractAsync();
+ const addressIfExists = await tokenRegistryContract.getTokenAddressByName.call(name);
+ if (addressIfExists === constants.NULL_ADDRESS) {
+ return undefined;
+ } else {
+ return addressIfExists;
+ }
+ }
+ public async getTokenBySymbolIfExistsAsync(symbol: string): Promise<Token|undefined> {
+ assert.isString('symbol', symbol);
+ const tokenRegistryContract = await this._getTokenRegistryContractAsync();
+ const metadata = await tokenRegistryContract.getTokenBySymbol.call(symbol);
+ const token = this._getTokenByMetadata(metadata);
+ return token;
+ }
+ public async getTokenByNameIfExistsAsync(name: string): Promise<Token|undefined> {
+ assert.isString('name', name);
+ const tokenRegistryContract = await this._getTokenRegistryContractAsync();
+ const metadata = await tokenRegistryContract.getTokenByName.call(name);
+ const token = this._getTokenByMetadata(metadata);
+ return token;
+ }
+ private _getTokenByMetadata(metadata: TokenMetadata): Token|undefined {
if (metadata[0] === constants.NULL_ADDRESS) {
return undefined;
}
diff --git a/src/types.ts b/src/types.ts
index 5ba85a7d5..71227647b 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -145,6 +145,18 @@ export interface TokenRegistryContract extends ContractInstance {
getTokenAddresses: {
call: () => Promise<string[]>;
};
+ getTokenAddressBySymbol: {
+ call: (symbol: string) => Promise<string>;
+ };
+ getTokenAddressByName: {
+ call: (name: string) => Promise<string>;
+ };
+ getTokenBySymbol: {
+ call: (symbol: string) => Promise<TokenMetadata>;
+ };
+ getTokenByName: {
+ call: (name: string) => Promise<TokenMetadata>;
+ };
}
export interface EtherTokenContract extends ContractInstance {