mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
Let CosmWasmClient.getNonce throw
This commit is contained in:
parent
03f01f54d6
commit
28ee35217e
@ -74,14 +74,14 @@ describe("CosmWasmClient", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("returns zeros for missing accounts", async () => {
|
||||
it("throws for missing accounts", async () => {
|
||||
pendingWithoutCosmos();
|
||||
const client = CosmWasmClient.makeReadOnly(httpUrl);
|
||||
const missing = makeRandomAddress();
|
||||
expect(await client.getNonce(missing)).toEqual({
|
||||
accountNumber: 0,
|
||||
sequence: 0,
|
||||
});
|
||||
await client.getNonce(missing).then(
|
||||
() => fail("this must not succeed"),
|
||||
error => expect(error).toMatch(/account does not exist on chain/i),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -148,13 +148,20 @@ export class CosmWasmClient {
|
||||
/**
|
||||
* Returns account number and sequence.
|
||||
*
|
||||
* Throws if the account does not exist on chain.
|
||||
*
|
||||
* @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.getAccount(address);
|
||||
if (!account) {
|
||||
throw new Error(
|
||||
"Account does not exist on chain. Send some tokens there before trying to query nonces.",
|
||||
);
|
||||
}
|
||||
return {
|
||||
accountNumber: account ? account.account_number : 0,
|
||||
sequence: account ? account.sequence : 0,
|
||||
accountNumber: account.account_number,
|
||||
sequence: account.sequence,
|
||||
};
|
||||
}
|
||||
|
||||
|
4
packages/sdk/types/cosmwasmclient.d.ts
vendored
4
packages/sdk/types/cosmwasmclient.d.ts
vendored
@ -1,6 +1,6 @@
|
||||
import { Log } from "./logs";
|
||||
import { BlockResponse, TxsResponse } from "./restclient";
|
||||
import { Coin, CosmosSdkTx, StdSignature, CosmosSdkAccount } from "./types";
|
||||
import { Coin, CosmosSdkAccount, CosmosSdkTx, StdSignature } from "./types";
|
||||
export interface SigningCallback {
|
||||
(signBytes: Uint8Array): Promise<StdSignature>;
|
||||
}
|
||||
@ -43,6 +43,8 @@ export declare class CosmWasmClient {
|
||||
/**
|
||||
* Returns account number and sequence.
|
||||
*
|
||||
* Throws if the account does not exist on chain.
|
||||
*
|
||||
* @param address returns data for this address. When unset, the client's sender adddress is used.
|
||||
*/
|
||||
getNonce(address?: string): Promise<GetNonceResult>;
|
||||
|
Loading…
x
Reference in New Issue
Block a user