Skip to content

Commit

Permalink
Merge branch 'master' into ty-8941-grpc_vm
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 authored May 19, 2021
2 parents 418a455 + b4d1a5e commit e05c9c9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
3 changes: 2 additions & 1 deletion client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) {
}
// we need to update KeyringDir field on Client Context first cause it is used in NewKeyringFromBackend
ctx = ctx.WithOutputFormat(conf.Output).
WithChainID(conf.ChainID)
WithChainID(conf.ChainID).
WithKeyringDir(ctx.HomeDir)

keyring, err := client.NewKeyringFromBackend(ctx, conf.KeyringBackend)
if err != nil {
Expand Down
15 changes: 7 additions & 8 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

bip39 "github.com/cosmos/go-bip39"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -109,6 +108,7 @@ func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
noBackup, _ := cmd.Flags().GetBool(flagNoBackup)
showMnemonic := !noBackup
kb := ctx.Keyring
outputFormat := ctx.OutputFormat

keyringAlgos, _ := kb.SupportedAlgorithms()
algoStr, _ := cmd.Flags().GetString(flags.FlagKeyAlgorithm)
Expand Down Expand Up @@ -201,7 +201,7 @@ func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
return err
}

return printCreate(cmd, info, false, "")
return printCreate(cmd, info, false, "", outputFormat)
}

// Get bip39 mnemonic
Expand Down Expand Up @@ -275,15 +275,14 @@ func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
mnemonic = ""
}

return printCreate(cmd, info, showMnemonic, mnemonic)
return printCreate(cmd, info, showMnemonic, mnemonic, outputFormat)
}

func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemonic string) error {
output, _ := cmd.Flags().GetString(cli.OutputFlag)
switch output {
func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemonic string, outputFormat string) error {
switch outputFormat {
case OutputFormatText:
cmd.PrintErrln()
printKeyInfo(cmd.OutOrStdout(), info, keyring.MkAccKeyOutput, output)
printKeyInfo(cmd.OutOrStdout(), info, keyring.MkAccKeyOutput, outputFormat)

// print mnemonic unless requested not to.
if showMnemonic {
Expand All @@ -310,7 +309,7 @@ func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemo
cmd.Println(string(jsonString))

default:
return fmt.Errorf("invalid output format %s", output)
return fmt.Errorf("invalid output format %s", outputFormat)
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions client/keys/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
return err
}

output, _ := cmd.Flags().GetString(cli.OutputFlag)
if isOutputSet {
clientCtx.OutputFormat, _ = cmd.Flags().GetString(cli.OutputFlag)
}

switch {
case isShowAddr, isShowPubKey:
Expand All @@ -126,7 +128,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
}
fmt.Fprintln(cmd.OutOrStdout(), out)
default:
printKeyInfo(cmd.OutOrStdout(), info, bechKeyOut, output)
printKeyInfo(cmd.OutOrStdout(), info, bechKeyOut, clientCtx.OutputFormat)
}

if isShowDevice {
Expand Down
8 changes: 6 additions & 2 deletions store/cachemulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,17 @@ func (cms Store) CacheMultiStoreWithVersion(_ int64) (types.CacheMultiStore, err

// GetStore returns an underlying Store by key.
func (cms Store) GetStore(key types.StoreKey) types.Store {
return cms.stores[key].(types.Store)
s := cms.stores[key]
if key == nil || s == nil {
panic(fmt.Sprintf("kv store with key %v has not been registered in stores", key))
}
return s.(types.Store)
}

// GetKVStore returns an underlying KVStore by key.
func (cms Store) GetKVStore(key types.StoreKey) types.KVStore {
store := cms.stores[key]
if key == nil {
if key == nil || store == nil {
panic(fmt.Sprintf("kv store with key %v has not been registered in stores", key))
}
return store.(types.KVStore)
Expand Down
23 changes: 23 additions & 0 deletions store/cachemulti/store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cachemulti

import (
"fmt"
"testing"

"github.com/cosmos/cosmos-sdk/store/types"
"github.com/stretchr/testify/require"
)

func TestStoreGetKVStore(t *testing.T) {
require := require.New(t)

s := Store{stores: map[types.StoreKey]types.CacheWrap{}}
key := types.NewKVStoreKey("abc")
errMsg := fmt.Sprintf("kv store with key %v has not been registered in stores", key)

require.PanicsWithValue(errMsg,
func() { s.GetStore(key) })

require.PanicsWithValue(errMsg,
func() { s.GetKVStore(key) })
}
6 changes: 5 additions & 1 deletion store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,11 @@ func (rs *Store) GetStore(key types.StoreKey) types.Store {
// NOTE: The returned KVStore may be wrapped in an inter-block cache if it is
// set on the root store.
func (rs *Store) GetKVStore(key types.StoreKey) types.KVStore {
store := rs.stores[key].(types.KVStore)
s := rs.stores[key]
if s == nil {
panic(fmt.Sprintf("store does not exist for key: %s", key.Name()))
}
store := s.(types.KVStore)

if rs.TracingEnabled() {
store = tracekv.NewStore(store, rs.traceWriter, rs.traceContext)
Expand Down

0 comments on commit e05c9c9

Please sign in to comment.