diff --git a/x/pricefeed/client/cli/query.go b/x/pricefeed/client/cli/query.go index 0100a373..5ad41c41 100644 --- a/x/pricefeed/client/cli/query.go +++ b/x/pricefeed/client/cli/query.go @@ -25,6 +25,7 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { GetCmdCurrentPrice(queryRoute, cdc), GetCmdRawPrices(queryRoute, cdc), GetCmdMarkets(queryRoute, cdc), + GetCmdQueryParams(queryRoute, cdc), )...) return pricefeedQueryCmd @@ -107,3 +108,28 @@ func GetCmdMarkets(queryRoute string, cdc *codec.Codec) *cobra.Command { }, } } + +// GetCmdQueryParams queries the pricefeed module parameters +func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command { + return &cobra.Command{ + Use: "params", + Short: "get the pricefeed module parameters", + Long: "Get the current global pricefeed module parameters.", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + cliCtx := context.NewCLIContext().WithCodec(cdc) + + // Query + route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetParams) + res, _, err := cliCtx.QueryWithData(route, nil) + if err != nil { + return err + } + + // Decode and print results + var out types.Params + cdc.MustUnmarshalJSON(res, &out) + return cliCtx.PrintOutput(out) + }, + } +} diff --git a/x/pricefeed/client/cli/tx.go b/x/pricefeed/client/cli/tx.go index 1793e59c..0b46a6af 100644 --- a/x/pricefeed/client/cli/tx.go +++ b/x/pricefeed/client/cli/tx.go @@ -42,9 +42,7 @@ func GetCmdPostPrice(cdc *codec.Codec) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc)) - // if err := cliCtx.EnsureAccountExists(); err != nil { - // return err - // } + price, err := sdk.NewDecFromStr(args[1]) if err != nil { return err diff --git a/x/pricefeed/client/rest/query.go b/x/pricefeed/client/rest/query.go index 30b2af46..9ff29431 100644 --- a/x/pricefeed/client/rest/query.go +++ b/x/pricefeed/client/rest/query.go @@ -17,6 +17,7 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) { r.HandleFunc(fmt.Sprintf("/%s/rawprices/{%s}", types.ModuleName, restName), queryRawPricesHandler(cliCtx)).Methods("GET") r.HandleFunc(fmt.Sprintf("/%s/currentprice/{%s}", types.ModuleName, restName), queryCurrentPriceHandler(cliCtx)).Methods("GET") r.HandleFunc(fmt.Sprintf("/%s/markets", types.ModuleName), queryMarketsHandler(cliCtx)).Methods("GET") + r.HandleFunc(fmt.Sprintf("/%s/params", types.ModuleName), queryParamsHandlerFn(cliCtx)).Methods("GET") } func queryRawPricesHandler(cliCtx context.CLIContext) http.HandlerFunc { @@ -55,3 +56,17 @@ func queryMarketsHandler(cliCtx context.CLIContext) http.HandlerFunc { rest.PostProcessResponse(w, cliCtx, res) } } + +func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + // Get the params + res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/pricefeed/%s", types.QueryGetParams), nil) + cliCtx = cliCtx.WithHeight(height) + if err != nil { + rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) + return + } + // Return the params + rest.PostProcessResponse(w, cliCtx, res) + } +} diff --git a/x/pricefeed/keeper/querier.go b/x/pricefeed/keeper/querier.go index 7952e688..6ea20a63 100644 --- a/x/pricefeed/keeper/querier.go +++ b/x/pricefeed/keeper/querier.go @@ -21,6 +21,8 @@ func NewQuerier(keeper Keeper) sdk.Querier { return queryRawPrices(ctx, req, keeper) case types.QueryMarkets: return queryMarkets(ctx, req, keeper) + case types.QueryGetParams: + return queryGetParams(ctx, req, keeper) default: return nil, sdk.ErrUnknownRequest("unknown pricefeed query endpoint") } @@ -80,3 +82,16 @@ func queryMarkets(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) (res [] return bz, nil } + +// query params in the auction store +func queryGetParams(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) ([]byte, sdk.Error) { + // Get params + params := keeper.GetParams(ctx) + + // Encode results + bz, err := codec.MarshalJSONIndent(keeper.cdc, params) + if err != nil { + return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err.Error())) + } + return bz, nil +} diff --git a/x/pricefeed/types/codec.go b/x/pricefeed/types/codec.go index cd0437e3..e651c17c 100644 --- a/x/pricefeed/types/codec.go +++ b/x/pricefeed/types/codec.go @@ -10,7 +10,7 @@ func init() { RegisterCodec(ModuleCdc) } -// RegisterCode registers concrete types on the Amino code +// RegisterCodec registers concrete types on the Amino code func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgPostPrice{}, "pricefeed/MsgPostPrice", nil) } diff --git a/x/pricefeed/types/errors.go b/x/pricefeed/types/errors.go index 325b0c1b..6d545f02 100644 --- a/x/pricefeed/types/errors.go +++ b/x/pricefeed/types/errors.go @@ -37,7 +37,7 @@ func ErrNoValidPrice(codespace sdk.CodespaceType) sdk.Error { return sdk.NewError(codespace, CodeInvalidPrice, fmt.Sprintf("All input prices are expired.")) } -// ErrInvalidAsset Error constructor for posted price messages for invalid markets +// ErrInvalidMarket Error constructor for posted price messages for invalid markets func ErrInvalidMarket(codespace sdk.CodespaceType, marketId string) sdk.Error { return sdk.NewError(codespace, CodeInvalidAsset, fmt.Sprintf("market %s does not exist", marketId)) } diff --git a/x/pricefeed/types/msgs_test.go b/x/pricefeed/types/msgs_test.go index fe139969..74192420 100644 --- a/x/pricefeed/types/msgs_test.go +++ b/x/pricefeed/types/msgs_test.go @@ -10,9 +10,6 @@ import ( func TestMsgPlaceBid_ValidateBasic(t *testing.T) { addr := sdk.AccAddress([]byte("someName")) - // oracles := []Oracle{Oracle{ - // OracleAddress: addr.String(), - // }} price, _ := sdk.NewDecFromStr("0.3005") expiry := tmtime.Now() negativePrice, _ := sdk.NewDecFromStr("-3.05") diff --git a/x/pricefeed/types/querier.go b/x/pricefeed/types/querier.go index 074a1ee4..8e5e1912 100644 --- a/x/pricefeed/types/querier.go +++ b/x/pricefeed/types/querier.go @@ -11,6 +11,8 @@ const ( QueryRawPrices = "rawprices" // QueryMarkets command for assets query QueryMarkets = "markets" + // QueryGetParams command for params query + QueryGetParams = "params" ) // QueryPricesParams fields for querying prices