From 9429659ed4df3fe05f0305f19b4b167e0b452363 Mon Sep 17 00:00:00 2001 From: huichiaotsou Date: Wed, 25 May 2022 11:48:19 +0800 Subject: [PATCH 1/2] save all query results(all pages) from total supply query --- modules/bank/source/local/source.go | 27 ++++++++++++++++++++++----- modules/bank/source/remote/source.go | 27 +++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/modules/bank/source/local/source.go b/modules/bank/source/local/source.go index 688b7b716..7fc4df934 100644 --- a/modules/bank/source/local/source.go +++ b/modules/bank/source/local/source.go @@ -3,6 +3,7 @@ package local import ( "fmt" + "github.com/cosmos/cosmos-sdk/types/query" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -50,19 +51,35 @@ func (s Source) GetBalances(addresses []string, height int64) ([]types.AccountBa return balances, nil } -// GetSupply implements keeper.Source +// GetSupply implements bankkeeper.Source func (s Source) GetSupply(height int64) (sdk.Coins, error) { ctx, err := s.LoadHeight(height) if err != nil { return nil, fmt.Errorf("error while loading height: %s", err) } - res, err := s.q.TotalSupply(sdk.WrapSDKContext(ctx), &banktypes.QueryTotalSupplyRequest{}) - if err != nil { - return nil, err + var coins []sdk.Coin + var nextKey []byte + var stop = false + for !stop { + res, err := s.q.TotalSupply( + sdk.WrapSDKContext(ctx), + &banktypes.QueryTotalSupplyRequest{ + Pagination: &query.PageRequest{ + Key: nextKey, + Limit: 100, // Query 100 supplies at time + }, + }) + if err != nil { + return nil, fmt.Errorf("error while getting total supply: %s", err) + } + + nextKey = res.Pagination.NextKey + stop = len(res.Pagination.NextKey) == 0 + coins = append(coins, res.Supply...) } - return res.Supply, nil + return coins, nil } // GetAccountBalances implements bankkeeper.Source diff --git a/modules/bank/source/remote/source.go b/modules/bank/source/remote/source.go index 57f2fb94e..07aef412e 100644 --- a/modules/bank/source/remote/source.go +++ b/modules/bank/source/remote/source.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/forbole/juno/v3/node/remote" @@ -51,10 +52,28 @@ func (s Source) GetBalances(addresses []string, height int64) ([]types.AccountBa // GetSupply implements bankkeeper.Source func (s Source) GetSupply(height int64) (sdk.Coins, error) { - res, err := s.bankClient.TotalSupply(remote.GetHeightRequestContext(s.Ctx, height), &banktypes.QueryTotalSupplyRequest{}) - if err != nil { - return nil, fmt.Errorf("error while getting total supply: %s", err) + ctx := remote.GetHeightRequestContext(s.Ctx, height) + + var coins []sdk.Coin + var nextKey []byte + var stop = false + for !stop { + res, err := s.bankClient.TotalSupply( + ctx, + &banktypes.QueryTotalSupplyRequest{ + Pagination: &query.PageRequest{ + Key: nextKey, + Limit: 100, // Query 100 supplies at time + }, + }) + if err != nil { + return nil, fmt.Errorf("error while getting total supply: %s", err) + } + + nextKey = res.Pagination.NextKey + stop = len(res.Pagination.NextKey) == 0 + coins = append(coins, res.Supply...) } - return res.Supply, nil + return coins, nil } From 31458d68fd68ed8ee6246f3758f003b1fe1638cf Mon Sep 17 00:00:00 2001 From: huichiaotsou Date: Wed, 25 May 2022 11:52:13 +0800 Subject: [PATCH 2/2] add change log --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 723f442af..1aceef327 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ #### Hasura - ([\#395](https://github.com/forbole/bdjuno/pull/395)) Remove time label from Hasura Prometheus monitoring +#### Bank module +- ([\#410](https://github.com/forbole/bdjuno/pull/410)) Change total supply query from only 1 page to all pages ## Version v3.0.1 ### Dependencies