Merge pull request #1238 from cosmos/totalSupply-pagination

Add pagination support to BankExtension.totalSupply
This commit is contained in:
Simon Warta 2022-08-12 11:17:04 +02:00 committed by GitHub
commit 4b230fb447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 16 deletions

View File

@ -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

View File

@ -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,

View File

@ -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<Coin>;
readonly allBalances: (address: string) => Promise<Coin[]>;
readonly totalSupply: () => Promise<Coin[]>;
readonly totalSupply: (paginationKey?: Uint8Array) => Promise<QueryTotalSupplyResponse>;
readonly supplyOf: (denom: string) => Promise<Coin>;
readonly denomMetadata: (denom: string) => Promise<Metadata>;
readonly denomsMetadata: () => Promise<Metadata[]>;
@ -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 });

View File

@ -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 {