Skip to content

Commit

Permalink
Specify supported tokens in Cosmos connection
Browse files Browse the repository at this point in the history
  • Loading branch information
willclarktech committed Nov 6, 2019
1 parent 03ef397 commit 0af02ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/iov-cosmos/src/cosmosconnection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ describe("CosmosConnection", () => {
}
expect(account.address).toEqual(defaultAddress);
expect(account.pubkey).toEqual(defaultPubkey);
expect(account.balance.length).toEqual(2);
// Unsupported coins are filtered out
expect(account.balance.length).toEqual(1);
connection.disconnect();
});

Expand All @@ -102,7 +103,8 @@ describe("CosmosConnection", () => {
algo: Algorithm.Secp256k1,
data: fromBase64("A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ"),
});
expect(account.balance.length).toEqual(2);
// Unsupported coins are filtered out
expect(account.balance.length).toEqual(1);
connection.disconnect();
});
});
Expand Down
5 changes: 4 additions & 1 deletion packages/iov-cosmos/src/cosmosconnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class CosmosConnection implements BlockchainConnection {

private readonly restClient: RestClient;
private readonly chainData: ChainData;
private readonly supportedTokens: readonly string[];

private get prefix(): CosmosBech32Prefix {
return "cosmos";
Expand All @@ -88,6 +89,7 @@ export class CosmosConnection implements BlockchainConnection {
private constructor(restClient: RestClient, chainData: ChainData) {
this.restClient = restClient;
this.chainData = chainData;
this.supportedTokens = ["uatom"];
}

public disconnect(): void {
Expand Down Expand Up @@ -115,11 +117,12 @@ export class CosmosConnection implements BlockchainConnection {
const address = isPubkeyQuery(query) ? pubkeyToAddress(query.pubkey, this.prefix) : query.address;
const { result } = await this.restClient.authAccounts(address);
const account = result.value;
const supportedCoins = account.coins.filter(coin => this.supportedTokens.includes(coin.denom));
return account.public_key === null
? undefined
: {
address: address,
balance: account.coins.map(decodeAmount),
balance: supportedCoins.map(decodeAmount),
pubkey: {
algo: Algorithm.Secp256k1,
data: fromBase64(account.public_key.value) as PubkeyBytes,
Expand Down
1 change: 1 addition & 0 deletions packages/iov-cosmos/types/cosmosconnection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export declare class CosmosConnection implements BlockchainConnection {
private static initialize;
private readonly restClient;
private readonly chainData;
private readonly supportedTokens;
private readonly prefix;
private constructor();
disconnect(): void;
Expand Down

0 comments on commit 0af02ad

Please sign in to comment.