Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stargate: no pagination available for Bank/TotalSupply #1057

Closed
JGJP opened this issue Feb 22, 2022 · 12 comments
Closed

Stargate: no pagination available for Bank/TotalSupply #1057

JGJP opened this issue Feb 22, 2022 · 12 comments
Labels
Question ❓ User question

Comments

@JGJP
Copy link

JGJP commented Feb 22, 2022

I am trying to paginate my call to TotalSupply in stargate's Bank module but it returns the same response whether I pass pagination params or not:

Image 2022-02-16 at 5 43 00 PM

In this screenshot I'm showing what I've done to create my own BankExtension, since stargate's own one does not relay pagination details to the underlying call. I've had success creating my own extensions before, and I've verified that passing a pagination key in this way works when calling Staking/ValidatorDelegations, so it seems that this is purely an issue on the RPC node itself. The response is always the same (maxed out at 100) whether I pass pagination details or not.

The reason I think it's on the RPC side is that stargate's method of calling these endpoints is exactly the same:

Staking/ValidatorDelegations

ValidatorDelegations(request) {
    const data = exports.QueryValidatorDelegationsRequest.encode(request).finish();
    const promise = this.rpc.request("cosmos.staking.v1beta1.Query", "ValidatorDelegations", data);
    return promise.then((data) => exports.QueryValidatorDelegationsResponse.decode(new minimal_1.default.Reader(data)));
}

Bank/TotalSupply

TotalSupply(request) {
    const data = exports.QueryTotalSupplyRequest.encode(request).finish();
    const promise = this.rpc.request("cosmos.bank.v1beta1.Query", "TotalSupply", data);
    return promise.then((data) => exports.QueryTotalSupplyResponse.decode(new minimal_1.default.Reader(data)));
}
@webmaster128
Copy link
Member

Which backend are you connecting to? The pagination field only exists for Cosmos SDK 0.43+. See

// QueryTotalSupplyRequest is the request type for the Query/TotalSupply RPC
// method.
message QueryTotalSupplyRequest {
  option (gogoproto.equal) = false;
  option (gogoproto.goproto_getters) = false;

  // pagination defines an optional pagination for the request.
  //
  // Since: cosmos-sdk 0.43
  cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

@JGJP
Copy link
Author

JGJP commented Feb 24, 2022

@webmaster128 I've confirmed that our node is already on 0.44

@webmaster128
Copy link
Member

okay. Does it work for other values. E.g. what happens if you set a limit of 42?

@JGJP
Copy link
Author

JGJP commented Feb 28, 2022

Same effect, I tried numbers like 10, 20, undefined etc.

@JGJP
Copy link
Author

JGJP commented Feb 28, 2022

Is the node supposed to be able to return total supply paginated? If so, can I see an example of how to make the call with Stargate? I should be able to use it with a public endpoint

@webmaster128
Copy link
Member

Looking at the Cosmos SDK code, the pagination was implemented in Cosmos SDK 0.43. I assume it should work. I don't know more than that. Could you ask the Cosmos SDK team or open a bug report in https://github.com/cosmos/cosmos-sdk?

@JGJP
Copy link
Author

JGJP commented Mar 2, 2022

Well Stargate itself is not listed as supporting 0.43:
https://github.com/cosmos/cosmjs/tree/main/packages/stargate
Is the info incorrect and just in need of updating?

@webmaster128
Copy link
Member

This info is outdatet. The latest 0.27 series supports 0.42-0.45.

@JGJP
Copy link
Author

JGJP commented Mar 9, 2022

The problem was purely client side, but unfortunately Stargate doesn't support specifying any pagination params, here's my custom solution:

import { QueryClient } from "@cosmjs/stargate"
import { Tendermint34Client } from "@cosmjs/tendermint-rpc"
import { QueryClientImpl as BankQueryClientImpl } from "cosmjs-types/cosmos/bank/v1beta1/query"

const setupCustomBankExtension = base => {
    const queryService = new BankQueryClientImpl({
        request: (service, method, data) => {
            const path = `/${service}/${method}`
            return base.queryUnverified(path, data)
        },
    })
    return {
        customBank: {
            totalSupply: async paginationKey => {
                return await queryService.TotalSupply({
                    pagination: {
                        countTotal: false,
                        key: paginationKey,
                        offset: Long.fromNumber(0, true),
                        limit: Long.fromNumber(100, true),
                        reverse: false,
                    } as PageRequest,
                })
            },
        },
    }
}

const tmClient = QueryClient.withExtensions(
    await Tendermint34Client.connect(rpcEndpoint),
    setupCustomBankExtension,
)

const paginationKey = new Uint8Array()
const { supply, pagination } = await tmClient.customBank.totalSupply(paginationKey)

Please thumbs up this or something so people know to use this

@webmaster128
Copy link
Member

but unfortunately Stargate doesn't support specifying any pagination params,

Yeah, true. This is becasue the pagination did not exist in 0.42. We can add it now.

I thought you already did that in your first screenshot.

@JGJP
Copy link
Author

JGJP commented Mar 15, 2022

It looks like I didn't form the pagination object correctly

@webmaster128 webmaster128 added the Question ❓ User question label Mar 15, 2022
@webmaster128
Copy link
Member

webmaster128 commented Mar 15, 2022

Thanks. The implementation is now tracked in #1095.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question ❓ User question
Projects
None yet
Development

No branches or pull requests

2 participants