69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
|
package mint
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/cosmos/cosmos-sdk/codec"
|
||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||
|
abci "github.com/tendermint/tendermint/abci/types"
|
||
|
)
|
||
|
|
||
|
// Query endpoints supported by the minting querier
|
||
|
const (
|
||
|
QueryParameters = "parameters"
|
||
|
QueryInflation = "inflation"
|
||
|
QueryAnnualProvisions = "annual_provisions"
|
||
|
)
|
||
|
|
||
|
// NewQuerier returns a minting Querier handler.
|
||
|
func NewQuerier(k Keeper) sdk.Querier {
|
||
|
return func(ctx sdk.Context, path []string, _ abci.RequestQuery) ([]byte, sdk.Error) {
|
||
|
switch path[0] {
|
||
|
case QueryParameters:
|
||
|
return queryParams(ctx, k)
|
||
|
|
||
|
case QueryInflation:
|
||
|
return queryInflation(ctx, k)
|
||
|
|
||
|
case QueryAnnualProvisions:
|
||
|
return queryAnnualProvisions(ctx, k)
|
||
|
|
||
|
default:
|
||
|
return nil, sdk.ErrUnknownRequest(fmt.Sprintf("unknown minting query endpoint: %s", path[0]))
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func queryParams(ctx sdk.Context, k Keeper) ([]byte, sdk.Error) {
|
||
|
params := k.GetParams(ctx)
|
||
|
|
||
|
res, err := codec.MarshalJSONIndent(k.cdc, params)
|
||
|
if err != nil {
|
||
|
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to marshal JSON", err.Error()))
|
||
|
}
|
||
|
|
||
|
return res, nil
|
||
|
}
|
||
|
|
||
|
func queryInflation(ctx sdk.Context, k Keeper) ([]byte, sdk.Error) {
|
||
|
minter := k.GetMinter(ctx)
|
||
|
|
||
|
res, err := codec.MarshalJSONIndent(k.cdc, minter.Inflation)
|
||
|
if err != nil {
|
||
|
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to marshal JSON", err.Error()))
|
||
|
}
|
||
|
|
||
|
return res, nil
|
||
|
}
|
||
|
|
||
|
func queryAnnualProvisions(ctx sdk.Context, k Keeper) ([]byte, sdk.Error) {
|
||
|
minter := k.GetMinter(ctx)
|
||
|
|
||
|
res, err := codec.MarshalJSONIndent(k.cdc, minter.AnnualProvisions)
|
||
|
if err != nil {
|
||
|
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to marshal JSON", err.Error()))
|
||
|
}
|
||
|
|
||
|
return res, nil
|
||
|
}
|