From a40deb2dbbe5e7532cfe654ae1b2f428a4c09f81 Mon Sep 17 00:00:00 2001 From: Roshan Date: Wed, 1 Feb 2023 17:31:50 +0800 Subject: [PATCH] fix: update balance query rpc method --- server/jsonrpc/backend/account_info.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/server/jsonrpc/backend/account_info.go b/server/jsonrpc/backend/account_info.go index 5070a8b0e5..18b558da40 100644 --- a/server/jsonrpc/backend/account_info.go +++ b/server/jsonrpc/backend/account_info.go @@ -8,6 +8,7 @@ import ( rpctypes "github.com/evmos/ethermint/rpc/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) func (b *Backend) GetBalance(address common.Address, blockNrOrHash rpctypes.BlockNumberOrHash) (*hexutil.Big, error) { @@ -21,16 +22,23 @@ func (b *Backend) GetBalance(address common.Address, blockNrOrHash rpctypes.Bloc return nil, err } - req := &banktypes.QueryBalanceRequest{ - Address: address.String(), - Denom: "BNB", + paramsReq := stakingtypes.QueryParamsRequest{} + queryStakingClient := stakingtypes.NewQueryClient(b.clientCtx) + + paramsRes, err := queryStakingClient.Params(b.ctx, ¶msReq) + if err != nil { + return (*hexutil.Big)(big.NewInt(0)), err } - queryClient := banktypes.NewQueryClient(b.clientCtx) - res, err := queryClient.Balance(b.ctx, req) + balanceReq := banktypes.QueryBalanceRequest{ + Address: address.String(), + Denom: paramsRes.Params.BondDenom, + } + queryBankClient := banktypes.NewQueryClient(b.clientCtx) + balanceRes, err := queryBankClient.Balance(b.ctx, &balanceReq) if err != nil { return (*hexutil.Big)(big.NewInt(0)), err } - return (*hexutil.Big)(res.Balance.Amount.BigInt()), nil + return (*hexutil.Big)(balanceRes.Balance.Amount.BigInt()), nil }