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

Add account mnemonic in config #1489

Merged
merged 2 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"time"

"github.com/cosmos/go-bip39"
homedir "github.com/mitchellh/go-homedir"
"github.com/sirupsen/logrus"
tmconfig "github.com/tendermint/tendermint/config"
Expand Down Expand Up @@ -63,6 +64,7 @@ type Config struct {
Account struct {
Name string `validate:"required"`
Password string `validate:"required"`
Mnemonic string
}
}

Expand Down Expand Up @@ -170,8 +172,12 @@ func (c *Config) validate() error {
if _, err := logrus.ParseLevel(c.Log.Level); err != nil {
return fmt.Errorf("config.Log.Level error: %w", err)
}
if c.Account.Mnemonic != "" && !bip39.IsMnemonicValid(c.Account.Mnemonic) {
return fmt.Errorf("config.Account.Mnemonic error: mnemonic is not valid")
}
if err := c.Tendermint.Config.ValidateBasic(); err != nil {
return fmt.Errorf("config.Tendermint error: %w", err)
}

return validator.New().Struct(c)
}
5 changes: 5 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ func TestDefaultConfig(t *testing.T) {
require.Equal(t, filepath.Join(home, ".mesg"), c.Path)
require.Equal(t, filepath.Join("database", "executions", executionDBVersion), c.Database.ExecutionRelativePath)
require.Equal(t, "engine", c.Name)
require.Equal(t, "engine", c.Account.Name)
require.Equal(t, "pass", c.Account.Password)
}

func TestEnv(t *testing.T) {
os.Setenv(envPathKey, "tempPath")
defer os.Unsetenv(envPathKey)
Expand Down Expand Up @@ -56,6 +59,8 @@ func TestLoadFromFile(t *testing.T) {
address: :50050
log:
forcecolors: true
account:
mnemonic: glimpse upon body vast economy give taxi yellow rabbit come click ranch chronic hammer sport near rotate charge lumber chicken cloud base thing forum
tendermint:
config:
consensus:
Expand Down
5 changes: 5 additions & 0 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func stopRunningServices(sdk *enginesdk.SDK, cfg *config.Config, address string)
}

func loadOrGenConfigAccount(kb *cosmos.Keybase, cfg *config.Config) (keys.Info, error) {
if cfg.Account.Mnemonic != "" {
logrus.WithField("module", "main").Warn("Config account mnemonic presents. Generating account with it...")
return kb.CreateAccount(cfg.Account.Name, cfg.Account.Mnemonic, "", cfg.Account.Password, 0, 0)
NicolasMahe marked this conversation as resolved.
Show resolved Hide resolved
}

exist, err := kb.Exist(cfg.Account.Name)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions e2e/testdata/e2e.config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
log:
level: fatal

account:
mnemonic: glimpse upon body vast economy give taxi yellow rabbit come click ranch chronic hammer sport near rotate charge lumber chicken cloud base thing forum


tendermint:
config:
consensus:
Expand Down