@@ -58,7 +58,7 @@ func (self *Jeth) err(call otto.FunctionCall, code int, msg string, id *int64) (
5858
5959// UnlockAccount asks the user for the password and than executes the jeth.UnlockAccount callback in the jsre
6060func (self * Jeth ) UnlockAccount (call otto.FunctionCall ) (response otto.Value ) {
61- var cmd , account , passwd string
61+ var account , passwd string
6262 timeout := int64 (300 )
6363 var ok bool
6464
@@ -92,8 +92,7 @@ func (self *Jeth) UnlockAccount(call otto.FunctionCall) (response otto.Value) {
9292 }
9393 }
9494
95- cmd = fmt .Sprintf ("jeth.unlockAccount('%s', '%s', %d)" , account , passwd , timeout )
96- if val , err := call .Otto .Run (cmd ); err == nil {
95+ if val , err := call .Otto .Call ("jeth.unlockAccount" , nil , account , passwd , timeout ); err == nil {
9796 return val
9897 }
9998
@@ -102,8 +101,10 @@ func (self *Jeth) UnlockAccount(call otto.FunctionCall) (response otto.Value) {
102101
103102// NewAccount asks the user for the password and than executes the jeth.newAccount callback in the jsre
104103func (self * Jeth ) NewAccount (call otto.FunctionCall ) (response otto.Value ) {
104+ var passwd string
105105 if len (call .ArgumentList ) == 0 {
106- passwd , err := PromptPassword ("Passphrase: " , true )
106+ var err error
107+ passwd , err = PromptPassword ("Passphrase: " , true )
107108 if err != nil {
108109 return otto .FalseValue ()
109110 }
@@ -116,13 +117,18 @@ func (self *Jeth) NewAccount(call otto.FunctionCall) (response otto.Value) {
116117 fmt .Println ("Passphrases don't match" )
117118 return otto .FalseValue ()
118119 }
120+ } else if len (call .ArgumentList ) == 1 && call .Argument (0 ).IsString () {
121+ passwd , _ = call .Argument (0 ).ToString ()
122+ } else {
123+ fmt .Println ("expected 0 or 1 string argument" )
124+ return otto .FalseValue ()
125+ }
119126
120- cmd := fmt .Sprintf ("jeth.newAccount('%s')" , passwd )
121- if val , err := call .Otto .Run (cmd ); err == nil {
122- return val
123- }
127+ if ret , err := call .Otto .Call ("jeth.newAccount" , nil , passwd ); err == nil {
128+ return ret
124129 } else {
125- fmt .Println ("New account doesn't expect argument(s), you will be prompted for a password" )
130+ fmt .Printf ("%v\n " , err )
131+ return otto .FalseValue ()
126132 }
127133
128134 return otto .FalseValue ()
0 commit comments