From 26557c1c201cc5f365634af513baeb1ad60c7bd1 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 11 Aug 2022 22:14:51 +0200 Subject: [PATCH 1/2] Simplify PageRequest generation No need to set default values --- packages/stargate/src/queryclient/utils.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/stargate/src/queryclient/utils.ts b/packages/stargate/src/queryclient/utils.ts index fa086e90..a0fb6220 100644 --- a/packages/stargate/src/queryclient/utils.ts +++ b/packages/stargate/src/queryclient/utils.ts @@ -22,14 +22,7 @@ export function toAccAddress(address: string): Uint8Array { * request the next page. */ export function createPagination(paginationKey?: Uint8Array): PageRequest | undefined { - return paginationKey - ? PageRequest.fromPartial({ - key: paginationKey, - offset: Long.UZERO, - limit: Long.UZERO, - countTotal: false, - }) - : undefined; + return paginationKey ? PageRequest.fromPartial({ key: paginationKey }) : undefined; } export interface ProtobufRpcClient { From 3216b838dc1db4a83a852da8ddb090e2bd699462 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 11 Aug 2022 22:20:38 +0200 Subject: [PATCH 2/2] Add pagination support to BankExtension.totalSupply --- CHANGELOG.md | 4 ++++ packages/stargate/src/modules/bank/queries.spec.ts | 4 ++-- packages/stargate/src/modules/bank/queries.ts | 14 ++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e20e236..be44bcbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,12 +61,16 @@ and this project adheres to - @cosmjs/stargate: Remove Cosmos SDK 0.42 support ([#1094]). - @cosmjs/tendermint-rpc: Change spelling of field `codeSpace` to `codespace` in `TxData` and `BroadcastTxSyncResponse` ([#1234]). +- @cosmjs/stargate: `BankExtension.totalSupply` now takes a pagination key + argument and returns the full `QueryTotalSupplyResponse` including the next + pagination key ([#1095]). [#1131]: https://github.com/cosmos/cosmjs/pull/1131 [#1168]: https://github.com/cosmos/cosmjs/pull/1168 [#1133]: https://github.com/cosmos/cosmjs/issues/1133 [#1094]: https://github.com/cosmos/cosmjs/issues/1094 [#1234]: https://github.com/cosmos/cosmjs/issues/1234 +[#1095]: https://github.com/cosmos/cosmjs/issues/1095 ## [0.28.11] - 2022-07-13 diff --git a/packages/stargate/src/modules/bank/queries.spec.ts b/packages/stargate/src/modules/bank/queries.spec.ts index bfd4d1ad..7f7b96ff 100644 --- a/packages/stargate/src/modules/bank/queries.spec.ts +++ b/packages/stargate/src/modules/bank/queries.spec.ts @@ -100,8 +100,8 @@ describe("BankExtension", () => { pendingWithoutSimapp(); const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl); - const response = await client.bank.totalSupply(); - expect(response).toEqual([ + const { supply } = await client.bank.totalSupply(); + expect(supply).toEqual([ { amount: simapp.totalSupply.toString(), denom: simapp.denomFee, diff --git a/packages/stargate/src/modules/bank/queries.ts b/packages/stargate/src/modules/bank/queries.ts index 9c596789..c631fe47 100644 --- a/packages/stargate/src/modules/bank/queries.ts +++ b/packages/stargate/src/modules/bank/queries.ts @@ -1,16 +1,16 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { assert } from "@cosmjs/utils"; import { Metadata } from "cosmjs-types/cosmos/bank/v1beta1/bank"; -import { QueryClientImpl } from "cosmjs-types/cosmos/bank/v1beta1/query"; +import { QueryClientImpl, QueryTotalSupplyResponse } from "cosmjs-types/cosmos/bank/v1beta1/query"; import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin"; -import { createProtobufRpcClient, QueryClient } from "../../queryclient"; +import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient"; export interface BankExtension { readonly bank: { readonly balance: (address: string, denom: string) => Promise; readonly allBalances: (address: string) => Promise; - readonly totalSupply: () => Promise; + readonly totalSupply: (paginationKey?: Uint8Array) => Promise; readonly supplyOf: (denom: string) => Promise; readonly denomMetadata: (denom: string) => Promise; readonly denomsMetadata: () => Promise; @@ -34,9 +34,11 @@ export function setupBankExtension(base: QueryClient): BankExtension { const { balances } = await queryService.AllBalances({ address: address }); return balances; }, - totalSupply: async () => { - const { supply } = await queryService.TotalSupply({}); - return supply; + totalSupply: async (paginationKey?: Uint8Array) => { + const response = await queryService.TotalSupply({ + pagination: createPagination(paginationKey), + }); + return response; }, supplyOf: async (denom: string) => { const { amount } = await queryService.SupplyOf({ denom: denom });