Remove verified queries

This commit is contained in:
Simon Warta 2021-10-20 23:12:16 +02:00
parent 57e4e2ca46
commit 4547b8ea50
6 changed files with 13 additions and 133 deletions

View File

@ -12,6 +12,17 @@ and this project adheres to
adding the fields `LaunchpadLedgerOptions.ledgerAppName` and
`.minLedgerAppVersion`.
### Changed
- @cosmjs/stargate: Remove verified queries from `AuthExtension` and
`BankExtension` as well as `StargateClient.getAccountVerified` because the
storage layout is not stable across multiple Cosmos SDK releases. Verified
queries remain available in the `IbcExtension` because for IBC the storage
layout is standardized. Such queries can still be implemented in CosmJS caller
code that only needs to support one backend. ([#865])
[#865]: https://github.com/cosmos/cosmjs/issues/865
## [0.26.2] - 2021-10-12
### Fixed

View File

@ -64,52 +64,4 @@ describe("AuthExtension", () => {
tmClient.disconnect();
});
});
describe("verified", () => {
describe("account", () => {
it("works for unused account", async () => {
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithAuth(simapp.tendermintUrl);
const account = await client.auth.verified.account(unused.address);
assert(account);
expect(account.typeUrl).toEqual("/cosmos.auth.v1beta1.BaseAccount");
expect(BaseAccount.decode(account.value)).toEqual({
address: unused.address,
// pubKey not set
accountNumber: Long.fromNumber(unused.accountNumber, true),
sequence: Long.fromNumber(0, true),
});
tmClient.disconnect();
});
it("works for account with pubkey and non-zero sequence", async () => {
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithAuth(simapp.tendermintUrl);
const account = await client.auth.verified.account(validator.delegatorAddress);
assert(account);
expect(account.typeUrl).toEqual("/cosmos.auth.v1beta1.BaseAccount");
expect(BaseAccount.decode(account.value)).toEqual({
address: validator.delegatorAddress,
pubKey: Any.fromPartial(encodePubkey(validator.pubkey)),
accountNumber: Long.fromNumber(0, true),
sequence: Long.fromNumber(validator.sequence, true),
});
tmClient.disconnect();
});
it("returns null for non-existent address", async () => {
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithAuth(simapp.tendermintUrl);
const account = await client.auth.verified.account(nonExistentAddress);
expect(account).toBeNull();
tmClient.disconnect();
});
});
});
});

View File

@ -2,7 +2,7 @@ import { QueryClientImpl } from "cosmjs-types/cosmos/auth/v1beta1/query";
import { Any } from "cosmjs-types/google/protobuf/any";
import { QueryClient } from "./queryclient";
import { createProtobufRpcClient, toAccAddress } from "./utils";
import { createProtobufRpcClient } from "./utils";
export interface AuthExtension {
readonly auth: {
@ -14,16 +14,6 @@ export interface AuthExtension {
* `typeUrl` and decode the `value` using its own type decoder.
*/
readonly account: (address: string) => Promise<Any | null>;
readonly verified: {
/**
* Returns an account if it exists and `null` otherwise.
*
* The account is a protobuf Any in order to be able to support many different
* account types in one API. The caller needs to switch over the expected and supported
* `typeUrl` and decode the `value` using its own type decoder.
*/
readonly account: (address: string) => Promise<Any | null>;
};
};
}
@ -39,15 +29,6 @@ export function setupAuthExtension(base: QueryClient): AuthExtension {
const { account } = await queryService.Account({ address: address });
return account ?? null;
},
verified: {
account: async (address: string) => {
// https://github.com/cosmos/cosmos-sdk/blob/8cab43c8120fec5200c3459cbf4a92017bb6f287/x/auth/types/keys.go#L29-L32
const key = Uint8Array.from([0x01, ...toAccAddress(address)]);
const responseData = await base.queryVerified("acc", key);
if (responseData.length === 0) return null;
return Any.decode(responseData);
},
},
},
};
}

View File

@ -143,46 +143,4 @@ describe("BankExtension", () => {
tmClient.disconnect();
});
});
describe("verified", () => {
describe("balance", () => {
it("works for different existing balances", async () => {
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl);
const response1 = await client.bank.verified.balance(unused.address, simapp.denomFee);
expect(response1).toEqual({
amount: unused.balanceFee,
denom: simapp.denomFee,
});
const response2 = await client.bank.verified.balance(unused.address, simapp.denomStaking);
expect(response2).toEqual({
amount: unused.balanceStaking,
denom: simapp.denomStaking,
});
tmClient.disconnect();
});
it("returns null for non-existent balance", async () => {
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl);
const response = await client.bank.verified.balance(unused.address, "gintonic");
expect(response).toBeNull();
tmClient.disconnect();
});
it("returns null for non-existent address", async () => {
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl);
const response = await client.bank.verified.balance(nonExistentAddress, simapp.denomFee);
expect(response).toBeNull();
tmClient.disconnect();
});
});
});
});

View File

@ -1,11 +1,10 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { toAscii } from "@cosmjs/encoding";
import { assert } from "@cosmjs/utils";
import { QueryClientImpl } from "cosmjs-types/cosmos/bank/v1beta1/query";
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
import { QueryClient } from "./queryclient";
import { createProtobufRpcClient, toAccAddress } from "./utils";
import { createProtobufRpcClient } from "./utils";
export interface BankExtension {
readonly bank: {
@ -13,9 +12,6 @@ export interface BankExtension {
readonly allBalances: (address: string) => Promise<Coin[]>;
readonly totalSupply: () => Promise<Coin[]>;
readonly supplyOf: (denom: string) => Promise<Coin>;
readonly verified: {
readonly balance: (address: string, denom: string) => Promise<Coin | null>;
};
};
}
@ -45,19 +41,6 @@ export function setupBankExtension(base: QueryClient): BankExtension {
assert(amount);
return amount;
},
verified: {
balance: async (address: string, denom: string) => {
// balance key is a bit tricker, using some prefix stores
// https://github.com/cosmwasm/cosmos-sdk/blob/80f7ff62f79777a487d0c7a53c64b0f7e43c47b9/x/bank/keeper/view.go#L74-L77
// ("balances", binAddress, denom)
// it seem like prefix stores just do a dumb concat with the keys (no tricks to avoid overlap)
// https://github.com/cosmos/cosmos-sdk/blob/2879c0702c87dc9dd828a8c42b9224dc054e28ad/store/prefix/store.go#L61-L64
// https://github.com/cosmos/cosmos-sdk/blob/2879c0702c87dc9dd828a8c42b9224dc054e28ad/store/prefix/store.go#L37-L43
const key = Uint8Array.from([...toAscii("balances"), ...toAccAddress(address), ...toAscii(denom)]);
const responseData = await base.queryVerified("bank", key);
return responseData.length ? Coin.decode(responseData) : null;
},
},
},
};
}

View File

@ -218,11 +218,6 @@ export class StargateClient {
}
}
public async getAccountVerified(searchAddress: string): Promise<Account | null> {
const account = await this.forceGetQueryClient().auth.verified.account(searchAddress);
return account ? accountFromAny(account) : null;
}
public async getSequence(address: string): Promise<SequenceResponse> {
const account = await this.getAccount(address);
if (!account) {