diff options
author | zelig <viktor.tron@gmail.com> | 2015-09-22 16:34:58 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-10-22 06:22:39 +0800 |
commit | 8b81ad1fc40080af441c0c6df94f0b2ea46e320b (patch) | |
tree | 7d8817ec84be38b911f967f1ecd5618d02e4caa9 /cmd/geth/js.go | |
parent | 58d0752fdd1c7363fb1a127cd7e0a86d7602be02 (diff) | |
download | dexon-8b81ad1fc40080af441c0c6df94f0b2ea46e320b.tar.gz dexon-8b81ad1fc40080af441c0c6df94f0b2ea46e320b.tar.zst dexon-8b81ad1fc40080af441c0c6df94f0b2ea46e320b.zip |
console:
* lines with leading space are ommitted from history
* exit processed even with whitespace around
* all whitespace lines (not only empty ones) are ignored
add 7 missing commands to admin api autocomplete
registrar: methods now return proper error if reg addresses are not set. fixes #1457
rpc/console: fix personal.newAccount() regression. Now all comms accept interactive password
registrar: add registrar tests for errors
crypto: catch AES decryption error on presale wallet import + fix error msg format. fixes #1580
CLI: improve error message when starting a second instance of geth. fixes #1564
cli/accounts: unlock multiple accounts. fixes #1785
* make unlocking multiple accounts work with inline <() fd
* passwdfile now correctly read only once
* improve logs
* fix CLI help text for unlocking
fix regression with docRoot / admin API
* docRoot/jspath passed to rpc/api ParseApis, which passes onto adminApi
* docRoot field for JS console in order to pass when RPC is (re)started
* improve flag desc for jspath
common/docserver: catch http errors from response
fix rpc/api tests
common/natspec: fix end to end test (skipped because takes 8s)
registrar: fix major regression:
* deploy registrars on frontier
* register HashsReg and UrlHint in GlobalRegistrar.
* set all 3 contract addresses in code
* zero out addresses first in tests
Diffstat (limited to 'cmd/geth/js.go')
-rw-r--r-- | cmd/geth/js.go | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/cmd/geth/js.go b/cmd/geth/js.go index b5ec82b57..8ebb04bce 100644 --- a/cmd/geth/js.go +++ b/cmd/geth/js.go @@ -45,9 +45,12 @@ import ( "github.com/robertkrimen/otto" ) -var passwordRegexp = regexp.MustCompile("personal.[nu]") - -const passwordRepl = "" +var ( + passwordRegexp = regexp.MustCompile("personal.[nu]") + leadingSpace = regexp.MustCompile("^ ") + onlyws = regexp.MustCompile("^\\s*$") + exit = regexp.MustCompile("^\\s*exit\\s*;*\\s*$") +) type prompter interface { AppendHistory(string) @@ -74,6 +77,7 @@ func (r dumbterm) PasswordPrompt(p string) (string, error) { func (r dumbterm) AppendHistory(string) {} type jsre struct { + docRoot string ds *docserver.DocServer re *re.JSRE ethereum *eth.Ethereum @@ -145,14 +149,14 @@ func apiWordCompleter(line string, pos int) (head string, completions []string, return begin, completionWords, end } -func newLightweightJSRE(libPath string, client comms.EthereumClient, datadir string, interactive bool) *jsre { +func newLightweightJSRE(docRoot string, client comms.EthereumClient, datadir string, interactive bool) *jsre { js := &jsre{ps1: "> "} js.wait = make(chan *big.Int) js.client = client - js.ds = docserver.New("/") + js.ds = docserver.New(docRoot) // update state in separare forever blocks - js.re = re.New(libPath) + js.re = re.New(docRoot) if err := js.apiBindings(js); err != nil { utils.Fatalf("Unable to initialize console - %v", err) } @@ -176,25 +180,25 @@ func newLightweightJSRE(libPath string, client comms.EthereumClient, datadir str return js } -func newJSRE(ethereum *eth.Ethereum, libPath, corsDomain string, client comms.EthereumClient, interactive bool, f xeth.Frontend) *jsre { - js := &jsre{ethereum: ethereum, ps1: "> "} +func newJSRE(ethereum *eth.Ethereum, docRoot, corsDomain string, client comms.EthereumClient, interactive bool, f xeth.Frontend) *jsre { + js := &jsre{ethereum: ethereum, ps1: "> ", docRoot: docRoot} // set default cors domain used by startRpc from CLI flag js.corsDomain = corsDomain if f == nil { f = js } - js.ds = docserver.New("/") + js.ds = docserver.New(docRoot) js.xeth = xeth.New(ethereum, f) js.wait = js.xeth.UpdateState() js.client = client if clt, ok := js.client.(*comms.InProcClient); ok { - if offeredApis, err := api.ParseApiString(shared.AllApis, codec.JSON, js.xeth, ethereum); err == nil { + if offeredApis, err := api.ParseApiString(shared.AllApis, codec.JSON, js.xeth, ethereum, docRoot); err == nil { clt.Initialize(api.Merge(offeredApis...)) } } // update state in separare forever blocks - js.re = re.New(libPath) + js.re = re.New(docRoot) if err := js.apiBindings(f); err != nil { utils.Fatalf("Unable to connect - %v", err) } @@ -277,7 +281,7 @@ func (js *jsre) apiBindings(f xeth.Frontend) error { apiNames = append(apiNames, a) } - apiImpl, err := api.ParseApiString(strings.Join(apiNames, ","), codec.JSON, js.xeth, js.ethereum) + apiImpl, err := api.ParseApiString(strings.Join(apiNames, ","), codec.JSON, js.xeth, js.ethereum, js.docRoot) if err != nil { utils.Fatalf("Unable to determine supported api's: %v", err) } @@ -334,6 +338,14 @@ func (js *jsre) apiBindings(f xeth.Frontend) error { return nil } +func (self *jsre) AskPassword() (string, bool) { + pass, err := self.PasswordPrompt("Passphrase: ") + if err != nil { + return "", false + } + return pass, true +} + func (self *jsre) ConfirmTransaction(tx string) bool { if self.ethereum.NatSpec { notice := natspec.GetNotice(self.xeth, tx, self.ds) @@ -405,18 +417,17 @@ func (self *jsre) interactive() { fmt.Println("caught interrupt, exiting") return case input, ok := <-inputln: - if !ok || indentCount <= 0 && input == "exit" { + if !ok || indentCount <= 0 && exit.MatchString(input) { return } - if input == "" { + if onlyws.MatchString(input) { continue } str += input + "\n" self.setIndent() if indentCount <= 0 { - hist := hidepassword(str[:len(str)-1]) - if len(hist) > 0 { - self.AppendHistory(hist) + if mustLogInHistory(str) { + self.AppendHistory(str[:len(str)-1]) } self.parseInput(str) str = "" @@ -425,12 +436,10 @@ func (self *jsre) interactive() { } } -func hidepassword(input string) string { - if passwordRegexp.MatchString(input) { - return passwordRepl - } else { - return input - } +func mustLogInHistory(input string) bool { + return len(input) == 0 || + passwordRegexp.MatchString(input) || + leadingSpace.MatchString(input) } func (self *jsre) withHistory(datadir string, op func(*os.File)) { |