mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 08:15:19 +00:00
a573625df8
* bump SDK version to v0.38.3 Co-authored-by: Denali Marsh <denali@kava.io> Co-authored-by: Kevin Davis <kjydavis3@gmail.com> Co-authored-by: Kevin Davis <karzak@users.noreply.github.com> Co-authored-by: denalimarsh <denalimarsh@gmail.com> Co-authored-by: rhuairahrighairigh <ruaridh.odonnell@gmail.com>
66 lines
2.3 KiB
Go
66 lines
2.3 KiB
Go
package keeper
|
|
|
|
import (
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
|
|
|
"github.com/kava-labs/kava/x/validator-vesting/types"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
)
|
|
|
|
// NewQuerier returns a new querier function
|
|
func NewQuerier(keeper Keeper) sdk.Querier {
|
|
return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err error) {
|
|
switch path[0] {
|
|
case types.QueryCirculatingSupply:
|
|
return queryGetCirculatingSupply(ctx, req, keeper)
|
|
case types.QueryTotalSupply:
|
|
return queryGetTotalSupply(ctx, req, keeper)
|
|
default:
|
|
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0])
|
|
}
|
|
}
|
|
}
|
|
|
|
func queryGetTotalSupply(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) ([]byte, error) {
|
|
totalSupply := keeper.supplyKeeper.GetSupply(ctx).GetTotal().AmountOf("ukava")
|
|
supplyInt := sdk.NewDecFromInt(totalSupply).Mul(sdk.MustNewDecFromStr("0.000001")).TruncateInt64()
|
|
bz, err := types.ModuleCdc.MarshalJSON(supplyInt)
|
|
if err != nil {
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
|
|
}
|
|
return bz, nil
|
|
}
|
|
|
|
func queryGetCirculatingSupply(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) ([]byte, error) {
|
|
circulatingSupply := keeper.supplyKeeper.GetSupply(ctx).GetTotal().AmountOf("ukava")
|
|
keeper.ak.IterateAccounts(ctx,
|
|
func(acc authexported.Account) (stop bool) {
|
|
|
|
// validator vesting account
|
|
vvacc, ok := acc.(*types.ValidatorVestingAccount)
|
|
if ok {
|
|
vestedBalance := vvacc.GetVestingCoins(ctx.BlockTime()).AmountOf("ukava")
|
|
circulatingSupply = circulatingSupply.Sub(vestedBalance)
|
|
return false
|
|
}
|
|
// periodic vesting account
|
|
pvacc, ok := acc.(*vesting.PeriodicVestingAccount)
|
|
if ok {
|
|
vestedBalance := pvacc.GetVestingCoins(ctx.BlockTime()).AmountOf("ukava")
|
|
circulatingSupply = circulatingSupply.Sub(vestedBalance)
|
|
return false
|
|
}
|
|
return false
|
|
})
|
|
supplyInt := sdk.NewDecFromInt(circulatingSupply).Mul(sdk.MustNewDecFromStr("0.000001")).TruncateInt64()
|
|
bz, err := types.ModuleCdc.MarshalJSON(supplyInt)
|
|
if err != nil {
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
|
|
}
|
|
return bz, nil
|
|
}
|