From b39a54211b4fc7318ad8dd10a897d6656b6c74a1 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Sun, 16 Feb 2020 19:08:16 +0100 Subject: [PATCH] Add getAccount to CosmWasmClient --- packages/sdk/src/cosmwasmclient.spec.ts | 19 +++++++++++++++++++ packages/sdk/src/cosmwasmclient.ts | 8 +++++++- packages/sdk/types/cosmwasmclient.d.ts | 3 ++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/sdk/src/cosmwasmclient.spec.ts b/packages/sdk/src/cosmwasmclient.spec.ts index b2098969..2994e3b9 100644 --- a/packages/sdk/src/cosmwasmclient.spec.ts +++ b/packages/sdk/src/cosmwasmclient.spec.ts @@ -73,6 +73,25 @@ describe("CosmWasmClient", () => { sequence: 0, }); }); + + + }); + + describe("getAccount", () => { + it("works", async () => { + pendingWithoutCosmos(); + const client = CosmWasmClient.makeReadOnly(httpUrl); + expect(await client.getAccount(unusedAccount.address)).toEqual({ + address: unusedAccount.address, + account_number: 5, + sequence: 0, + public_key: "", + coins: [ + {denom: 'ucosm', amount: '1000000000'}, + {denom: 'ustake', amount: '1000000000'}, + ], + }); + }); }); describe("getBlock", () => { diff --git a/packages/sdk/src/cosmwasmclient.ts b/packages/sdk/src/cosmwasmclient.ts index b80e86f8..55335904 100644 --- a/packages/sdk/src/cosmwasmclient.ts +++ b/packages/sdk/src/cosmwasmclient.ts @@ -12,6 +12,7 @@ import { MsgStoreCode, StdFee, StdSignature, + CosmosSdkAccount, } from "./types"; const defaultUploadFee: StdFee = { @@ -150,13 +151,18 @@ export class CosmWasmClient { * @param address returns data for this address. When unset, the client's sender adddress is used. */ public async getNonce(address?: string): Promise { - const account = (await this.restClient.authAccounts(address || this.senderAddress)).result.value; + const account = await this.getAccount(address); return { accountNumber: account.account_number, sequence: account.sequence, }; } + public async getAccount(address?: string): Promise { + const account = await this.restClient.authAccounts(address || this.senderAddress); + return account.result.value; + } + /** * Gets block header and meta * diff --git a/packages/sdk/types/cosmwasmclient.d.ts b/packages/sdk/types/cosmwasmclient.d.ts index bd66f743..da430498 100644 --- a/packages/sdk/types/cosmwasmclient.d.ts +++ b/packages/sdk/types/cosmwasmclient.d.ts @@ -1,6 +1,6 @@ import { Log } from "./logs"; import { BlockResponse, TxsResponse } from "./restclient"; -import { Coin, CosmosSdkTx, StdSignature } from "./types"; +import { Coin, CosmosSdkTx, StdSignature, CosmosSdkAccount } from "./types"; export interface SigningCallback { (signBytes: Uint8Array): Promise; } @@ -46,6 +46,7 @@ export declare class CosmWasmClient { * @param address returns data for this address. When unset, the client's sender adddress is used. */ getNonce(address?: string): Promise; + getAccount(address?: string): Promise; /** * Gets block header and meta *