2019-11-25 19:46:02 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
2020-04-23 16:35:58 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2019-11-25 19:46:02 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2020-02-02 16:06:33 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-11-25 19:46:02 +00:00
|
|
|
"github.com/spf13/cobra"
|
2020-04-30 14:13:31 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/pricefeed/types"
|
2019-11-25 19:46:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetQueryCmd returns the cli query commands for this module
|
2020-01-17 12:29:19 +00:00
|
|
|
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
2019-11-25 19:46:02 +00:00
|
|
|
// Group nameservice queries under a subcommand
|
|
|
|
pricefeedQueryCmd := &cobra.Command{
|
|
|
|
Use: types.ModuleName,
|
|
|
|
Short: "Querying commands for the pricefeed module",
|
|
|
|
DisableFlagParsing: true,
|
|
|
|
SuggestionsMinimumDistance: 2,
|
|
|
|
RunE: client.ValidateCmd,
|
|
|
|
}
|
|
|
|
|
2020-04-23 16:35:58 +00:00
|
|
|
pricefeedQueryCmd.AddCommand(flags.GetCommands(
|
2020-02-02 16:06:33 +00:00
|
|
|
GetCmdPrice(queryRoute, cdc),
|
2020-01-17 12:29:19 +00:00
|
|
|
GetCmdRawPrices(queryRoute, cdc),
|
2020-02-02 16:06:33 +00:00
|
|
|
GetCmdOracles(queryRoute, cdc),
|
2020-01-17 12:29:19 +00:00
|
|
|
GetCmdMarkets(queryRoute, cdc),
|
2020-01-17 12:55:17 +00:00
|
|
|
GetCmdQueryParams(queryRoute, cdc),
|
2019-11-25 19:46:02 +00:00
|
|
|
)...)
|
|
|
|
|
|
|
|
return pricefeedQueryCmd
|
|
|
|
}
|
|
|
|
|
2020-02-02 16:06:33 +00:00
|
|
|
// GetCmdOracles queries the oracle set of an asset
|
|
|
|
func GetCmdOracles(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "oracles [marketID]",
|
|
|
|
Short: "get the oracle set for a market",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
marketID := args[0]
|
|
|
|
|
|
|
|
bz, err := cdc.MarshalJSON(types.QueryWithMarketIDParams{
|
|
|
|
MarketID: marketID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryOracles)
|
|
|
|
|
|
|
|
res, _, err := cliCtx.QueryWithData(route, bz)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var oracles []sdk.AccAddress
|
|
|
|
cdc.MustUnmarshalJSON(res, &oracles)
|
|
|
|
return cliCtx.PrintOutput(oracles)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCmdPrice queries the current price of an asset
|
|
|
|
func GetCmdPrice(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
2019-11-25 19:46:02 +00:00
|
|
|
return &cobra.Command{
|
2020-01-17 12:29:19 +00:00
|
|
|
Use: "price [marketID]",
|
|
|
|
Short: "get the current price for the input market",
|
2019-11-25 19:46:02 +00:00
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
2020-01-17 12:29:19 +00:00
|
|
|
marketID := args[0]
|
|
|
|
|
2020-02-02 16:06:33 +00:00
|
|
|
bz, err := cdc.MarshalJSON(types.QueryWithMarketIDParams{
|
2020-01-17 12:29:19 +00:00
|
|
|
MarketID: marketID,
|
|
|
|
})
|
2019-11-25 19:46:02 +00:00
|
|
|
if err != nil {
|
2020-01-17 12:29:19 +00:00
|
|
|
return err
|
2019-11-25 19:46:02 +00:00
|
|
|
}
|
2020-02-02 16:06:33 +00:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryPrice)
|
2020-01-17 12:29:19 +00:00
|
|
|
|
|
|
|
res, _, err := cliCtx.QueryWithData(route, bz)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var price types.CurrentPrice
|
|
|
|
cdc.MustUnmarshalJSON(res, &price)
|
|
|
|
return cliCtx.PrintOutput(price)
|
2019-11-25 19:46:02 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCmdRawPrices queries the current price of an asset
|
|
|
|
func GetCmdRawPrices(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
2020-01-17 12:29:19 +00:00
|
|
|
Use: "rawprices [marketID]",
|
|
|
|
Short: "get the raw oracle prices for the input market",
|
2019-11-25 19:46:02 +00:00
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
2020-01-17 12:29:19 +00:00
|
|
|
marketID := args[0]
|
|
|
|
|
2020-02-02 16:06:33 +00:00
|
|
|
bz, err := cdc.MarshalJSON(types.QueryWithMarketIDParams{
|
2020-01-17 12:29:19 +00:00
|
|
|
MarketID: marketID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryRawPrices)
|
|
|
|
|
|
|
|
res, _, err := cliCtx.QueryWithData(route, bz)
|
|
|
|
|
2019-11-25 19:46:02 +00:00
|
|
|
if err != nil {
|
2020-01-17 12:29:19 +00:00
|
|
|
return err
|
2019-11-25 19:46:02 +00:00
|
|
|
}
|
2020-01-17 12:29:19 +00:00
|
|
|
var prices []types.PostedPrice
|
|
|
|
cdc.MustUnmarshalJSON(res, &prices)
|
|
|
|
return cliCtx.PrintOutput(prices)
|
2019-11-25 19:46:02 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-17 12:29:19 +00:00
|
|
|
// GetCmdMarkets queries list of markets in the pricefeed
|
|
|
|
func GetCmdMarkets(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
2019-11-25 19:46:02 +00:00
|
|
|
return &cobra.Command{
|
2020-01-17 12:29:19 +00:00
|
|
|
Use: "markets",
|
|
|
|
Short: "get the markets in the pricefeed",
|
2019-11-25 19:46:02 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
2020-01-17 12:29:19 +00:00
|
|
|
route := fmt.Sprintf("custom/%s/markets", queryRoute)
|
|
|
|
res, _, err := cliCtx.QueryWithData(route, nil)
|
2019-11-25 19:46:02 +00:00
|
|
|
if err != nil {
|
2020-01-17 12:29:19 +00:00
|
|
|
return err
|
2019-11-25 19:46:02 +00:00
|
|
|
}
|
2020-01-17 12:29:19 +00:00
|
|
|
var markets types.Markets
|
|
|
|
cdc.MustUnmarshalJSON(res, &markets)
|
|
|
|
return cliCtx.PrintOutput(markets)
|
2019-11-25 19:46:02 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-01-17 12:55:17 +00:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|