diff options
Diffstat (limited to 'cmd/utils/flags.go')
-rw-r--r-- | cmd/utils/flags.go | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 1d70245ab..ceed04cd3 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -551,45 +551,36 @@ func MakeDatabaseHandles() int { // MakeAccountManager creates an account manager from set command line flags. func MakeAccountManager(ctx *cli.Context) *accounts.Manager { // Create the keystore crypto primitive, light if requested - scryptN := crypto.StandardScryptN - scryptP := crypto.StandardScryptP - + scryptN := accounts.StandardScryptN + scryptP := accounts.StandardScryptP if ctx.GlobalBool(LightKDFFlag.Name) { - scryptN = crypto.LightScryptN - scryptP = crypto.LightScryptP + scryptN = accounts.LightScryptN + scryptP = accounts.LightScryptP } - // Assemble an account manager using the configured datadir - var ( - datadir = MustMakeDataDir(ctx) - keystoredir = MakeKeyStoreDir(datadir, ctx) - keystore = crypto.NewKeyStorePassphrase(keystoredir, scryptN, scryptP) - ) - return accounts.NewManager(keystore) + datadir := MustMakeDataDir(ctx) + keydir := MakeKeyStoreDir(datadir, ctx) + return accounts.NewManager(keydir, scryptN, scryptP) } // MakeAddress converts an account specified directly as a hex encoded string or // a key index in the key store to an internal account representation. -func MakeAddress(accman *accounts.Manager, account string) (a common.Address, err error) { +func MakeAddress(accman *accounts.Manager, account string) (accounts.Account, error) { // If the specified account is a valid address, return it if common.IsHexAddress(account) { - return common.HexToAddress(account), nil + return accounts.Account{Address: common.HexToAddress(account)}, nil } // Otherwise try to interpret the account as a keystore index index, err := strconv.Atoi(account) if err != nil { - return a, fmt.Errorf("invalid account address or index %q", account) - } - hex, err := accman.AddressByIndex(index) - if err != nil { - return a, fmt.Errorf("can't get account #%d (%v)", index, err) + return accounts.Account{}, fmt.Errorf("invalid account address or index %q", account) } - return common.HexToAddress(hex), nil + return accman.AccountByIndex(index) } // MakeEtherbase retrieves the etherbase either from the directly specified // command line flags or from the keystore if CLI indexed. func MakeEtherbase(accman *accounts.Manager, ctx *cli.Context) common.Address { - accounts, _ := accman.Accounts() + accounts := accman.Accounts() if !ctx.GlobalIsSet(EtherbaseFlag.Name) && len(accounts) == 0 { glog.V(logger.Error).Infoln("WARNING: No etherbase set and no accounts found as default") return common.Address{} @@ -599,11 +590,11 @@ func MakeEtherbase(accman *accounts.Manager, ctx *cli.Context) common.Address { return common.Address{} } // If the specified etherbase is a valid address, return it - addr, err := MakeAddress(accman, etherbase) + account, err := MakeAddress(accman, etherbase) if err != nil { Fatalf("Option %q: %v", EtherbaseFlag.Name, err) } - return addr + return account.Address } // MakeMinerExtra resolves extradata for the miner from the set command line flags @@ -615,17 +606,22 @@ func MakeMinerExtra(extra []byte, ctx *cli.Context) []byte { return extra } -// MakePasswordList loads up a list of password from a file specified by the -// command line flags. +// MakePasswordList reads password lines from the file specified by --password. func MakePasswordList(ctx *cli.Context) []string { - if path := ctx.GlobalString(PasswordFileFlag.Name); path != "" { - blob, err := ioutil.ReadFile(path) - if err != nil { - Fatalf("Failed to read password file: %v", err) - } - return strings.Split(string(blob), "\n") + path := ctx.GlobalString(PasswordFileFlag.Name) + if path == "" { + return nil + } + text, err := ioutil.ReadFile(path) + if err != nil { + Fatalf("Failed to read password file: %v", err) + } + lines := strings.Split(string(text), "\n") + // Sanitise DOS line endings. + for i := range lines { + lines[i] = strings.TrimRight(lines[i], "\r") } - return nil + return lines } // MakeSystemNode sets up a local node, configures the services to launch and |