Make store name for query account configurable

This commit is contained in:
Ethan Frey 2018-02-23 11:07:53 +01:00 committed by rigelrozanski
parent c7ca6ec038
commit 7779eec990
2 changed files with 17 additions and 10 deletions

View File

@ -37,9 +37,13 @@ func main() {
// query/post commands (custom to binary) // query/post commands (custom to binary)
basecliCmd.AddCommand( basecliCmd.AddCommand(
client.GetCommands(bankcmd.GetAccountCmd())...) client.GetCommands(
bankcmd.GetAccountCmd("main"),
)...)
basecliCmd.AddCommand( basecliCmd.AddCommand(
client.PostCommands(bankcmd.SendTxCommand())...) client.PostCommands(
bankcmd.SendTxCommand(),
)...)
// add proxy, version and key info // add proxy, version and key info
basecliCmd.AddCommand( basecliCmd.AddCommand(

View File

@ -19,16 +19,21 @@ import (
// GetAccountCmd returns a query account that will display the // GetAccountCmd returns a query account that will display the
// state of the account at a given address // state of the account at a given address
func GetAccountCmd() *cobra.Command { func GetAccountCmd(storeName string) *cobra.Command {
cmd := &cobra.Command{ cmd := acctCmd{storeName}
return &cobra.Command{
Use: "account <address>", Use: "account <address>",
Short: "Query account balance", Short: "Query account balance",
RunE: getAccount, RunE: cmd.get,
} }
return cmd
} }
func getAccount(cmd *cobra.Command, args []string) error { type acctCmd struct {
storeName string
}
func (a acctCmd) get(cmd *cobra.Command, args []string) error {
if len(args) != 1 || len(args[0]) == 0 { if len(args) != 1 || len(args[0]) == 0 {
return errors.New("You must provide an account name") return errors.New("You must provide an account name")
} }
@ -40,9 +45,7 @@ func getAccount(cmd *cobra.Command, args []string) error {
return err return err
} }
key := crypto.Address(bz) key := crypto.Address(bz)
path := fmt.Sprintf("/%s/key", a.storeName)
// TODO: make the store name a variable in getAccountCmd?
path := "/main/key"
uri := viper.GetString(client.FlagNode) uri := viper.GetString(client.FlagNode)
if uri == "" { if uri == "" {