diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-03-08 23:07:12 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-03-08 23:07:12 +0800 |
commit | 05c86c2c9fa14ea03fdc5d0cd77cdecc34e4f164 (patch) | |
tree | 270fab0bb443b8055320c9cab583f0dd7f4fb560 | |
parent | 31b4ff8cc12cce8fb94538c2f6d5f6da883b10d1 (diff) | |
parent | 0fd251c7f7df6e76a88e6f37bf4282a84a9006dc (diff) | |
download | dexon-05c86c2c9fa14ea03fdc5d0cd77cdecc34e4f164.tar.gz dexon-05c86c2c9fa14ea03fdc5d0cd77cdecc34e4f164.tar.zst dexon-05c86c2c9fa14ea03fdc5d0cd77cdecc34e4f164.zip |
Merge pull request #2309 from bas-vk/passwd
console: allow optional password on the command line
-rw-r--r-- | cmd/utils/jeth.go | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/cmd/utils/jeth.go b/cmd/utils/jeth.go index b460597c1..e5e520db2 100644 --- a/cmd/utils/jeth.go +++ b/cmd/utils/jeth.go @@ -58,7 +58,7 @@ func (self *Jeth) err(call otto.FunctionCall, code int, msg string, id *int64) ( // UnlockAccount asks the user for the password and than executes the jeth.UnlockAccount callback in the jsre func (self *Jeth) UnlockAccount(call otto.FunctionCall) (response otto.Value) { - var cmd, account, passwd string + var account, passwd string timeout := int64(300) var ok bool @@ -92,8 +92,7 @@ func (self *Jeth) UnlockAccount(call otto.FunctionCall) (response otto.Value) { } } - cmd = fmt.Sprintf("jeth.unlockAccount('%s', '%s', %d)", account, passwd, timeout) - if val, err := call.Otto.Run(cmd); err == nil { + if val, err := call.Otto.Call("jeth.unlockAccount", nil, account, passwd, timeout); err == nil { return val } @@ -102,8 +101,10 @@ func (self *Jeth) UnlockAccount(call otto.FunctionCall) (response otto.Value) { // NewAccount asks the user for the password and than executes the jeth.newAccount callback in the jsre func (self *Jeth) NewAccount(call otto.FunctionCall) (response otto.Value) { + var passwd string if len(call.ArgumentList) == 0 { - passwd, err := PromptPassword("Passphrase: ", true) + var err error + passwd, err = PromptPassword("Passphrase: ", true) if err != nil { return otto.FalseValue() } @@ -116,13 +117,18 @@ func (self *Jeth) NewAccount(call otto.FunctionCall) (response otto.Value) { fmt.Println("Passphrases don't match") return otto.FalseValue() } + } else if len(call.ArgumentList) == 1 && call.Argument(0).IsString() { + passwd, _ = call.Argument(0).ToString() + } else { + fmt.Println("expected 0 or 1 string argument") + return otto.FalseValue() + } - cmd := fmt.Sprintf("jeth.newAccount('%s')", passwd) - if val, err := call.Otto.Run(cmd); err == nil { - return val - } + if ret, err := call.Otto.Call("jeth.newAccount", nil, passwd); err == nil { + return ret } else { - fmt.Println("New account doesn't expect argument(s), you will be prompted for a password") + fmt.Printf("%v\n", err) + return otto.FalseValue() } return otto.FalseValue() |