From 7779eec990a690502c3007e2480607994e13064a Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 23 Feb 2018 11:07:53 +0100 Subject: [PATCH] Make store name for query account configurable --- examples/basecoin/cmd/basecli/main.go | 8 ++++++-- x/bank/commands/account.go | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/examples/basecoin/cmd/basecli/main.go b/examples/basecoin/cmd/basecli/main.go index f12dc8c65..8dbdad04d 100644 --- a/examples/basecoin/cmd/basecli/main.go +++ b/examples/basecoin/cmd/basecli/main.go @@ -37,9 +37,13 @@ func main() { // query/post commands (custom to binary) basecliCmd.AddCommand( - client.GetCommands(bankcmd.GetAccountCmd())...) + client.GetCommands( + bankcmd.GetAccountCmd("main"), + )...) basecliCmd.AddCommand( - client.PostCommands(bankcmd.SendTxCommand())...) + client.PostCommands( + bankcmd.SendTxCommand(), + )...) // add proxy, version and key info basecliCmd.AddCommand( diff --git a/x/bank/commands/account.go b/x/bank/commands/account.go index c805d44c2..87f4066d9 100644 --- a/x/bank/commands/account.go +++ b/x/bank/commands/account.go @@ -19,16 +19,21 @@ import ( // GetAccountCmd returns a query account that will display the // state of the account at a given address -func GetAccountCmd() *cobra.Command { - cmd := &cobra.Command{ +func GetAccountCmd(storeName string) *cobra.Command { + cmd := acctCmd{storeName} + + return &cobra.Command{ Use: "account
", 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 { return errors.New("You must provide an account name") } @@ -40,9 +45,7 @@ func getAccount(cmd *cobra.Command, args []string) error { return err } key := crypto.Address(bz) - - // TODO: make the store name a variable in getAccountCmd? - path := "/main/key" + path := fmt.Sprintf("/%s/key", a.storeName) uri := viper.GetString(client.FlagNode) if uri == "" {