update cmds

This commit is contained in:
rhuairahrighairigh 2019-07-18 19:05:26 +01:00
parent d73cfc7167
commit cfbd4e92aa
2 changed files with 54 additions and 77 deletions

View File

@ -5,8 +5,6 @@ import (
"os" "os"
"path" "path"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -17,32 +15,15 @@ import (
"github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/lcd" "github.com/cosmos/cosmos-sdk/client/lcd"
"github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/version"
"github.com/kava-labs/kava/app" "github.com/cosmos/cosmos-sdk/x/auth"
at "github.com/cosmos/cosmos-sdk/x/auth"
auth "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
bank "github.com/cosmos/cosmos-sdk/x/bank/client/rest"
dist "github.com/cosmos/cosmos-sdk/x/distribution/client/rest"
gv "github.com/cosmos/cosmos-sdk/x/gov"
gov "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
mintrest "github.com/cosmos/cosmos-sdk/x/mint/client/rest"
sl "github.com/cosmos/cosmos-sdk/x/slashing"
slashing "github.com/cosmos/cosmos-sdk/x/slashing/client/rest"
st "github.com/cosmos/cosmos-sdk/x/staking"
staking "github.com/cosmos/cosmos-sdk/x/staking/client/rest"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
"github.com/cosmos/cosmos-sdk/x/bank"
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
crisisclient "github.com/cosmos/cosmos-sdk/x/crisis/client"
distcmd "github.com/cosmos/cosmos-sdk/x/distribution" "github.com/kava-labs/kava/app"
distClient "github.com/cosmos/cosmos-sdk/x/distribution/client"
govClient "github.com/cosmos/cosmos-sdk/x/gov/client"
mintclient "github.com/cosmos/cosmos-sdk/x/mint/client"
slashingclient "github.com/cosmos/cosmos-sdk/x/slashing/client"
stakingclient "github.com/cosmos/cosmos-sdk/x/staking/client"
) )
func main() { func main() {
@ -61,17 +42,6 @@ func main() {
// the below functions and eliminate global vars, like we do // the below functions and eliminate global vars, like we do
// with the cdc // with the cdc
// Module clients hold cli commnads (tx,query) and lcd routes
// TODO: Make the lcd command take a list of ModuleClient
mc := []sdk.ModuleClients{
govClient.NewModuleClient(gv.StoreKey, cdc),
distClient.NewModuleClient(distcmd.StoreKey, cdc),
stakingclient.NewModuleClient(st.StoreKey, cdc),
mintclient.NewModuleClient(mint.StoreKey, cdc),
slashingclient.NewModuleClient(sl.StoreKey, cdc),
crisisclient.NewModuleClient(sl.StoreKey, cdc),
}
rootCmd := &cobra.Command{ rootCmd := &cobra.Command{
Use: "kvcli", Use: "kvcli",
Short: "Command line interface for interacting with kvd", Short: "Command line interface for interacting with kvd",
@ -87,19 +57,19 @@ func main() {
rootCmd.AddCommand( rootCmd.AddCommand(
rpc.StatusCommand(), rpc.StatusCommand(),
client.ConfigCmd(app.DefaultCLIHome), client.ConfigCmd(app.DefaultCLIHome),
queryCmd(cdc, mc), queryCmd(cdc),
txCmd(cdc, mc), txCmd(cdc),
client.LineBreak, client.LineBreak,
lcd.ServeCommand(cdc, registerRoutes), lcd.ServeCommand(cdc, registerRoutes),
client.LineBreak, client.LineBreak,
keys.Commands(), keys.Commands(),
client.LineBreak, client.LineBreak,
version.VersionCmd, version.Cmd,
client.NewCompletionCmd(rootCmd, true), client.NewCompletionCmd(rootCmd, true),
) )
// Add flags and prefix all env exposed with GA // Add flags and prefix all env exposed with GA
executor := cli.PrepareMainCmd(rootCmd, "GA", app.DefaultCLIHome) executor := cli.PrepareMainCmd(rootCmd, "KA", app.DefaultCLIHome)
err := executor.Execute() err := executor.Execute()
if err != nil { if err != nil {
@ -108,7 +78,7 @@ func main() {
} }
} }
func queryCmd(cdc *amino.Codec, mc []sdk.ModuleClients) *cobra.Command { func queryCmd(cdc *amino.Codec) *cobra.Command {
queryCmd := &cobra.Command{ queryCmd := &cobra.Command{
Use: "query", Use: "query",
Aliases: []string{"q"}, Aliases: []string{"q"},
@ -116,25 +86,22 @@ func queryCmd(cdc *amino.Codec, mc []sdk.ModuleClients) *cobra.Command {
} }
queryCmd.AddCommand( queryCmd.AddCommand(
authcmd.GetAccountCmd(cdc),
client.LineBreak,
rpc.ValidatorCommand(cdc), rpc.ValidatorCommand(cdc),
rpc.BlockCommand(), rpc.BlockCommand(),
tx.SearchTxCmd(cdc), authcmd.QueryTxsByEventsCmd(cdc),
tx.QueryTxCmd(cdc), authcmd.QueryTxCmd(cdc),
client.LineBreak, client.LineBreak,
authcmd.GetAccountCmd(at.StoreKey, cdc),
) )
for _, m := range mc { // add modules' query commands
mQueryCmd := m.GetQueryCmd() app.ModuleBasics.AddQueryCommands(queryCmd, cdc)
if mQueryCmd != nil {
queryCmd.AddCommand(mQueryCmd)
}
}
return queryCmd return queryCmd
} }
func txCmd(cdc *amino.Codec, mc []sdk.ModuleClients) *cobra.Command { func txCmd(cdc *amino.Codec) *cobra.Command {
txCmd := &cobra.Command{ txCmd := &cobra.Command{
Use: "tx", Use: "tx",
Short: "Transactions subcommands", Short: "Transactions subcommands",
@ -145,31 +112,35 @@ func txCmd(cdc *amino.Codec, mc []sdk.ModuleClients) *cobra.Command {
client.LineBreak, client.LineBreak,
authcmd.GetSignCommand(cdc), authcmd.GetSignCommand(cdc),
authcmd.GetMultiSignCommand(cdc), authcmd.GetMultiSignCommand(cdc),
tx.GetBroadcastCommand(cdc), client.LineBreak,
tx.GetEncodeCommand(cdc), authcmd.GetBroadcastCommand(cdc),
authcmd.GetEncodeCommand(cdc),
client.LineBreak, client.LineBreak,
) )
for _, m := range mc { // add modules' tx commands
txCmd.AddCommand(m.GetTxCmd()) app.ModuleBasics.AddTxCommands(txCmd, cdc)
// remove auth and bank commands as they're mounted under the root tx command
var cmdsToRemove []*cobra.Command
for _, cmd := range txCmd.Commands() {
if cmd.Use == auth.ModuleName || cmd.Use == bank.ModuleName {
cmdsToRemove = append(cmdsToRemove, cmd)
} }
}
txCmd.RemoveCommand(cmdsToRemove...)
return txCmd return txCmd
} }
// TODO description still valid?
// registerRoutes registers the routes from the different modules for the LCD. // registerRoutes registers the routes from the different modules for the LCD.
// NOTE: details on the routes added for each module are in the module documentation // NOTE: details on the routes added for each module are in the module documentation
// NOTE: If making updates here you also need to update the test helper in client/lcd/test_helper.go // NOTE: If making updates here you also need to update the test helper in client/lcd/test_helper.go
func registerRoutes(rs *lcd.RestServer) { func registerRoutes(rs *lcd.RestServer) {
rpc.RegisterRoutes(rs.CliCtx, rs.Mux) client.RegisterRoutes(rs.CliCtx, rs.Mux)
tx.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc) authrest.RegisterTxRoutes(rs.CliCtx, rs.Mux)
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, at.StoreKey) app.ModuleBasics.RegisterRESTRoutes(rs.CliCtx, rs.Mux)
bank.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
dist.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, distcmd.StoreKey)
staking.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
slashing.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
gov.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
mintrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
} }
func initConfig(cmd *cobra.Command) error { func initConfig(cmd *cobra.Command) error {

View File

@ -18,8 +18,13 @@ import (
"github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/store" "github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/genaccounts"
genaccscli "github.com/cosmos/cosmos-sdk/x/genaccounts/client/cli"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/kava-labs/kava/app" "github.com/kava-labs/kava/app"
initPkg "github.com/kava-labs/kava/init"
) )
// kvd custom flags // kvd custom flags
@ -42,23 +47,23 @@ func main() {
PersistentPreRunE: server.PersistentPreRunEFn(ctx), PersistentPreRunE: server.PersistentPreRunEFn(ctx),
} }
rootCmd.AddCommand(initPkg.InitCmd(ctx, cdc)) rootCmd.AddCommand(genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome))
rootCmd.AddCommand(initPkg.CollectGenTxsCmd(ctx, cdc)) rootCmd.AddCommand(genutilcli.CollectGenTxsCmd(ctx, cdc, genaccounts.AppModuleBasic{}, app.DefaultNodeHome))
rootCmd.AddCommand(initPkg.TestnetFilesCmd(ctx, cdc)) rootCmd.AddCommand(genutilcli.MigrateGenesisCmd(ctx, cdc))
rootCmd.AddCommand(initPkg.GenTxCmd(ctx, cdc)) rootCmd.AddCommand(genutilcli.GenTxCmd(ctx, cdc, app.ModuleBasics, staking.AppModuleBasic{},
rootCmd.AddCommand(initPkg.AddGenesisAccountCmd(ctx, cdc)) genaccounts.AppModuleBasic{}, app.DefaultNodeHome, app.DefaultCLIHome))
rootCmd.AddCommand(initPkg.ValidateGenesisCmd(ctx, cdc)) rootCmd.AddCommand(genutilcli.ValidateGenesisCmd(ctx, cdc, app.ModuleBasics))
rootCmd.AddCommand(genaccscli.AddGenesisAccountCmd(ctx, cdc, app.DefaultNodeHome, app.DefaultCLIHome))
rootCmd.AddCommand(client.NewCompletionCmd(rootCmd, true)) rootCmd.AddCommand(client.NewCompletionCmd(rootCmd, true))
server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators) server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)
// prepare and add flags // prepare and add flags
executor := cli.PrepareBaseCmd(rootCmd, "GA", app.DefaultNodeHome) executor := cli.PrepareBaseCmd(rootCmd, "KA", app.DefaultNodeHome)
rootCmd.PersistentFlags().UintVar(&invCheckPeriod, flagInvCheckPeriod, rootCmd.PersistentFlags().UintVar(&invCheckPeriod, flagInvCheckPeriod,
0, "Assert registered invariants every N blocks") 0, "Assert registered invariants every N blocks")
err := executor.Execute() err := executor.Execute()
if err != nil { if err != nil {
// handle with #870
panic(err) panic(err)
} }
} }
@ -68,6 +73,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application
logger, db, traceStore, true, invCheckPeriod, logger, db, traceStore, true, invCheckPeriod,
baseapp.SetPruning(store.NewPruningOptionsFromString(viper.GetString("pruning"))), baseapp.SetPruning(store.NewPruningOptionsFromString(viper.GetString("pruning"))),
baseapp.SetMinGasPrices(viper.GetString(server.FlagMinGasPrices)), baseapp.SetMinGasPrices(viper.GetString(server.FlagMinGasPrices)),
baseapp.SetHaltHeight(uint64(viper.GetInt(server.FlagHaltHeight))),
) )
} }
@ -76,13 +82,13 @@ func exportAppStateAndTMValidators(
) (json.RawMessage, []tmtypes.GenesisValidator, error) { ) (json.RawMessage, []tmtypes.GenesisValidator, error) {
if height != -1 { if height != -1 {
gApp := app.NewApp(logger, db, traceStore, false, uint(1)) tempApp := app.NewApp(logger, db, traceStore, false, uint(1))
err := gApp.LoadHeight(height) err := tempApp.LoadHeight(height)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
return gApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList) return tempApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
} }
gApp := app.NewApp(logger, db, traceStore, true, uint(1)) tempApp := app.NewApp(logger, db, traceStore, true, uint(1))
return gApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList) return tempApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
} }