Skip to content

Commit 099d667

Browse files
authored
Merge pull request #910 from cosmos/remove-verified-queries
Remove verified queries from AuthExtension and BankExtension
2 parents 57e4e2c + 4547b8e commit 099d667

File tree

6 files changed

+13
-133
lines changed

6 files changed

+13
-133
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ and this project adheres to
1212
adding the fields `LaunchpadLedgerOptions.ledgerAppName` and
1313
`.minLedgerAppVersion`.
1414

15+
### Changed
16+
17+
- @cosmjs/stargate: Remove verified queries from `AuthExtension` and
18+
`BankExtension` as well as `StargateClient.getAccountVerified` because the
19+
storage layout is not stable across multiple Cosmos SDK releases. Verified
20+
queries remain available in the `IbcExtension` because for IBC the storage
21+
layout is standardized. Such queries can still be implemented in CosmJS caller
22+
code that only needs to support one backend. ([#865])
23+
24+
[#865]: https://github.com/cosmos/cosmjs/issues/865
25+
1526
## [0.26.2] - 2021-10-12
1627

1728
### Fixed

packages/stargate/src/queries/auth.spec.ts

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -64,52 +64,4 @@ describe("AuthExtension", () => {
6464
tmClient.disconnect();
6565
});
6666
});
67-
68-
describe("verified", () => {
69-
describe("account", () => {
70-
it("works for unused account", async () => {
71-
pendingWithoutSimapp();
72-
const [client, tmClient] = await makeClientWithAuth(simapp.tendermintUrl);
73-
const account = await client.auth.verified.account(unused.address);
74-
assert(account);
75-
76-
expect(account.typeUrl).toEqual("/cosmos.auth.v1beta1.BaseAccount");
77-
expect(BaseAccount.decode(account.value)).toEqual({
78-
address: unused.address,
79-
// pubKey not set
80-
accountNumber: Long.fromNumber(unused.accountNumber, true),
81-
sequence: Long.fromNumber(0, true),
82-
});
83-
84-
tmClient.disconnect();
85-
});
86-
87-
it("works for account with pubkey and non-zero sequence", async () => {
88-
pendingWithoutSimapp();
89-
const [client, tmClient] = await makeClientWithAuth(simapp.tendermintUrl);
90-
const account = await client.auth.verified.account(validator.delegatorAddress);
91-
assert(account);
92-
93-
expect(account.typeUrl).toEqual("/cosmos.auth.v1beta1.BaseAccount");
94-
expect(BaseAccount.decode(account.value)).toEqual({
95-
address: validator.delegatorAddress,
96-
pubKey: Any.fromPartial(encodePubkey(validator.pubkey)),
97-
accountNumber: Long.fromNumber(0, true),
98-
sequence: Long.fromNumber(validator.sequence, true),
99-
});
100-
101-
tmClient.disconnect();
102-
});
103-
104-
it("returns null for non-existent address", async () => {
105-
pendingWithoutSimapp();
106-
const [client, tmClient] = await makeClientWithAuth(simapp.tendermintUrl);
107-
const account = await client.auth.verified.account(nonExistentAddress);
108-
109-
expect(account).toBeNull();
110-
111-
tmClient.disconnect();
112-
});
113-
});
114-
});
11567
});

packages/stargate/src/queries/auth.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { QueryClientImpl } from "cosmjs-types/cosmos/auth/v1beta1/query";
22
import { Any } from "cosmjs-types/google/protobuf/any";
33

44
import { QueryClient } from "./queryclient";
5-
import { createProtobufRpcClient, toAccAddress } from "./utils";
5+
import { createProtobufRpcClient } from "./utils";
66

77
export interface AuthExtension {
88
readonly auth: {
@@ -14,16 +14,6 @@ export interface AuthExtension {
1414
* `typeUrl` and decode the `value` using its own type decoder.
1515
*/
1616
readonly account: (address: string) => Promise<Any | null>;
17-
readonly verified: {
18-
/**
19-
* Returns an account if it exists and `null` otherwise.
20-
*
21-
* The account is a protobuf Any in order to be able to support many different
22-
* account types in one API. The caller needs to switch over the expected and supported
23-
* `typeUrl` and decode the `value` using its own type decoder.
24-
*/
25-
readonly account: (address: string) => Promise<Any | null>;
26-
};
2717
};
2818
}
2919

@@ -39,15 +29,6 @@ export function setupAuthExtension(base: QueryClient): AuthExtension {
3929
const { account } = await queryService.Account({ address: address });
4030
return account ?? null;
4131
},
42-
verified: {
43-
account: async (address: string) => {
44-
// https://github.com/cosmos/cosmos-sdk/blob/8cab43c8120fec5200c3459cbf4a92017bb6f287/x/auth/types/keys.go#L29-L32
45-
const key = Uint8Array.from([0x01, ...toAccAddress(address)]);
46-
const responseData = await base.queryVerified("acc", key);
47-
if (responseData.length === 0) return null;
48-
return Any.decode(responseData);
49-
},
50-
},
5132
},
5233
};
5334
}

packages/stargate/src/queries/bank.spec.ts

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -143,46 +143,4 @@ describe("BankExtension", () => {
143143
tmClient.disconnect();
144144
});
145145
});
146-
147-
describe("verified", () => {
148-
describe("balance", () => {
149-
it("works for different existing balances", async () => {
150-
pendingWithoutSimapp();
151-
const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl);
152-
153-
const response1 = await client.bank.verified.balance(unused.address, simapp.denomFee);
154-
expect(response1).toEqual({
155-
amount: unused.balanceFee,
156-
denom: simapp.denomFee,
157-
});
158-
const response2 = await client.bank.verified.balance(unused.address, simapp.denomStaking);
159-
expect(response2).toEqual({
160-
amount: unused.balanceStaking,
161-
denom: simapp.denomStaking,
162-
});
163-
164-
tmClient.disconnect();
165-
});
166-
167-
it("returns null for non-existent balance", async () => {
168-
pendingWithoutSimapp();
169-
const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl);
170-
171-
const response = await client.bank.verified.balance(unused.address, "gintonic");
172-
expect(response).toBeNull();
173-
174-
tmClient.disconnect();
175-
});
176-
177-
it("returns null for non-existent address", async () => {
178-
pendingWithoutSimapp();
179-
const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl);
180-
181-
const response = await client.bank.verified.balance(nonExistentAddress, simapp.denomFee);
182-
expect(response).toBeNull();
183-
184-
tmClient.disconnect();
185-
});
186-
});
187-
});
188146
});

packages/stargate/src/queries/bank.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
/* eslint-disable @typescript-eslint/naming-convention */
2-
import { toAscii } from "@cosmjs/encoding";
32
import { assert } from "@cosmjs/utils";
43
import { QueryClientImpl } from "cosmjs-types/cosmos/bank/v1beta1/query";
54
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
65

76
import { QueryClient } from "./queryclient";
8-
import { createProtobufRpcClient, toAccAddress } from "./utils";
7+
import { createProtobufRpcClient } from "./utils";
98

109
export interface BankExtension {
1110
readonly bank: {
1211
readonly balance: (address: string, denom: string) => Promise<Coin>;
1312
readonly allBalances: (address: string) => Promise<Coin[]>;
1413
readonly totalSupply: () => Promise<Coin[]>;
1514
readonly supplyOf: (denom: string) => Promise<Coin>;
16-
readonly verified: {
17-
readonly balance: (address: string, denom: string) => Promise<Coin | null>;
18-
};
1915
};
2016
}
2117

@@ -45,19 +41,6 @@ export function setupBankExtension(base: QueryClient): BankExtension {
4541
assert(amount);
4642
return amount;
4743
},
48-
verified: {
49-
balance: async (address: string, denom: string) => {
50-
// balance key is a bit tricker, using some prefix stores
51-
// https://github.com/cosmwasm/cosmos-sdk/blob/80f7ff62f79777a487d0c7a53c64b0f7e43c47b9/x/bank/keeper/view.go#L74-L77
52-
// ("balances", binAddress, denom)
53-
// it seem like prefix stores just do a dumb concat with the keys (no tricks to avoid overlap)
54-
// https://github.com/cosmos/cosmos-sdk/blob/2879c0702c87dc9dd828a8c42b9224dc054e28ad/store/prefix/store.go#L61-L64
55-
// https://github.com/cosmos/cosmos-sdk/blob/2879c0702c87dc9dd828a8c42b9224dc054e28ad/store/prefix/store.go#L37-L43
56-
const key = Uint8Array.from([...toAscii("balances"), ...toAccAddress(address), ...toAscii(denom)]);
57-
const responseData = await base.queryVerified("bank", key);
58-
return responseData.length ? Coin.decode(responseData) : null;
59-
},
60-
},
6144
},
6245
};
6346
}

packages/stargate/src/stargateclient.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,6 @@ export class StargateClient {
218218
}
219219
}
220220

221-
public async getAccountVerified(searchAddress: string): Promise<Account | null> {
222-
const account = await this.forceGetQueryClient().auth.verified.account(searchAddress);
223-
return account ? accountFromAny(account) : null;
224-
}
225-
226221
public async getSequence(address: string): Promise<SequenceResponse> {
227222
const account = await this.getAccount(address);
228223
if (!account) {

0 commit comments

Comments
 (0)