From 5023ce831c278d5479186f35f23e13914fc734c0 Mon Sep 17 00:00:00 2001 From: bluewebgeek Date: Tue, 19 Jun 2018 07:54:37 +0800 Subject: [PATCH 1/7] console: correct typo and add comments --- console/bridge.go | 22 +++++++++++++--------- console/console.go | 4 +--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/console/bridge.go b/console/bridge.go index b0b4d37985..f4ea936bd8 100644 --- a/console/bridge.go +++ b/console/bridge.go @@ -29,7 +29,7 @@ import ( "github.com/robertkrimen/otto" ) -// bridge is a collection of JavaScript utility methods to bride the .js runtime +// bridge is a collection of JavaScript utility methods to bridge the .js runtime // environment and the Go RPC connection backing the remote method calls. type bridge struct { client *rpc.Client // RPC client to execute Ethereum requests through @@ -56,7 +56,7 @@ func (b *bridge) NewAccount(call otto.FunctionCall) (response otto.Value) { err error ) switch { - // No password was specified, prompt the user for it + // No password was specified, prompt the user for it. case len(call.ArgumentList) == 0: if password, err = b.prompter.PromptPassword("Passphrase: "); err != nil { throwJSException(err.Error()) @@ -68,7 +68,7 @@ func (b *bridge) NewAccount(call otto.FunctionCall) (response otto.Value) { throwJSException("passphrases don't match!") } - // A single string password was specified, use that + // A single string password was specified, use that. case len(call.ArgumentList) == 1 && call.Argument(0).IsString(): password, _ = call.Argument(0).ToString() @@ -76,7 +76,7 @@ func (b *bridge) NewAccount(call otto.FunctionCall) (response otto.Value) { default: throwJSException("expected 0 or 1 string argument") } - // Password acquired, 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()) @@ -87,18 +87,21 @@ func (b *bridge) NewAccount(call otto.FunctionCall) (response otto.Value) { // OpenWallet is a wrapper around personal.openWallet which can interpret and // react to certain error messages, such as the Trezor PIN matrix request. func (b *bridge) OpenWallet(call otto.FunctionCall) (response otto.Value) { - // Make sure we have a wallet specified to open + // Make sure we have a wallet specified to open. if !call.Argument(0).IsString() { throwJSException("first argument must be the wallet URL to open") } wallet := call.Argument(0) + // If password is not given or is the null value, set the password to + // blank which is digestible by otto/JavaScript. var passwd otto.Value if call.Argument(1).IsUndefined() || call.Argument(1).IsNull() { passwd, _ = otto.ToValue("") } else { passwd = call.Argument(1) } + // Open the wallet and return if successful in itself val, err := call.Otto.Call("jeth.openWallet", nil, wallet, passwd) if err == nil { @@ -162,7 +165,7 @@ func (b *bridge) UnlockAccount(call otto.FunctionCall) (response otto.Value) { } duration = call.Argument(2) } - // Send the request to the backend and return + // Send the request to the backend and return. val, err := call.Otto.Call("jeth.unlockAccount", nil, account, passwd, duration) if err != nil { throwJSException(err.Error()) @@ -180,6 +183,7 @@ func (b *bridge) Sign(call otto.FunctionCall) (response otto.Value) { passwd = call.Argument(2) ) + // Make sure the first and second arguments are strings. if !message.IsString() { throwJSException("first argument must be the message to sign") } @@ -187,7 +191,7 @@ func (b *bridge) Sign(call otto.FunctionCall) (response otto.Value) { throwJSException("second argument must be the account to sign with") } - // if the password is not given or null ask the user and ensure password is a string + // If the password is not given or null ask the user and ensure password is a string if passwd.IsUndefined() || passwd.IsNull() { fmt.Fprintf(b.printer, "Give password for account %s\n", account) if input, err := b.prompter.PromptPassword("Passphrase: "); err != nil { @@ -271,7 +275,7 @@ func (b *bridge) SleepBlocks(call otto.FunctionCall) (response otto.Value) { } type jsonrpcCall struct { - ID int64 + Id int64 Method string Params []interface{} } @@ -304,7 +308,7 @@ func (b *bridge) Send(call otto.FunctionCall) (response otto.Value) { resps, _ := call.Otto.Object("new Array()") for _, req := range reqs { resp, _ := call.Otto.Object(`({"jsonrpc":"2.0"})`) - resp.Set("id", req.ID) + resp.Set("id", req.Id) var result json.RawMessage err = b.client.Call(&result, req.Method, req.Params...) switch err := err.(type) { diff --git a/console/console.go b/console/console.go index 56e03837ac..b280d4e65d 100644 --- a/console/console.go +++ b/console/console.go @@ -60,7 +60,7 @@ type Config struct { Preload []string // Absolute paths to JavaScript files to preload } -// Console is a JavaScript interpreted runtime environment. It is a fully fledged +// Console is a JavaScript interpreted runtime environment. It is a fully fleged // JavaScript console attached to a running node via an external or in-process RPC // client. type Console struct { @@ -73,8 +73,6 @@ type Console struct { printer io.Writer // Output writer to serialize any display strings to } -// New initializes a JavaScript interpreted runtime environment and sets defaults -// with the config struct. func New(config Config) (*Console, error) { // Handle unset config values gracefully if config.Prompter == nil { From 8471b88deabdec8e20359b75dfcabcf4220addc6 Mon Sep 17 00:00:00 2001 From: bluewebgeek Date: Tue, 19 Jun 2018 08:02:22 +0800 Subject: [PATCH 2/7] console: correct typo and add comments --- console/console.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/console/console.go b/console/console.go index b280d4e65d..3428fa244e 100644 --- a/console/console.go +++ b/console/console.go @@ -31,7 +31,6 @@ import ( "github.com/ethereum/go-ethereum/internal/jsre" "github.com/ethereum/go-ethereum/internal/web3ext" "github.com/ethereum/go-ethereum/rpc" - "github.com/mattn/go-colorable" "github.com/peterh/liner" "github.com/robertkrimen/otto" ) @@ -73,6 +72,8 @@ type Console struct { printer io.Writer // Output writer to serialize any display strings to } +// New initializes a JavaScript interpreted runtime environment and sets defaults +// with the config struct. func New(config Config) (*Console, error) { // Handle unset config values gracefully if config.Prompter == nil { From 385f77588476d21ea4f38141a164a6220c8cee96 Mon Sep 17 00:00:00 2001 From: bluewebgeek Date: Tue, 19 Jun 2018 08:03:21 +0800 Subject: [PATCH 3/7] console: correct typo and add comments --- console/console.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/console/console.go b/console/console.go index 3428fa244e..26e9dd6c44 100644 --- a/console/console.go +++ b/console/console.go @@ -72,8 +72,8 @@ type Console struct { printer io.Writer // Output writer to serialize any display strings to } -// New initializes a JavaScript interpreted runtime environment and sets defaults -// with the config struct. +// New initializes a JavaScript interpreted runtime environment and sets defaults +// with the config struct. func New(config Config) (*Console, error) { // Handle unset config values gracefully if config.Prompter == nil { From ef2e28a625bac02681e3fe4392000d9c9a9debc3 Mon Sep 17 00:00:00 2001 From: bluewebgeek Date: Tue, 19 Jun 2018 08:05:42 +0800 Subject: [PATCH 4/7] console: correct typo and add comments --- console/console.go | 1 + 1 file changed, 1 insertion(+) diff --git a/console/console.go b/console/console.go index 26e9dd6c44..1bceb7bc65 100644 --- a/console/console.go +++ b/console/console.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/internal/jsre" "github.com/ethereum/go-ethereum/internal/web3ext" "github.com/ethereum/go-ethereum/rpc" + "github.com/mattn/go-colorable" "github.com/peterh/liner" "github.com/robertkrimen/otto" ) From f8124171ade4a988129e4655f31c00e3ddf7c634 Mon Sep 17 00:00:00 2001 From: Caesar Chad Date: Tue, 19 Jun 2018 21:37:13 +0800 Subject: [PATCH 5/7] console: typo and comment clean up --- console/console.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console/console.go b/console/console.go index 1bceb7bc65..56e03837ac 100644 --- a/console/console.go +++ b/console/console.go @@ -60,7 +60,7 @@ type Config struct { Preload []string // Absolute paths to JavaScript files to preload } -// Console is a JavaScript interpreted runtime environment. It is a fully fleged +// Console is a JavaScript interpreted runtime environment. It is a fully fledged // JavaScript console attached to a running node via an external or in-process RPC // client. type Console struct { From 3ae3201b3e01403e4f09169eb8287f29d7d8a7c7 Mon Sep 17 00:00:00 2001 From: Caesar Chad Date: Tue, 19 Jun 2018 21:38:49 +0800 Subject: [PATCH 6/7] console: typo and comments clean up --- console/bridge.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/console/bridge.go b/console/bridge.go index f4ea936bd8..1b2a30d7a0 100644 --- a/console/bridge.go +++ b/console/bridge.go @@ -37,7 +37,7 @@ type bridge struct { printer io.Writer // Output writer to serialize any display strings to } -// newBridge creates a new JavaScript wrapper around an RPC client. +// newBridge creates a new JavaScript wrapper around an RPC client func newBridge(client *rpc.Client, prompter UserPrompter, printer io.Writer) *bridge { return &bridge{ client: client, @@ -87,7 +87,7 @@ func (b *bridge) NewAccount(call otto.FunctionCall) (response otto.Value) { // OpenWallet is a wrapper around personal.openWallet which can interpret and // react to certain error messages, such as the Trezor PIN matrix request. func (b *bridge) OpenWallet(call otto.FunctionCall) (response otto.Value) { - // Make sure we have a wallet specified to open. + // Make sure we have a wallet specified to open if !call.Argument(0).IsString() { throwJSException("first argument must be the wallet URL to open") } @@ -157,7 +157,7 @@ func (b *bridge) UnlockAccount(call otto.FunctionCall) (response otto.Value) { } passwd = call.Argument(1) } - // Third argument is the duration how long the account must be unlocked. + // Third argument is the duration how long the account must be unlocked duration := otto.NullValue() if call.Argument(2).IsDefined() && !call.Argument(2).IsNull() { if !call.Argument(2).IsNumber() { @@ -165,7 +165,7 @@ func (b *bridge) UnlockAccount(call otto.FunctionCall) (response otto.Value) { } duration = call.Argument(2) } - // Send the request to the backend and return. + // Send the request to the backend and return val, err := call.Otto.Call("jeth.unlockAccount", nil, account, passwd, duration) if err != nil { throwJSException(err.Error()) @@ -183,7 +183,7 @@ func (b *bridge) Sign(call otto.FunctionCall) (response otto.Value) { passwd = call.Argument(2) ) - // Make sure the first and second arguments are strings. + // Make sure the first and second arguments are strings if !message.IsString() { throwJSException("first argument must be the message to sign") } @@ -280,7 +280,7 @@ type jsonrpcCall struct { Params []interface{} } -// Send implements the web3 provider "send" method. +// Send implements the web3 provider "send" method func (b *bridge) Send(call otto.FunctionCall) (response otto.Value) { // Remarshal the request into a Go value. JSON, _ := call.Otto.Object("JSON") From c224da9220b674c65cba2e225da03d62edfa1643 Mon Sep 17 00:00:00 2001 From: Caesar Chad Date: Tue, 19 Jun 2018 21:41:59 +0800 Subject: [PATCH 7/7] console: typo and comments clean up --- console/bridge.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/console/bridge.go b/console/bridge.go index 1b2a30d7a0..56ce47a6a9 100644 --- a/console/bridge.go +++ b/console/bridge.go @@ -56,7 +56,7 @@ func (b *bridge) NewAccount(call otto.FunctionCall) (response otto.Value) { err error ) switch { - // No password was specified, prompt the user for it. + // No password was specified, prompt the user for it case len(call.ArgumentList) == 0: if password, err = b.prompter.PromptPassword("Passphrase: "); err != nil { throwJSException(err.Error()) @@ -68,7 +68,7 @@ func (b *bridge) NewAccount(call otto.FunctionCall) (response otto.Value) { throwJSException("passphrases don't match!") } - // A single string password was specified, use that. + // A single string password was specified, use that case len(call.ArgumentList) == 1 && call.Argument(0).IsString(): password, _ = call.Argument(0).ToString() @@ -76,7 +76,7 @@ func (b *bridge) NewAccount(call otto.FunctionCall) (response otto.Value) { default: throwJSException("expected 0 or 1 string argument") } - // Password acquired, 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())