diff --git a/CHANGELOG.md b/CHANGELOG.md index e2b99d525d..6ffd30780b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/stargate/src/queries/auth.spec.ts b/packages/stargate/src/queries/auth.spec.ts index b68ffc4476..d744bb49e6 100644 --- a/packages/stargate/src/queries/auth.spec.ts +++ b/packages/stargate/src/queries/auth.spec.ts @@ -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(); - }); - }); - }); }); diff --git a/packages/stargate/src/queries/auth.ts b/packages/stargate/src/queries/auth.ts index 0368b0ddba..958f5a432a 100644 --- a/packages/stargate/src/queries/auth.ts +++ b/packages/stargate/src/queries/auth.ts @@ -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; - 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; - }; }; } @@ -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); - }, - }, }, }; } diff --git a/packages/stargate/src/queries/bank.spec.ts b/packages/stargate/src/queries/bank.spec.ts index e6fdc1c97d..e0fd0ae62b 100644 --- a/packages/stargate/src/queries/bank.spec.ts +++ b/packages/stargate/src/queries/bank.spec.ts @@ -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(); - }); - }); - }); }); diff --git a/packages/stargate/src/queries/bank.ts b/packages/stargate/src/queries/bank.ts index 5ed5d1a50b..7e7c254e03 100644 --- a/packages/stargate/src/queries/bank.ts +++ b/packages/stargate/src/queries/bank.ts @@ -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; readonly totalSupply: () => Promise; readonly supplyOf: (denom: string) => Promise; - readonly verified: { - readonly balance: (address: string, denom: string) => Promise; - }; }; } @@ -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; - }, - }, }, }; } diff --git a/packages/stargate/src/stargateclient.ts b/packages/stargate/src/stargateclient.ts index a0ac1e59a2..dde63ba63a 100644 --- a/packages/stargate/src/stargateclient.ts +++ b/packages/stargate/src/stargateclient.ts @@ -218,11 +218,6 @@ export class StargateClient { } } - public async getAccountVerified(searchAddress: string): Promise { - const account = await this.forceGetQueryClient().auth.verified.account(searchAddress); - return account ? accountFromAny(account) : null; - } - public async getSequence(address: string): Promise { const account = await this.getAccount(address); if (!account) {