Add pagination support to BankExtension.totalSupply

This commit is contained in:
Simon Warta 2022-08-11 22:20:38 +02:00
parent 26557c1c20
commit 3216b838dc
3 changed files with 14 additions and 8 deletions

View File

@ -61,12 +61,16 @@ and this project adheres to
- @cosmjs/stargate: Remove Cosmos SDK 0.42 support ([#1094]). - @cosmjs/stargate: Remove Cosmos SDK 0.42 support ([#1094]).
- @cosmjs/tendermint-rpc: Change spelling of field `codeSpace` to `codespace` in - @cosmjs/tendermint-rpc: Change spelling of field `codeSpace` to `codespace` in
`TxData` and `BroadcastTxSyncResponse` ([#1234]). `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 [#1131]: https://github.com/cosmos/cosmjs/pull/1131
[#1168]: https://github.com/cosmos/cosmjs/pull/1168 [#1168]: https://github.com/cosmos/cosmjs/pull/1168
[#1133]: https://github.com/cosmos/cosmjs/issues/1133 [#1133]: https://github.com/cosmos/cosmjs/issues/1133
[#1094]: https://github.com/cosmos/cosmjs/issues/1094 [#1094]: https://github.com/cosmos/cosmjs/issues/1094
[#1234]: https://github.com/cosmos/cosmjs/issues/1234 [#1234]: https://github.com/cosmos/cosmjs/issues/1234
[#1095]: https://github.com/cosmos/cosmjs/issues/1095
## [0.28.11] - 2022-07-13 ## [0.28.11] - 2022-07-13

View File

@ -100,8 +100,8 @@ describe("BankExtension", () => {
pendingWithoutSimapp(); pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl); const [client, tmClient] = await makeClientWithBank(simapp.tendermintUrl);
const response = await client.bank.totalSupply(); const { supply } = await client.bank.totalSupply();
expect(response).toEqual([ expect(supply).toEqual([
{ {
amount: simapp.totalSupply.toString(), amount: simapp.totalSupply.toString(),
denom: simapp.denomFee, denom: simapp.denomFee,

View File

@ -1,16 +1,16 @@
/* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable @typescript-eslint/naming-convention */
import { assert } from "@cosmjs/utils"; import { assert } from "@cosmjs/utils";
import { Metadata } from "cosmjs-types/cosmos/bank/v1beta1/bank"; 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 { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
import { createProtobufRpcClient, QueryClient } from "../../queryclient"; import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient";
export interface BankExtension { export interface BankExtension {
readonly bank: { readonly bank: {
readonly balance: (address: string, denom: string) => Promise<Coin>; readonly balance: (address: string, denom: string) => Promise<Coin>;
readonly allBalances: (address: string) => Promise<Coin[]>; readonly allBalances: (address: string) => Promise<Coin[]>;
readonly totalSupply: () => Promise<Coin[]>; readonly totalSupply: (paginationKey?: Uint8Array) => Promise<QueryTotalSupplyResponse>;
readonly supplyOf: (denom: string) => Promise<Coin>; readonly supplyOf: (denom: string) => Promise<Coin>;
readonly denomMetadata: (denom: string) => Promise<Metadata>; readonly denomMetadata: (denom: string) => Promise<Metadata>;
readonly denomsMetadata: () => Promise<Metadata[]>; readonly denomsMetadata: () => Promise<Metadata[]>;
@ -34,9 +34,11 @@ export function setupBankExtension(base: QueryClient): BankExtension {
const { balances } = await queryService.AllBalances({ address: address }); const { balances } = await queryService.AllBalances({ address: address });
return balances; return balances;
}, },
totalSupply: async () => { totalSupply: async (paginationKey?: Uint8Array) => {
const { supply } = await queryService.TotalSupply({}); const response = await queryService.TotalSupply({
return supply; pagination: createPagination(paginationKey),
});
return response;
}, },
supplyOf: async (denom: string) => { supplyOf: async (denom: string) => {
const { amount } = await queryService.SupplyOf({ denom: denom }); const { amount } = await queryService.SupplyOf({ denom: denom });