* A few godoc updates * More minor tweaks and reformatting * Implement initial minting querier * Implement stringer interface for minting params * Minor cleanup * Add minting CLI commands * Implement inflation query command * Implement annual provisions query and CLI command * Update x/mint/client/module_client.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update x/mint/client/module_client.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update x/mint/client/module_client.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update x/mint/querier.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Add minting REST client routes/handlers * Fix build issues * Implement querier unit tests * Update gaiacli docs * Implement LCD tests * Update Swagger docs * Add pending log entry * add examples Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * revert adding examples Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
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
|
|
}
|