0g-chain/x/precisebank/keeper/grpc_query.go
drklee3 3853e276a6
feat(x/precisebank): Add query service with TotalFractionalBalances (#1970)
Add query service to precisebank, mostly for e2e test purposes in #1966
Also fix client grpc codec
2024-07-19 10:24:23 -07:00

39 lines
1.0 KiB
Go

package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/x/precisebank/types"
)
type queryServer struct {
keeper Keeper
}
// NewQueryServerImpl creates a new server for handling gRPC queries.
func NewQueryServerImpl(k Keeper) types.QueryServer {
return &queryServer{keeper: k}
}
var _ types.QueryServer = queryServer{}
// TotalFractionalBalances returns the total sum of all fractional balances.
// This is mostly for external verification of the total fractional balances,
// being a multiple of the conversion factor and backed by the reserve.
func (s queryServer) TotalFractionalBalances(
goCtx context.Context,
req *types.QueryTotalFractionalBalancesRequest,
) (*types.QueryTotalFractionalBalancesResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
totalAmount := s.keeper.GetTotalSumFractionalBalances(ctx)
totalCoin := sdk.NewCoin(types.ExtendedCoinDenom, totalAmount)
return &types.QueryTotalFractionalBalancesResponse{
Total: totalCoin,
}, nil
}