Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple NewKeyringFromDir() from sdk.GetConfig() #5547

Merged
merged 10 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ if the provided arguments are invalid.
`StdTx.Signatures` to get back the array of StdSignatures `[]StdSignature`.
* (modules) [\#5299](https://github.com/cosmos/cosmos-sdk/pull/5299) `HandleDoubleSign` along with params `MaxEvidenceAge`
and `DoubleSignJailEndTime` have moved from the `x/slashing` module to the `x/evidence` module.
* (keys) [\#4941](https://github.com/cosmos/cosmos-sdk/issues/4941) Keybase concrete types constructors such as `NewKeyringFromHomeFlag`, `NewKeyringFromDir`, `NewKeyBaseFromDir`, or `NewInMemory`
* (keys) [\#4941](https://github.com/cosmos/cosmos-sdk/issues/4941) Keybase concrete types constructors such as `NewKeyringFromHomeFlag`, `NewKeyBaseFromDir`, or `NewInMemory`
now accept optional parameters of type `KeybaseOption`. These optional parameters are also added on the keys subcommands
functions, which are now public, and allows these options to be set on the commands or ignored to default to previous behavior.
Furthermore, the `NewKeyBaseFromHomeFlag` constructor has been removed [\#5547](https://github.com/cosmos/cosmos-sdk/pull/5547)
Expand Down
11 changes: 1 addition & 10 deletions client/keys/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,7 @@ func NewInMemoryKeyBase() keys.Keybase { return keys.NewInMemory() }
// NewKeyBaseFromHomeFlag initializes a keyring based on configuration. Keybase
// options can be applied when generating this new Keybase.
func NewKeyringFromHomeFlag(input io.Reader, opts ...keys.KeybaseOption) (keys.Keybase, error) {
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
alessio marked this conversation as resolved.
Show resolved Hide resolved
return NewKeyringFromDir(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagHome), input, opts...)
}

// NewKeyBaseFromDir initializes a keyring at the given directory.
// If the viper flag flags.FlagKeyringBackend is set to file, it returns an on-disk keyring with
// CLI prompt support only. If flags.FlagKeyringBackend is set to test it will return an on-disk,
// password-less keyring that could be used for testing purposes.
func NewKeyringFromDir(keyringServiceName string, rootDir string, input io.Reader, opts ...keys.KeybaseOption) (keys.Keybase, error) {
keyringBackend := viper.GetString(flags.FlagKeyringBackend)
return keys.NewKeyring(keyringServiceName, keyringBackend, rootDir, input, opts...)
return keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), input, opts...)
}

func getLazyKeyBaseFromDir(rootDir string, opts ...keys.KeybaseOption) (keys.Keybase, error) {
Expand Down
26 changes: 0 additions & 26 deletions client/keys/utils_test.go

This file was deleted.

13 changes: 6 additions & 7 deletions x/auth/client/cli/tx_multisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import (
"github.com/spf13/viper"

"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/codec"
crkeys "github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
Expand Down Expand Up @@ -68,17 +66,18 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string)
}

inBuf := bufio.NewReader(cmd.InOrStdin())
keybase, err := keys.NewKeyringFromDir(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(cli.HomeFlag), inBuf)
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(),
viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), inBuf)
if err != nil {
return
}

multisigInfo, err := keybase.Get(args[1])
multisigInfo, err := kb.Get(args[1])
if err != nil {
return
}
if multisigInfo.GetType() != crkeys.TypeMulti {
return fmt.Errorf("%q must be of type %s: %s", args[1], crkeys.TypeMulti, multisigInfo.GetType())
if multisigInfo.GetType() != keys.TypeMulti {
return fmt.Errorf("%q must be of type %s: %s", args[1], keys.TypeMulti, multisigInfo.GetType())
}

multisigPub := multisigInfo.GetPubKey().(multisig.PubKeyMultisigThreshold)
Expand Down
8 changes: 4 additions & 4 deletions x/genutil/client/cli/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import (

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/codec"
kbkeys "github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand Down Expand Up @@ -94,7 +93,8 @@ func GenTxCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, sm
}

inBuf := bufio.NewReader(cmd.InOrStdin())
kb, err := keys.NewKeyringFromDir(sdk.GetConfig().GetKeyringServiceName(), viper.GetString(flagClientHome), inBuf)
kb, err := keys.NewKeyring(sdk.GetConfig().GetKeyringServiceName(),
viper.GetString(flags.FlagKeyringBackend), viper.GetString(flagClientHome), inBuf)
if err != nil {
return errors.Wrap(err, "failed to initialize keybase")
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func GenTxCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, sm
return errors.Wrap(err, "failed to build create-validator message")
}

if key.GetType() == kbkeys.TypeOffline || key.GetType() == kbkeys.TypeMulti {
if key.GetType() == keys.TypeOffline || key.GetType() == keys.TypeMulti {
fmt.Println("Offline key passed in. Use `tx sign` command to sign:")
return utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg})
}
Expand Down