aboutsummaryrefslogtreecommitdiffstats
path: root/console
diff options
context:
space:
mode:
Diffstat (limited to 'console')
-rw-r--r--console/bridge.go25
-rw-r--r--console/console.go11
-rw-r--r--console/prompter.go4
3 files changed, 15 insertions, 25 deletions
diff --git a/console/bridge.go b/console/bridge.go
index 7f7e6feb1..f0c59804b 100644
--- a/console/bridge.go
+++ b/console/bridge.go
@@ -46,7 +46,7 @@ func newBridge(client *rpc.Client, prompter UserPrompter, printer io.Writer) *br
}
// NewAccount is a wrapper around the personal.newAccount RPC method that uses a
-// non-echoing password prompt to aquire the passphrase and executes the original
+// non-echoing password prompt to acquire the passphrase and executes the original
// RPC method (saved in jeth.newAccount) with it to actually execute the RPC call.
func (b *bridge) NewAccount(call otto.FunctionCall) (response otto.Value) {
var (
@@ -75,7 +75,7 @@ func (b *bridge) NewAccount(call otto.FunctionCall) (response otto.Value) {
default:
throwJSException("expected 0 or 1 string argument")
}
- // Password aquired, execute the call and return
+ // Password acquired, execute the call and return
ret, err := call.Otto.Call("jeth.newAccount", nil, password)
if err != nil {
throwJSException(err.Error())
@@ -84,7 +84,7 @@ func (b *bridge) NewAccount(call otto.FunctionCall) (response otto.Value) {
}
// UnlockAccount is a wrapper around the personal.unlockAccount RPC method that
-// uses a non-echoing password prompt to aquire the passphrase and executes the
+// uses a non-echoing password prompt to acquire the passphrase and executes the
// original RPC method (saved in jeth.unlockAccount) with it to actually execute
// the RPC call.
func (b *bridge) UnlockAccount(call otto.FunctionCall) (response otto.Value) {
@@ -127,7 +127,7 @@ func (b *bridge) UnlockAccount(call otto.FunctionCall) (response otto.Value) {
}
// Sign is a wrapper around the personal.sign RPC method that uses a non-echoing password
-// prompt to aquire the passphrase and executes the original RPC method (saved in
+// prompt to acquire the passphrase and executes the original RPC method (saved in
// jeth.sign) with it to actually execute the RPC call.
func (b *bridge) Sign(call otto.FunctionCall) (response otto.Value) {
var (
@@ -270,18 +270,15 @@ func (b *bridge) Send(call otto.FunctionCall) (response otto.Value) {
} else {
resultVal, err := JSON.Call("parse", string(result))
if err != nil {
- resp = newErrorResponse(call, -32603, err.Error(), &req.Id).Object()
+ setError(resp, -32603, err.Error())
} else {
resp.Set("result", resultVal)
}
}
case rpc.Error:
- resp.Set("error", map[string]interface{}{
- "code": err.ErrorCode(),
- "message": err.Error(),
- })
+ setError(resp, err.ErrorCode(), err.Error())
default:
- resp = newErrorResponse(call, -32603, err.Error(), &req.Id).Object()
+ setError(resp, -32603, err.Error())
}
resps.Call("push", resp)
}
@@ -300,12 +297,8 @@ func (b *bridge) Send(call otto.FunctionCall) (response otto.Value) {
return response
}
-func newErrorResponse(call otto.FunctionCall, code int, msg string, id interface{}) otto.Value {
- // Bundle the error into a JSON RPC call response
- m := map[string]interface{}{"version": "2.0", "id": id, "error": map[string]interface{}{"code": code, msg: msg}}
- res, _ := json.Marshal(m)
- val, _ := call.Otto.Run("(" + string(res) + ")")
- return val
+func setError(resp *otto.Object, code int, msg string) {
+ resp.Set("error", map[string]interface{}{"code": code, "message": msg})
}
// throwJSException panics on an otto.Value. The Otto VM will recover from the
diff --git a/console/console.go b/console/console.go
index 6e3d7e43c..8865f5e89 100644
--- a/console/console.go
+++ b/console/console.go
@@ -36,9 +36,9 @@ import (
)
var (
- passwordRegexp = regexp.MustCompile("personal.[nus]")
- onlyWhitespace = regexp.MustCompile("^\\s*$")
- exit = regexp.MustCompile("^\\s*exit\\s*;*\\s*$")
+ passwordRegexp = regexp.MustCompile(`personal.[nus]`)
+ onlyWhitespace = regexp.MustCompile(`^\s*$`)
+ exit = regexp.MustCompile(`^\s*exit\s*;*\s*$`)
)
// HistoryFile is the file within the data directory to store input scrollback.
@@ -275,10 +275,7 @@ func (c *Console) Evaluate(statement string) error {
fmt.Fprintf(c.printer, "[native] error: %v\n", r)
}
}()
- if err := c.jsre.Evaluate(statement, c.printer); err != nil {
- return err
- }
- return nil
+ return c.jsre.Evaluate(statement, c.printer)
}
// Interactive starts an interactive user session, where input is propted from
diff --git a/console/prompter.go b/console/prompter.go
index 5946d9ece..6acbfb0e2 100644
--- a/console/prompter.go
+++ b/console/prompter.go
@@ -44,7 +44,7 @@ type UserPrompter interface {
PromptConfirm(prompt string) (bool, error)
// SetHistory sets the the input scrollback history that the prompter will allow
- // the user to scoll back to.
+ // the user to scroll back to.
SetHistory(history []string)
// AppendHistory appends an entry to the scrollback history. It should be called
@@ -147,7 +147,7 @@ func (p *terminalPrompter) PromptConfirm(prompt string) (bool, error) {
}
// SetHistory sets the the input scrollback history that the prompter will allow
-// the user to scoll back to.
+// the user to scroll back to.
func (p *terminalPrompter) SetHistory(history []string) {
p.State.ReadHistory(strings.NewReader(strings.Join(history, "\n")))
}