cosmos-sdk/x/auth/client/cli/query.go
2019-06-05 19:26:16 -04:00

58 lines
1.5 KiB
Go

package cli
import (
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)
// GetTxCmd returns the transaction commands for this module
func GetQueryCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the auth module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: utils.ValidateCmd,
}
cmd.AddCommand(GetAccountCmd(cdc))
return cmd
}
// GetAccountCmd returns a query account that will display the state of the
// account at a given address.
// nolint: unparam
func GetAccountCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "account [address]",
Short: "Query account balance",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().
WithCodec(cdc).WithAccountDecoder(cdc)
key, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}
if err = cliCtx.EnsureAccountExistsFromAddr(key); err != nil {
return err
}
acc, err := cliCtx.GetAccount(key)
if err != nil {
return err
}
return cliCtx.PrintOutput(acc)
},
}
return flags.GetCommands(cmd)[0]
}