stargate: Adjust StargateClient.getSequence

This commit is contained in:
willclarktech 2021-03-30 17:05:09 +02:00
parent 86fc265fba
commit 68dc0b45cf
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
3 changed files with 15 additions and 15 deletions

View File

@ -276,11 +276,7 @@ export class SigningStargateClient extends StargateClient {
if (explicitSignerData) {
signerData = explicitSignerData;
} else {
const accountFromChain = await this.getAccount(signerAddress);
if (!accountFromChain) {
throw new Error("Account not found");
}
const { accountNumber, sequence } = accountFromChain;
const { accountNumber, sequence } = await this.getSequence(signerAddress);
const chainId = await this.getChainId();
signerData = { accountNumber, sequence, chainId };
}

View File

@ -131,12 +131,13 @@ describe("StargateClient", () => {
client.disconnect();
});
it("returns null for non-existent address", async () => {
it("rejects for non-existent address", async () => {
pendingWithoutSimapp();
const client = await StargateClient.connect(simapp.tendermintUrl);
const account = await client.getSequence(nonExistentAddress);
expect(account).toBeNull();
await expectAsync(client.getSequence(nonExistentAddress)).toBeRejectedWithError(
/account does not exist on chain/i,
);
client.disconnect();
});

View File

@ -177,14 +177,17 @@ export class StargateClient {
return account ? accountFromAny(account) : null;
}
public async getSequence(address: string): Promise<SequenceResponse | null> {
public async getSequence(address: string): Promise<SequenceResponse> {
const account = await this.getAccount(address);
return account
? {
accountNumber: account.accountNumber,
sequence: account.sequence,
}
: null;
if (!account) {
throw new Error(
"Account does not exist on chain. Send some tokens there before trying to query sequence.",
);
}
return {
accountNumber: account.accountNumber,
sequence: account.sequence,
};
}
public async getBlock(height?: number): Promise<Block> {