Skip to content

Commit

Permalink
Merge branch 'master' into release/v0.38.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez committed Jan 23, 2020
2 parents 2c26efa + d0ff973 commit f3b82c5
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 48 deletions.
2 changes: 1 addition & 1 deletion client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func GetFromFields(input io.Reader, from string, genOnly bool) (sdk.AccAddress,
return addr, "", nil
}

keybase, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(),
keybase, err := keys.NewKeyring(sdk.KeyringServiceName(),
viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), input)
if err != nil {
return nil, "", err
Expand Down
2 changes: 1 addition & 1 deletion client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func getKeybase(transient bool, buf io.Reader) (keys.Keybase, error) {
return keys.NewInMemory(), nil
}

return keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
return keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
}

func runAddCmd(cmd *cobra.Command, args []string) error {
Expand Down
4 changes: 2 additions & 2 deletions client/keys/add_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
require.NoError(t, runAddCmd(cmd, []string{"keyname1"}))

// Now check that it has been stored properly
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
require.NoError(t, err)
require.NotNil(t, kb)
defer func() {
Expand Down Expand Up @@ -98,7 +98,7 @@ func Test_runAddCmdLedger(t *testing.T) {
require.NoError(t, runAddCmd(cmd, []string{"keyname1"}))

// Now check that it has been stored properly
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
require.NoError(t, err)
require.NotNil(t, kb)
defer func() {
Expand Down
2 changes: 1 addition & 1 deletion client/keys/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Test_runAddCmdBasic(t *testing.T) {
mockIn.Reset("testpass1\ntestpass1\n")
} else {
mockIn.Reset("y\n")
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
require.NoError(t, err)
defer func() {
kb.Delete("keyname1", "", false)
Expand Down
2 changes: 1 addition & 1 deletion client/keys/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private keys stored in a ledger device cannot be deleted with the CLI.
func runDeleteCmd(cmd *cobra.Command, args []string) error {
buf := bufio.NewReader(cmd.InOrStdin())

kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions client/keys/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Test_runDeleteCmd(t *testing.T) {
fakeKeyName1 := "runDeleteCmd_Key1"
fakeKeyName2 := "runDeleteCmd_Key2"
if !runningUnattended {
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
require.NoError(t, err)
defer func() {
kb.Delete("runDeleteCmd_Key1", "", false)
Expand All @@ -41,7 +41,7 @@ func Test_runDeleteCmd(t *testing.T) {
viper.Set(flags.FlagHome, kbHome)

// Now
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
require.NoError(t, err)
if runningUnattended {
mockIn.Reset("testpass1\ntestpass1\n")
Expand Down
2 changes: 1 addition & 1 deletion client/keys/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ExportKeyCommand() *cobra.Command {

func runExportCmd(cmd *cobra.Command, args []string) error {
buf := bufio.NewReader(cmd.InOrStdin())
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion client/keys/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Test_runExportCmd(t *testing.T) {
viper.Set(flags.FlagHome, kbHome)

// create a key
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
require.NoError(t, err)
if !runningUnattended {
defer func() {
Expand Down
2 changes: 1 addition & 1 deletion client/keys/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func ImportKeyCommand() *cobra.Command {

func runImportCmd(cmd *cobra.Command, args []string) error {
buf := bufio.NewReader(cmd.InOrStdin())
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion client/keys/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Test_runImportCmd(t *testing.T) {
viper.Set(flags.FlagHome, kbHome)

if !runningUnattended {
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
require.NoError(t, err)
defer func() {
kb.Delete("keyname1", "", false)
Expand Down
2 changes: 1 addition & 1 deletion client/keys/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ along with their associated name and address.`,
}

func runListCmd(cmd *cobra.Command, _ []string) error {
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), cmd.InOrStdin())
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), cmd.InOrStdin())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion client/keys/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Test_runListCmd(t *testing.T) {
viper.Set(flags.FlagHome, kbHome2)

mockIn, _, _ := tests.ApplyMockIO(cmdBasic)
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
require.NoError(t, err)
if runningUnattended {
mockIn.Reset("testpass1\ntestpass1\n")
Expand Down
4 changes: 2 additions & 2 deletions client/keys/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -55,7 +55,7 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
}

buf := bufio.NewReader(cmd.InOrStdin())
keyringServiceName := types.GetConfig().GetKeyringServiceName()
keyringServiceName := sdk.KeyringServiceName()

var (
tmpDir string
Expand Down
2 changes: 1 addition & 1 deletion client/keys/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ consisting of all the keys provided by name and multisig threshold.`,
func runShowCmd(cmd *cobra.Command, args []string) (err error) {
var info keys.Info

kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), cmd.InOrStdin())
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), cmd.InOrStdin())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion client/keys/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Test_runShowCmd(t *testing.T) {

fakeKeyName1 := "runShowCmd_Key1"
fakeKeyName2 := "runShowCmd_Key2"
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
require.NoError(t, err)
defer func() {
kb.Delete("runShowCmd_Key1", "", false)
Expand Down
30 changes: 15 additions & 15 deletions crypto/keys/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ func newKeyringKeybase(db keyring.Keyring, opts ...KeybaseOption) Keybase {
// options can be applied when generating this new Keybase.
// Available backends are "os", "file", "test".
func NewKeyring(
svcName, backend, rootDir string, userInput io.Reader, opts ...KeybaseOption,
appName, backend, rootDir string, userInput io.Reader, opts ...KeybaseOption,
) (Keybase, error) {

var db keyring.Keyring
var err error

switch backend {
case BackendTest:
db, err = keyring.Open(lkbToKeyringConfig(svcName, rootDir, nil, true))
db, err = keyring.Open(lkbToKeyringConfig(appName, rootDir, nil, true))
case BackendFile:
db, err = keyring.Open(newFileBackendKeyringConfig(svcName, rootDir, userInput))
db, err = keyring.Open(newFileBackendKeyringConfig(appName, rootDir, userInput))
case BackendOS:
db, err = keyring.Open(lkbToKeyringConfig(svcName, rootDir, userInput, false))
db, err = keyring.Open(lkbToKeyringConfig(appName, rootDir, userInput, false))
case BackendKWallet:
db, err = keyring.Open(newKWalletBackendKeyringConfig(svcName, rootDir, userInput))
db, err = keyring.Open(newKWalletBackendKeyringConfig(appName, rootDir, userInput))
case BackendPass:
db, err = keyring.Open(newPassBackendKeyringConfig(svcName, rootDir, userInput))
db, err = keyring.Open(newPassBackendKeyringConfig(appName, rootDir, userInput))
default:
return nil, fmt.Errorf("unknown keyring backend %v", backend)
}
Expand Down Expand Up @@ -488,39 +488,39 @@ func (kb keyringKeybase) writeInfo(name string, info Info) {
}
}

func lkbToKeyringConfig(name, dir string, buf io.Reader, test bool) keyring.Config {
func lkbToKeyringConfig(appName, dir string, buf io.Reader, test bool) keyring.Config {
if test {
return keyring.Config{
AllowedBackends: []keyring.BackendType{keyring.FileBackend},
ServiceName: name,
FileDir: filepath.Join(dir, fmt.Sprintf(testKeyringDirNameFmt, name)),
ServiceName: appName,
FileDir: filepath.Join(dir, fmt.Sprintf(testKeyringDirNameFmt, appName)),
FilePasswordFunc: func(_ string) (string, error) {
return "test", nil
},
}
}

return keyring.Config{
ServiceName: name,
ServiceName: appName,
FileDir: dir,
FilePasswordFunc: newRealPrompt(dir, buf),
}
}

func newKWalletBackendKeyringConfig(name, _ string, _ io.Reader) keyring.Config {
func newKWalletBackendKeyringConfig(appName, _ string, _ io.Reader) keyring.Config {
return keyring.Config{
AllowedBackends: []keyring.BackendType{keyring.KWalletBackend},
ServiceName: "kdewallet",
KWalletAppID: name,
KWalletAppID: appName,
KWalletFolder: "",
}
}

func newPassBackendKeyringConfig(name, dir string, _ io.Reader) keyring.Config {
prefix := filepath.Join(dir, fmt.Sprintf(keyringDirNameFmt, name))
func newPassBackendKeyringConfig(appName, dir string, _ io.Reader) keyring.Config {
prefix := filepath.Join(dir, fmt.Sprintf(keyringDirNameFmt, appName))
return keyring.Config{
AllowedBackends: []keyring.BackendType{keyring.PassBackend},
ServiceName: name,
ServiceName: appName,
PassPrefix: prefix,
}
}
Expand Down
19 changes: 8 additions & 11 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package types

import (
"sync"

"github.com/cosmos/cosmos-sdk/version"
)

// DefaultKeyringServiceName defines a default service name for the keyring.
Expand All @@ -11,7 +13,6 @@ const DefaultKeyringServiceName = "cosmos"
// This could be used to initialize certain configuration parameters for the SDK.
type Config struct {
fullFundraiserPath string
keyringServiceName string
bech32AddressPrefix map[string]string
txEncoder TxEncoder
addressVerifier func([]byte) error
Expand All @@ -28,6 +29,7 @@ func GetConfig() *Config {
if sdkConfig != nil {
return sdkConfig
}

sdkConfig = &Config{
sealed: false,
bech32AddressPrefix: map[string]string{
Expand All @@ -41,7 +43,6 @@ func GetConfig() *Config {
coinType: CoinType,
fullFundraiserPath: FullFundraiserPath,
txEncoder: nil,
keyringServiceName: DefaultKeyringServiceName,
}
return sdkConfig
}
Expand Down Expand Up @@ -104,12 +105,6 @@ func (config *Config) SetFullFundraiserPath(fullFundraiserPath string) {
config.fullFundraiserPath = fullFundraiserPath
}

// Set the keyringServiceName (BIP44Prefix) on the config
func (config *Config) SetKeyringServiceName(keyringServiceName string) {
config.assertNotSealed()
config.keyringServiceName = keyringServiceName
}

// Seal seals the config such that the config state could not be modified further
func (config *Config) Seal() *Config {
config.mtx.Lock()
Expand Down Expand Up @@ -169,7 +164,9 @@ func (config *Config) GetFullFundraiserPath() string {
return config.fullFundraiserPath
}

// GetKeyringServiceName returns the keyring service name from the config.
func (config *Config) GetKeyringServiceName() string {
return config.keyringServiceName
func KeyringServiceName() string {
if len(version.Name) == 0 {
return DefaultKeyringServiceName
}
return version.Name
}
2 changes: 1 addition & 1 deletion x/auth/client/cli/tx_multisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string)
}

inBuf := bufio.NewReader(cmd.InOrStdin())
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(),
kb, err := keys.NewKeyring(sdk.KeyringServiceName(),
viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), inBuf)
if err != nil {
return
Expand Down
4 changes: 2 additions & 2 deletions x/auth/types/txbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewTxBuilder(
// NewTxBuilderFromCLI returns a new initialized TxBuilder with parameters from
// the command line using Viper.
func NewTxBuilderFromCLI(input io.Reader) TxBuilder {
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), input)
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), input)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -276,7 +276,7 @@ func MakeSignature(keybase keys.Keybase, name, passphrase string,
msg StdSignMsg) (sig StdSignature, err error) {

if keybase == nil {
keybase, err = keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), os.Stdin)
keybase, err = keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), os.Stdin)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion x/genutil/client/cli/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func GenTxCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, sm
}

inBuf := bufio.NewReader(cmd.InOrStdin())
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(),
kb, err := keys.NewKeyring(sdk.KeyringServiceName(),
viper.GetString(flags.FlagKeyringBackend), viper.GetString(flagClientHome), inBuf)
if err != nil {
return errors.Wrap(err, "failed to initialize keybase")
Expand Down

0 comments on commit f3b82c5

Please sign in to comment.