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

Move AccNumber and AccIndex to the config #1599

Merged
merged 1 commit into from
Jan 14, 2020
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
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type Config struct {
Account struct {
Name string `validate:"required"`
Password string `validate:"required"`
Number uint32
Index uint32
Mnemonic string
}
}
Expand Down Expand Up @@ -97,6 +99,8 @@ func defaultConfig() (*Config, error) {

c.Account.Name = "engine"
c.Account.Password = "pass"
c.Account.Number = uint32(0)
c.Account.Index = uint32(0)

return &c, nil
}
Expand Down
2 changes: 2 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func TestDefaultConfig(t *testing.T) {
require.Equal(t, "engine", c.Name)
require.Equal(t, "engine", c.Account.Name)
require.Equal(t, "pass", c.Account.Password)
require.Equal(t, uint32(0), c.Account.Number)
require.Equal(t, uint32(0), c.Account.Index)
}

func TestEnv(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func stopRunningServices(sdk *enginesdk.SDK, address string) error {
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, cosmos.AccNumber, cosmos.AccIndex)
return kb.CreateAccount(cfg.Account.Name, cfg.Account.Mnemonic, "", cfg.Account.Password, cfg.Account.Number, cfg.Account.Index)
}

exist, err := kb.Exist(cfg.Account.Name)
Expand All @@ -82,7 +82,7 @@ func loadOrGenConfigAccount(kb *cosmos.Keybase, cfg *config.Config) (keys.Info,
"password": cfg.Account.Password,
"mnemonic": mnemonic,
}).Warn("Account")
return kb.CreateAccount(cfg.Account.Name, mnemonic, "", cfg.Account.Password, cosmos.AccNumber, cosmos.AccIndex)
return kb.CreateAccount(cfg.Account.Name, mnemonic, "", cfg.Account.Password, cfg.Account.Number, cfg.Account.Index)
}

func loadOrGenDevGenesis(app *cosmos.App, kb *cosmos.Keybase, cfg *config.Config) (*tmtypes.GenesisDoc, error) {
Expand Down
2 changes: 1 addition & 1 deletion cosmos/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestGenesis(t *testing.T) {
)
// init account
mnemonic, _ := kb.NewMnemonic()
kb.CreateAccount(name, mnemonic, "", password, AccNumber, AccIndex)
kb.CreateAccount(name, mnemonic, "", password, 0, 0)
// start tests
t.Run("generate validator", func(t *testing.T) {
v, err := NewGenesisValidator(kb, name, password, privValidatorKeyFile, privValidatorStateFile, nodeKeyFile)
Expand Down
9 changes: 1 addition & 8 deletions cosmos/keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ import (
"github.com/tendermint/tendermint/crypto"
)

const (
// AccNumber is the account number of the account in keybase.
AccNumber = 0
// AccIndex is the account index of the account in keybase.
AccIndex = 0

mnemonicEntropySize = 256
)
const mnemonicEntropySize = 256

// Keybase is a standard cosmos keybase.
type Keybase struct {
Expand Down
2 changes: 1 addition & 1 deletion cosmos/keybase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestKeybase(t *testing.T) {
})

t.Run("Create", func(t *testing.T) {
acc, err := kb.CreateAccount(name, mnemonic, "", password, AccNumber, AccIndex)
acc, err := kb.CreateAccount(name, mnemonic, "", password, 0, 0)
require.NoError(t, err)
require.Equal(t, name, acc.GetName())
})
Expand Down