@@ -18,6 +18,7 @@ package console
18
18
19
19
import (
20
20
"encoding/json"
21
+ "errors"
21
22
"fmt"
22
23
"io"
23
24
"reflect"
@@ -77,18 +78,18 @@ func (b *bridge) NewAccount(call jsre.Call) (goja.Value, error) {
77
78
return nil , err
78
79
}
79
80
if password != confirm {
80
- return nil , fmt . Errorf ("passwords don't match!" )
81
+ return nil , errors . New ("passwords don't match!" )
81
82
}
82
83
// A single string password was specified, use that
83
84
case len (call .Arguments ) == 1 && call .Argument (0 ).ToString () != nil :
84
85
password = call .Argument (0 ).ToString ().String ()
85
86
default :
86
- return nil , fmt . Errorf ("expected 0 or 1 string argument" )
87
+ return nil , errors . New ("expected 0 or 1 string argument" )
87
88
}
88
89
// Password acquired, execute the call and return
89
90
newAccount , callable := goja .AssertFunction (getJeth (call .VM ).Get ("newAccount" ))
90
91
if ! callable {
91
- return nil , fmt . Errorf ("jeth.newAccount is not callable" )
92
+ return nil , errors . New ("jeth.newAccount is not callable" )
92
93
}
93
94
ret , err := newAccount (goja .Null (), call .VM .ToValue (password ))
94
95
if err != nil {
@@ -102,7 +103,7 @@ func (b *bridge) NewAccount(call jsre.Call) (goja.Value, error) {
102
103
func (b * bridge ) OpenWallet (call jsre.Call ) (goja.Value , error ) {
103
104
// Make sure we have a wallet specified to open
104
105
if call .Argument (0 ).ToObject (call .VM ).ClassName () != "String" {
105
- return nil , fmt . Errorf ("first argument must be the wallet URL to open" )
106
+ return nil , errors . New ("first argument must be the wallet URL to open" )
106
107
}
107
108
wallet := call .Argument (0 )
108
109
@@ -115,7 +116,7 @@ func (b *bridge) OpenWallet(call jsre.Call) (goja.Value, error) {
115
116
// Open the wallet and return if successful in itself
116
117
openWallet , callable := goja .AssertFunction (getJeth (call .VM ).Get ("openWallet" ))
117
118
if ! callable {
118
- return nil , fmt . Errorf ("jeth.openWallet is not callable" )
119
+ return nil , errors . New ("jeth.openWallet is not callable" )
119
120
}
120
121
val , err := openWallet (goja .Null (), wallet , passwd )
121
122
if err == nil {
@@ -198,7 +199,7 @@ func (b *bridge) readPassphraseAndReopenWallet(call jsre.Call) (goja.Value, erro
198
199
}
199
200
openWallet , callable := goja .AssertFunction (getJeth (call .VM ).Get ("openWallet" ))
200
201
if ! callable {
201
- return nil , fmt . Errorf ("jeth.openWallet is not callable" )
202
+ return nil , errors . New ("jeth.openWallet is not callable" )
202
203
}
203
204
return openWallet (goja .Null (), wallet , call .VM .ToValue (input ))
204
205
}
@@ -219,7 +220,7 @@ func (b *bridge) readPinAndReopenWallet(call jsre.Call) (goja.Value, error) {
219
220
}
220
221
openWallet , callable := goja .AssertFunction (getJeth (call .VM ).Get ("openWallet" ))
221
222
if ! callable {
222
- return nil , fmt . Errorf ("jeth.openWallet is not callable" )
223
+ return nil , errors . New ("jeth.openWallet is not callable" )
223
224
}
224
225
return openWallet (goja .Null (), wallet , call .VM .ToValue (input ))
225
226
}
@@ -230,13 +231,13 @@ func (b *bridge) readPinAndReopenWallet(call jsre.Call) (goja.Value, error) {
230
231
// the RPC call.
231
232
func (b * bridge ) UnlockAccount (call jsre.Call ) (goja.Value , error ) {
232
233
if len (call .Arguments ) < 1 {
233
- return nil , fmt . Errorf ("usage: unlockAccount(account, [ password, duration ])" )
234
+ return nil , errors . New ("usage: unlockAccount(account, [ password, duration ])" )
234
235
}
235
236
236
237
account := call .Argument (0 )
237
238
// Make sure we have an account specified to unlock.
238
239
if goja .IsUndefined (account ) || goja .IsNull (account ) || account .ExportType ().Kind () != reflect .String {
239
- return nil , fmt . Errorf ("first argument must be the account to unlock" )
240
+ return nil , errors . New ("first argument must be the account to unlock" )
240
241
}
241
242
242
243
// If password is not given or is the null value, prompt the user for it.
@@ -250,7 +251,7 @@ func (b *bridge) UnlockAccount(call jsre.Call) (goja.Value, error) {
250
251
passwd = call .VM .ToValue (input )
251
252
} else {
252
253
if call .Argument (1 ).ExportType ().Kind () != reflect .String {
253
- return nil , fmt . Errorf ("password must be a string" )
254
+ return nil , errors . New ("password must be a string" )
254
255
}
255
256
passwd = call .Argument (1 )
256
257
}
@@ -259,15 +260,15 @@ func (b *bridge) UnlockAccount(call jsre.Call) (goja.Value, error) {
259
260
duration := goja .Null ()
260
261
if ! goja .IsUndefined (call .Argument (2 )) && ! goja .IsNull (call .Argument (2 )) {
261
262
if ! isNumber (call .Argument (2 )) {
262
- return nil , fmt . Errorf ("unlock duration must be a number" )
263
+ return nil , errors . New ("unlock duration must be a number" )
263
264
}
264
265
duration = call .Argument (2 )
265
266
}
266
267
267
268
// Send the request to the backend and return.
268
269
unlockAccount , callable := goja .AssertFunction (getJeth (call .VM ).Get ("unlockAccount" ))
269
270
if ! callable {
270
- return nil , fmt . Errorf ("jeth.unlockAccount is not callable" )
271
+ return nil , errors . New ("jeth.unlockAccount is not callable" )
271
272
}
272
273
return unlockAccount (goja .Null (), account , passwd , duration )
273
274
}
@@ -277,7 +278,7 @@ func (b *bridge) UnlockAccount(call jsre.Call) (goja.Value, error) {
277
278
// jeth.sign) with it to actually execute the RPC call.
278
279
func (b * bridge ) Sign (call jsre.Call ) (goja.Value , error ) {
279
280
if nArgs := len (call .Arguments ); nArgs < 2 {
280
- return nil , fmt . Errorf ("usage: sign(message, account, [ password ])" )
281
+ return nil , errors . New ("usage: sign(message, account, [ password ])" )
281
282
}
282
283
var (
283
284
message = call .Argument (0 )
@@ -286,10 +287,10 @@ func (b *bridge) Sign(call jsre.Call) (goja.Value, error) {
286
287
)
287
288
288
289
if goja .IsUndefined (message ) || message .ExportType ().Kind () != reflect .String {
289
- return nil , fmt . Errorf ("first argument must be the message to sign" )
290
+ return nil , errors . New ("first argument must be the message to sign" )
290
291
}
291
292
if goja .IsUndefined (account ) || account .ExportType ().Kind () != reflect .String {
292
- return nil , fmt . Errorf ("second argument must be the account to sign with" )
293
+ return nil , errors . New ("second argument must be the account to sign with" )
293
294
}
294
295
295
296
// if the password is not given or null ask the user and ensure password is a string
@@ -301,25 +302,25 @@ func (b *bridge) Sign(call jsre.Call) (goja.Value, error) {
301
302
}
302
303
passwd = call .VM .ToValue (input )
303
304
} else if passwd .ExportType ().Kind () != reflect .String {
304
- return nil , fmt . Errorf ("third argument must be the password to unlock the account" )
305
+ return nil , errors . New ("third argument must be the password to unlock the account" )
305
306
}
306
307
307
308
// Send the request to the backend and return
308
309
sign , callable := goja .AssertFunction (getJeth (call .VM ).Get ("sign" ))
309
310
if ! callable {
310
- return nil , fmt . Errorf ("jeth.sign is not callable" )
311
+ return nil , errors . New ("jeth.sign is not callable" )
311
312
}
312
313
return sign (goja .Null (), message , account , passwd )
313
314
}
314
315
315
316
// Sleep will block the console for the specified number of seconds.
316
317
func (b * bridge ) Sleep (call jsre.Call ) (goja.Value , error ) {
317
318
if nArgs := len (call .Arguments ); nArgs < 1 {
318
- return nil , fmt . Errorf ("usage: sleep(<number of seconds>)" )
319
+ return nil , errors . New ("usage: sleep(<number of seconds>)" )
319
320
}
320
321
sleepObj := call .Argument (0 )
321
322
if goja .IsUndefined (sleepObj ) || goja .IsNull (sleepObj ) || ! isNumber (sleepObj ) {
322
- return nil , fmt . Errorf ("usage: sleep(<number of seconds>)" )
323
+ return nil , errors . New ("usage: sleep(<number of seconds>)" )
323
324
}
324
325
sleep := sleepObj .ToFloat ()
325
326
time .Sleep (time .Duration (sleep * float64 (time .Second )))
@@ -336,17 +337,17 @@ func (b *bridge) SleepBlocks(call jsre.Call) (goja.Value, error) {
336
337
)
337
338
nArgs := len (call .Arguments )
338
339
if nArgs == 0 {
339
- return nil , fmt . Errorf ("usage: sleepBlocks(<n blocks>[, max sleep in seconds])" )
340
+ return nil , errors . New ("usage: sleepBlocks(<n blocks>[, max sleep in seconds])" )
340
341
}
341
342
if nArgs >= 1 {
342
343
if goja .IsNull (call .Argument (0 )) || goja .IsUndefined (call .Argument (0 )) || ! isNumber (call .Argument (0 )) {
343
- return nil , fmt . Errorf ("expected number as first argument" )
344
+ return nil , errors . New ("expected number as first argument" )
344
345
}
345
346
blocks = call .Argument (0 ).ToInteger ()
346
347
}
347
348
if nArgs >= 2 {
348
349
if goja .IsNull (call .Argument (1 )) || goja .IsUndefined (call .Argument (1 )) || ! isNumber (call .Argument (1 )) {
349
- return nil , fmt . Errorf ("expected number as second argument" )
350
+ return nil , errors . New ("expected number as second argument" )
350
351
}
351
352
sleep = call .Argument (1 ).ToInteger ()
352
353
}
@@ -421,7 +422,7 @@ func (b *bridge) Send(call jsre.Call) (goja.Value, error) {
421
422
JSON := call .VM .Get ("JSON" ).ToObject (call .VM )
422
423
parse , callable := goja .AssertFunction (JSON .Get ("parse" ))
423
424
if ! callable {
424
- return nil , fmt . Errorf ("JSON.parse is not a function" )
425
+ return nil , errors . New ("JSON.parse is not a function" )
425
426
}
426
427
resultVal , err := parse (goja .Null (), call .VM .ToValue (string (result )))
427
428
if err != nil {
0 commit comments