stargate: Adjust StargateClient.getSequence
This commit is contained in:
parent
86fc265fba
commit
68dc0b45cf
@ -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 };
|
||||
}
|
||||
|
||||
@ -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();
|
||||
});
|
||||
|
||||
@ -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> {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user