aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth/js.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/geth/js.go')
-rw-r--r--cmd/geth/js.go55
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)) {