aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/jeth.go
diff options
context:
space:
mode:
authorBas van Kervel <bas@ethdev.com>2015-10-15 22:07:19 +0800
committerBas van Kervel <bas@ethdev.com>2015-12-14 23:34:05 +0800
commiteae81465c1c815c317cd30e4de6bdf4d59df2340 (patch)
treeb6f4b7787967a58416171adb79fd12ac29d89577 /rpc/jeth.go
parent8db9d44ca9fb6baf406256cae491c475de2f4989 (diff)
downloaddexon-eae81465c1c815c317cd30e4de6bdf4d59df2340.tar.gz
dexon-eae81465c1c815c317cd30e4de6bdf4d59df2340.tar.zst
dexon-eae81465c1c815c317cd30e4de6bdf4d59df2340.zip
rpc: new RPC implementation with pub/sub support
Diffstat (limited to 'rpc/jeth.go')
-rw-r--r--rpc/jeth.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/rpc/jeth.go b/rpc/jeth.go
index 1260a3404..de7dd1e76 100644
--- a/rpc/jeth.go
+++ b/rpc/jeth.go
@@ -54,6 +54,78 @@ func (self *Jeth) err(call otto.FunctionCall, code int, msg string, id interface
return res
}
+// UnlockAccount asks the user for the password and than executes the jeth.UnlockAccount callback in the jsre
+func (self *Jeth) UnlockAccount(call otto.FunctionCall) (response otto.Value) {
+ var cmd, account, passwd string
+ timeout := int64(300)
+ var ok bool
+
+ if len(call.ArgumentList) == 0 {
+ fmt.Println("expected address of account to unlock")
+ return otto.FalseValue()
+ }
+
+ if len(call.ArgumentList) >= 1 {
+ if accountExport, err := call.Argument(0).Export(); err == nil {
+ if account, ok = accountExport.(string); ok {
+ if len(call.ArgumentList) == 1 {
+ fmt.Printf("Unlock account %s\n", account)
+ passwd, err = utils.PromptPassword("Passphrase: ", true)
+ if err != nil {
+ return otto.FalseValue()
+ }
+ }
+ }
+ }
+ }
+ if len(call.ArgumentList) >= 2 {
+ if passwdExport, err := call.Argument(1).Export(); err == nil {
+ passwd, _ = passwdExport.(string)
+ }
+ }
+
+ if len(call.ArgumentList) >= 3 {
+ if timeoutExport, err := call.Argument(2).Export(); err == nil {
+ timeout, _ = timeoutExport.(int64)
+ }
+ }
+
+ cmd = fmt.Sprintf("jeth.unlockAccount('%s', '%s', %d)", account, passwd, timeout)
+ if val, err := call.Otto.Run(cmd); err == nil {
+ return val
+ }
+
+ return otto.FalseValue()
+}
+
+// NewAccount asks the user for the password and than executes the jeth.newAccount callback in the jsre
+func (self *Jeth) NewAccount(call otto.FunctionCall) (response otto.Value) {
+ if len(call.ArgumentList) == 0 {
+ passwd, err := utils.PromptPassword("Passphrase: ", true)
+ if err != nil {
+ return otto.FalseValue()
+ }
+ passwd2, err := utils.PromptPassword("Repeat passphrase: ", true)
+ if err != nil {
+ return otto.FalseValue()
+ }
+
+ if passwd != passwd2 {
+ fmt.Println("Passphrases don't match")
+ return otto.FalseValue()
+ }
+
+ cmd := fmt.Sprintf("jeth.newAccount('%s')", passwd)
+ if val, err := call.Otto.Run(cmd); err == nil {
+ return val
+ }
+ } else {
+ fmt.Println("New account doesn't expect argument(s), you will be prompted for a password")
+ }
+
+ return otto.FalseValue()
+}
+
func (self *Jeth) Send(call otto.FunctionCall) (response otto.Value) {
reqif, err := call.Argument(0).Export()
if err != nil {