Add getAccount to CosmWasmClient

This commit is contained in:
Ethan Frey 2020-02-16 19:08:16 +01:00 committed by Simon Warta
parent d4f5d1b801
commit b39a54211b
3 changed files with 28 additions and 2 deletions

View File

@ -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", () => {

View File

@ -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<GetNonceResult> {
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<CosmosSdkAccount> {
const account = await this.restClient.authAccounts(address || this.senderAddress);
return account.result.value;
}
/**
* Gets block header and meta
*

View File

@ -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<StdSignature>;
}
@ -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<GetNonceResult>;
getAccount(address?: string): Promise<CosmosSdkAccount>;
/**
* Gets block header and meta
*