aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2015-11-03 18:47:07 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-11-03 18:47:07 +0800
commite5532154a50114d5ffb1ffd850b746cab00cb899 (patch)
tree0042cc997ccf4166b9b52464339d52d37d7a8ad6 /rpc
parent9666db2a442887ccf8ec2d81f5e2fedc1a3a3d3e (diff)
parentf75becc264f8bde0f58391fc226243d03e78aa7b (diff)
downloadgo-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.tar
go-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.tar.gz
go-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.tar.bz2
go-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.tar.lz
go-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.tar.xz
go-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.tar.zst
go-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.zip
Merge branch 'release/1.3.0'
Conflicts: VERSION cmd/geth/main.go
Diffstat (limited to 'rpc')
-rw-r--r--rpc/api/admin.go15
-rw-r--r--rpc/api/debug.go14
-rw-r--r--rpc/api/eth.go18
-rw-r--r--rpc/api/eth_args.go22
-rw-r--r--rpc/api/eth_js.go6
-rw-r--r--rpc/api/miner.go2
-rw-r--r--rpc/api/parsing.go4
-rw-r--r--rpc/api/personal.go17
-rw-r--r--rpc/api/personal_args.go17
-rw-r--r--rpc/api/utils.go8
-rw-r--r--rpc/comms/comms.go11
-rw-r--r--rpc/comms/ipc.go43
-rw-r--r--rpc/comms/ipc_unix.go40
-rw-r--r--rpc/comms/ipc_windows.go36
-rw-r--r--rpc/jeth.go2
-rw-r--r--rpc/useragent/remote_frontend.go25
16 files changed, 162 insertions, 118 deletions
diff --git a/rpc/api/admin.go b/rpc/api/admin.go
index 8af69b189..eb08fbc5d 100644
--- a/rpc/api/admin.go
+++ b/rpc/api/admin.go
@@ -25,7 +25,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/compiler"
- "github.com/ethereum/go-ethereum/common/docserver"
"github.com/ethereum/go-ethereum/common/natspec"
"github.com/ethereum/go-ethereum/common/registrar"
"github.com/ethereum/go-ethereum/core"
@@ -84,7 +83,6 @@ type adminApi struct {
ethereum *eth.Ethereum
codec codec.Codec
coder codec.ApiCoder
- ds *docserver.DocServer
}
// create a new admin api instance
@@ -94,7 +92,6 @@ func NewAdminApi(xeth *xeth.XEth, ethereum *eth.Ethereum, codec codec.Codec) *ad
ethereum: ethereum,
codec: codec,
coder: codec.New(nil),
- ds: docserver.New("/"),
}
}
@@ -151,7 +148,7 @@ func (self *adminApi) DataDir(req *shared.Request) (interface{}, error) {
return self.ethereum.DataDir, nil
}
-func hasAllBlocks(chain *core.ChainManager, bs []*types.Block) bool {
+func hasAllBlocks(chain *core.BlockChain, bs []*types.Block) bool {
for _, b := range bs {
if !chain.HasBlock(b.Hash()) {
return false
@@ -193,10 +190,10 @@ func (self *adminApi) ImportChain(req *shared.Request) (interface{}, error) {
break
}
// Import the batch.
- if hasAllBlocks(self.ethereum.ChainManager(), blocks[:i]) {
+ if hasAllBlocks(self.ethereum.BlockChain(), blocks[:i]) {
continue
}
- if _, err := self.ethereum.ChainManager().InsertChain(blocks[:i]); err != nil {
+ if _, err := self.ethereum.BlockChain().InsertChain(blocks[:i]); err != nil {
return false, fmt.Errorf("invalid block %d: %v", n, err)
}
}
@@ -214,7 +211,7 @@ func (self *adminApi) ExportChain(req *shared.Request) (interface{}, error) {
return false, err
}
defer fh.Close()
- if err := self.ethereum.ChainManager().Export(fh); err != nil {
+ if err := self.ethereum.BlockChain().Export(fh); err != nil {
return false, err
}
@@ -437,7 +434,7 @@ func (self *adminApi) GetContractInfo(req *shared.Request) (interface{}, error)
return nil, shared.NewDecodeParamError(err.Error())
}
- infoDoc, err := natspec.FetchDocsForContract(args.Contract, self.xeth, self.ds)
+ infoDoc, err := natspec.FetchDocsForContract(args.Contract, self.xeth, self.ethereum.HTTPClient())
if err != nil {
return nil, err
}
@@ -457,7 +454,7 @@ func (self *adminApi) HttpGet(req *shared.Request) (interface{}, error) {
return nil, shared.NewDecodeParamError(err.Error())
}
- resp, err := self.ds.Get(args.Uri, args.Path)
+ resp, err := self.ethereum.HTTPClient().Get(args.Uri, args.Path)
if err != nil {
return nil, err
}
diff --git a/rpc/api/debug.go b/rpc/api/debug.go
index d325b1720..d2cbc7f19 100644
--- a/rpc/api/debug.go
+++ b/rpc/api/debug.go
@@ -119,9 +119,9 @@ func (self *debugApi) DumpBlock(req *shared.Request) (interface{}, error) {
return nil, fmt.Errorf("block #%d not found", args.BlockNumber)
}
- stateDb := state.New(block.Root(), self.ethereum.ChainDb())
- if stateDb == nil {
- return nil, nil
+ stateDb, err := state.New(block.Root(), self.ethereum.ChainDb())
+ if err != nil {
+ return nil, err
}
return stateDb.RawDump(), nil
@@ -146,13 +146,7 @@ func (self *debugApi) SetHead(req *shared.Request) (interface{}, error) {
if err := self.codec.Decode(req.Params, &args); err != nil {
return nil, shared.NewDecodeParamError(err.Error())
}
-
- block := self.xeth.EthBlockByNumber(args.BlockNumber)
- if block == nil {
- return nil, fmt.Errorf("block #%d not found", args.BlockNumber)
- }
-
- self.ethereum.ChainManager().SetHead(block)
+ self.ethereum.BlockChain().SetHead(uint64(args.BlockNumber))
return nil, nil
}
diff --git a/rpc/api/eth.go b/rpc/api/eth.go
index 4cd5f2695..b84ae31da 100644
--- a/rpc/api/eth.go
+++ b/rpc/api/eth.go
@@ -24,6 +24,7 @@ import (
"fmt"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/common/natspec"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
@@ -67,6 +68,7 @@ var (
"eth_getUncleCountByBlockNumber": (*ethApi).GetUncleCountByBlockNumber,
"eth_getData": (*ethApi).GetData,
"eth_getCode": (*ethApi).GetData,
+ "eth_getNatSpec": (*ethApi).GetNatSpec,
"eth_sign": (*ethApi).Sign,
"eth_sendRawTransaction": (*ethApi).SendRawTransaction,
"eth_sendTransaction": (*ethApi).SendTransaction,
@@ -168,9 +170,7 @@ func (self *ethApi) IsMining(req *shared.Request) (interface{}, error) {
}
func (self *ethApi) IsSyncing(req *shared.Request) (interface{}, error) {
- current := self.ethereum.ChainManager().CurrentBlock().NumberU64()
- origin, height := self.ethereum.Downloader().Boundaries()
-
+ origin, current, height := self.ethereum.Downloader().Progress()
if current < height {
return map[string]interface{}{
"startingBlock": newHexNum(big.NewInt(int64(origin)).Bytes()),
@@ -324,6 +324,18 @@ func (self *ethApi) SendTransaction(req *shared.Request) (interface{}, error) {
return v, nil
}
+func (self *ethApi) GetNatSpec(req *shared.Request) (interface{}, error) {
+ args := new(NewTxArgs)
+ if err := self.codec.Decode(req.Params, &args); err != nil {
+ return nil, shared.NewDecodeParamError(err.Error())
+ }
+
+ var jsontx = fmt.Sprintf(`{"params":[{"to":"%s","data": "%s"}]}`, args.To, args.Data)
+ notice := natspec.GetNotice(self.xeth, jsontx, self.ethereum.HTTPClient())
+
+ return notice, nil
+}
+
func (self *ethApi) EstimateGas(req *shared.Request) (interface{}, error) {
_, gas, err := self.doCall(req.Params)
if err != nil {
diff --git a/rpc/api/eth_args.go b/rpc/api/eth_args.go
index 8bd077e20..457350d74 100644
--- a/rpc/api/eth_args.go
+++ b/rpc/api/eth_args.go
@@ -24,8 +24,8 @@ import (
"strings"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/rpc/shared"
)
@@ -626,7 +626,12 @@ func (args *GetBlockByHashArgs) UnmarshalJSON(b []byte) (err error) {
args.IncludeTxs = obj[1].(bool)
- return nil
+ if inclTx, ok := obj[1].(bool); ok {
+ args.IncludeTxs = inclTx
+ return nil
+ }
+
+ return shared.NewInvalidTypeError("includeTxs", "not a bool")
}
type GetBlockByNumberArgs struct {
@@ -648,9 +653,12 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
return err
}
- args.IncludeTxs = obj[1].(bool)
+ if inclTx, ok := obj[1].(bool); ok {
+ args.IncludeTxs = inclTx
+ return nil
+ }
- return nil
+ return shared.NewInvalidTypeError("includeTxs", "not a bool")
}
type BlockFilterArgs struct {
@@ -830,7 +838,7 @@ type LogRes struct {
TransactionIndex *hexnum `json:"transactionIndex"`
}
-func NewLogRes(log *state.Log) LogRes {
+func NewLogRes(log *vm.Log) LogRes {
var l LogRes
l.Topics = make([]*hexdata, len(log.Topics))
for j, topic := range log.Topics {
@@ -838,7 +846,7 @@ func NewLogRes(log *state.Log) LogRes {
}
l.Address = newHexData(log.Address)
l.Data = newHexData(log.Data)
- l.BlockNumber = newHexNum(log.Number)
+ l.BlockNumber = newHexNum(log.BlockNumber)
l.LogIndex = newHexNum(log.Index)
l.TransactionHash = newHexData(log.TxHash)
l.TransactionIndex = newHexNum(log.TxIndex)
@@ -847,7 +855,7 @@ func NewLogRes(log *state.Log) LogRes {
return l
}
-func NewLogsRes(logs state.Logs) (ls []LogRes) {
+func NewLogsRes(logs vm.Logs) (ls []LogRes) {
ls = make([]LogRes, len(logs))
for i, log := range logs {
diff --git a/rpc/api/eth_js.go b/rpc/api/eth_js.go
index 393dac22f..75c103c9d 100644
--- a/rpc/api/eth_js.go
+++ b/rpc/api/eth_js.go
@@ -35,6 +35,12 @@ web3._extend({
call: 'eth_resend',
params: 3,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
+ }),
+ new web3._extend.Method({
+ name: 'getNatSpec',
+ call: 'eth_getNatSpec',
+ params: 1,
+ inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
})
],
properties:
diff --git a/rpc/api/miner.go b/rpc/api/miner.go
index 5325a660a..e07855dd2 100644
--- a/rpc/api/miner.go
+++ b/rpc/api/miner.go
@@ -100,7 +100,7 @@ func (self *minerApi) StartMiner(req *shared.Request) (interface{}, error) {
}
self.ethereum.StartAutoDAG()
- err := self.ethereum.StartMining(args.Threads)
+ err := self.ethereum.StartMining(args.Threads, "")
if err == nil {
return true, nil
}
diff --git a/rpc/api/parsing.go b/rpc/api/parsing.go
index cdfaa0ed1..7667616ff 100644
--- a/rpc/api/parsing.go
+++ b/rpc/api/parsing.go
@@ -453,8 +453,8 @@ func NewReceiptRes(rec *types.Receipt) *ReceiptRes {
v.ContractAddress = newHexData(rec.ContractAddress)
}
- logs := make([]interface{}, len(rec.Logs()))
- for i, log := range rec.Logs() {
+ logs := make([]interface{}, len(rec.Logs))
+ for i, log := range rec.Logs {
logs[i] = NewLogRes(log)
}
v.Logs = &logs
diff --git a/rpc/api/personal.go b/rpc/api/personal.go
index 1fb412612..4f347c610 100644
--- a/rpc/api/personal.go
+++ b/rpc/api/personal.go
@@ -98,9 +98,22 @@ func (self *personalApi) NewAccount(req *shared.Request) (interface{}, error) {
if err := self.codec.Decode(req.Params, &args); err != nil {
return nil, shared.NewDecodeParamError(err.Error())
}
-
+ var passwd string
+ if args.Passphrase == nil {
+ fe := self.xeth.Frontend()
+ if fe == nil {
+ return false, fmt.Errorf("unable to create account: unable to interact with user")
+ }
+ var ok bool
+ passwd, ok = fe.AskPassword()
+ if !ok {
+ return false, fmt.Errorf("unable to create account: no password given")
+ }
+ } else {
+ passwd = *args.Passphrase
+ }
am := self.ethereum.AccountManager()
- acc, err := am.NewAccount(args.Passphrase)
+ acc, err := am.NewAccount(passwd)
return acc.Address.Hex(), err
}
diff --git a/rpc/api/personal_args.go b/rpc/api/personal_args.go
index 73dc6285e..5d215c71d 100644
--- a/rpc/api/personal_args.go
+++ b/rpc/api/personal_args.go
@@ -23,7 +23,7 @@ import (
)
type NewAccountArgs struct {
- Passphrase string
+ Passphrase *string
}
func (args *NewAccountArgs) UnmarshalJSON(b []byte) (err error) {
@@ -32,16 +32,15 @@ func (args *NewAccountArgs) UnmarshalJSON(b []byte) (err error) {
return shared.NewDecodeParamError(err.Error())
}
- if len(obj) < 1 {
- return shared.NewInsufficientParamsError(len(obj), 1)
- }
-
- if passhrase, ok := obj[0].(string); ok {
- args.Passphrase = passhrase
- return nil
+ if len(obj) >= 1 && obj[0] != nil {
+ if passphrasestr, ok := obj[0].(string); ok {
+ args.Passphrase = &passphrasestr
+ } else {
+ return shared.NewInvalidTypeError("passphrase", "not a string")
+ }
}
- return shared.NewInvalidTypeError("passhrase", "not a string")
+ return nil
}
type UnlockAccountArgs struct {
diff --git a/rpc/api/utils.go b/rpc/api/utils.go
index 76b2c531d..5a3ade46b 100644
--- a/rpc/api/utils.go
+++ b/rpc/api/utils.go
@@ -33,14 +33,21 @@ var (
"admin": []string{
"addPeer",
"datadir",
+ "enableUserAgent",
"exportChain",
"getContractInfo",
+ "httpGet",
"importChain",
"nodeInfo",
"peers",
"register",
"registerUrl",
+ "saveInfo",
+ "setGlobalRegistrar",
+ "setHashReg",
+ "setUrlHint",
"setSolc",
+ "sleep",
"sleepBlocks",
"startNatSpec",
"startRPC",
@@ -82,6 +89,7 @@ var (
"getBlockTransactionCount",
"getBlockUncleCount",
"getCode",
+ "getNatSpec",
"getCompilers",
"gasPrice",
"getStorageAt",
diff --git a/rpc/comms/comms.go b/rpc/comms/comms.go
index 731b2f62e..61fba5722 100644
--- a/rpc/comms/comms.go
+++ b/rpc/comms/comms.go
@@ -62,13 +62,18 @@ type EthereumClient interface {
func handle(id int, conn net.Conn, api shared.EthereumApi, c codec.Codec) {
codec := c.New(conn)
+ defer func() {
+ if r := recover(); r != nil {
+ glog.Errorf("panic: %v\n", r)
+ }
+ codec.Close()
+ }()
+
for {
requests, isBatch, err := codec.ReadRequest()
if err == io.EOF {
- codec.Close()
return
} else if err != nil {
- codec.Close()
glog.V(logger.Debug).Infof("Closed IPC Conn %06d recv err - %v\n", id, err)
return
}
@@ -87,7 +92,6 @@ func handle(id int, conn net.Conn, api shared.EthereumApi, c codec.Codec) {
err = codec.WriteResponse(responses[:responseCount])
if err != nil {
- codec.Close()
glog.V(logger.Debug).Infof("Closed IPC Conn %06d send err - %v\n", id, err)
return
}
@@ -98,7 +102,6 @@ func handle(id int, conn net.Conn, api shared.EthereumApi, c codec.Codec) {
rpcResponse = shared.NewRpcResponse(requests[0].Id, requests[0].Jsonrpc, res, err)
err = codec.WriteResponse(rpcResponse)
if err != nil {
- codec.Close()
glog.V(logger.Debug).Infof("Closed IPC Conn %06d send err - %v\n", id, err)
return
}
diff --git a/rpc/comms/ipc.go b/rpc/comms/ipc.go
index 3de659b65..882d62ab4 100644
--- a/rpc/comms/ipc.go
+++ b/rpc/comms/ipc.go
@@ -20,13 +20,22 @@ import (
"fmt"
"math/rand"
"net"
+ "os"
"encoding/json"
+ "github.com/ethereum/go-ethereum/logger"
+ "github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
)
+type Stopper interface {
+ Stop()
+}
+
+type InitFunc func(conn net.Conn) (Stopper, shared.EthereumApi, error)
+
type IpcConfig struct {
Endpoint string
}
@@ -90,8 +99,38 @@ func NewIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) {
}
// Start IPC server
-func StartIpc(cfg IpcConfig, codec codec.Codec, initializer func(conn net.Conn) (shared.EthereumApi, error)) error {
- return startIpc(cfg, codec, initializer)
+func StartIpc(cfg IpcConfig, codec codec.Codec, initializer InitFunc) error {
+ l, err := ipcListen(cfg)
+ if err != nil {
+ return err
+ }
+ go ipcLoop(cfg, codec, initializer, l)
+ return nil
+}
+
+func ipcLoop(cfg IpcConfig, codec codec.Codec, initializer InitFunc, l net.Listener) {
+ glog.V(logger.Info).Infof("IPC service started (%s)\n", cfg.Endpoint)
+ defer os.Remove(cfg.Endpoint)
+ defer l.Close()
+ for {
+ conn, err := l.Accept()
+ if err != nil {
+ glog.V(logger.Debug).Infof("accept: %v", err)
+ return
+ }
+ id := newIpcConnId()
+ go func() {
+ defer conn.Close()
+ glog.V(logger.Debug).Infof("new connection with id %06d started", id)
+ stopper, api, err := initializer(conn)
+ if err != nil {
+ glog.V(logger.Error).Infof("Unable to initialize IPC connection: %v", err)
+ return
+ }
+ defer stopper.Stop()
+ handle(id, conn, api, codec)
+ }()
+ }
}
func newIpcConnId() int {
diff --git a/rpc/comms/ipc_unix.go b/rpc/comms/ipc_unix.go
index d68363a45..4b839572a 100644
--- a/rpc/comms/ipc_unix.go
+++ b/rpc/comms/ipc_unix.go
@@ -23,8 +23,6 @@ import (
"os"
"path/filepath"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/rpc/useragent"
@@ -69,44 +67,16 @@ func (self *ipcClient) reconnect() error {
return err
}
-func startIpc(cfg IpcConfig, codec codec.Codec, initializer func(conn net.Conn) (shared.EthereumApi, error)) error {
+func ipcListen(cfg IpcConfig) (net.Listener, error) {
// Ensure the IPC path exists and remove any previous leftover
if err := os.MkdirAll(filepath.Dir(cfg.Endpoint), 0751); err != nil {
- return err
+ return nil, err
}
os.Remove(cfg.Endpoint)
-
- l, err := net.ListenUnix("unix", &net.UnixAddr{Name: cfg.Endpoint, Net: "unix"})
+ l, err := net.Listen("unix", cfg.Endpoint)
if err != nil {
- return err
+ return nil, err
}
os.Chmod(cfg.Endpoint, 0600)
-
- go func() {
- for {
- conn, err := l.AcceptUnix()
- if err != nil {
- glog.V(logger.Error).Infof("Error accepting ipc connection - %v\n", err)
- continue
- }
-
- id := newIpcConnId()
- glog.V(logger.Debug).Infof("New IPC connection with id %06d started\n", id)
-
- api, err := initializer(conn)
- if err != nil {
- glog.V(logger.Error).Infof("Unable to initialize IPC connection - %v\n", err)
- conn.Close()
- continue
- }
-
- go handle(id, conn, api, codec)
- }
-
- os.Remove(cfg.Endpoint)
- }()
-
- glog.V(logger.Info).Infof("IPC service started (%s)\n", cfg.Endpoint)
-
- return nil
+ return l, nil
}
diff --git a/rpc/comms/ipc_windows.go b/rpc/comms/ipc_windows.go
index 47edd9e5b..e25fba253 100644
--- a/rpc/comms/ipc_windows.go
+++ b/rpc/comms/ipc_windows.go
@@ -28,8 +28,6 @@ import (
"time"
"unsafe"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/rpc/useragent"
@@ -688,40 +686,12 @@ func (self *ipcClient) reconnect() error {
return err
}
-func startIpc(cfg IpcConfig, codec codec.Codec, initializer func(conn net.Conn) (shared.EthereumApi, error)) error {
+func ipcListen(cfg IpcConfig) (net.Listener, error) {
os.Remove(cfg.Endpoint) // in case it still exists from a previous run
-
l, err := Listen(cfg.Endpoint)
if err != nil {
- return err
+ return nil, err
}
os.Chmod(cfg.Endpoint, 0600)
-
- go func() {
- for {
- conn, err := l.Accept()
- if err != nil {
- glog.V(logger.Error).Infof("Error accepting ipc connection - %v\n", err)
- continue
- }
-
- id := newIpcConnId()
- glog.V(logger.Debug).Infof("New IPC connection with id %06d started\n", id)
-
- api, err := initializer(conn)
- if err != nil {
- glog.V(logger.Error).Infof("Unable to initialize IPC connection - %v\n", err)
- conn.Close()
- continue
- }
-
- go handle(id, conn, api, codec)
- }
-
- os.Remove(cfg.Endpoint)
- }()
-
- glog.V(logger.Info).Infof("IPC service started (%s)\n", cfg.Endpoint)
-
- return nil
+ return l, nil
}
diff --git a/rpc/jeth.go b/rpc/jeth.go
index ae2603ae4..1260a3404 100644
--- a/rpc/jeth.go
+++ b/rpc/jeth.go
@@ -158,11 +158,11 @@ func (self *Jeth) askPassword(id interface{}, jsonrpc string, args []interface{}
if len(args) >= 1 {
if account, ok := args[0].(string); ok {
fmt.Printf("Unlock account %s\n", account)
- passwd, err = utils.PromptPassword("Passphrase: ", true)
} else {
return false
}
}
+ passwd, err = utils.PromptPassword("Passphrase: ", true)
if err = self.client.Send(shared.NewRpcResponse(id, jsonrpc, passwd, err)); err != nil {
glog.V(logger.Info).Infof("Unable to send user agent ask password response - %v\n", err)
diff --git a/rpc/useragent/remote_frontend.go b/rpc/useragent/remote_frontend.go
index 0dd4a6049..944ab287a 100644
--- a/rpc/useragent/remote_frontend.go
+++ b/rpc/useragent/remote_frontend.go
@@ -49,6 +49,31 @@ func (fe *RemoteFrontend) Enable() {
fe.enabled = true
}
+func (fe *RemoteFrontend) AskPassword() (string, bool) {
+ if !fe.enabled {
+ return "", false
+ }
+
+ err := fe.send(AskPasswordMethod)
+ if err != nil {
+ glog.V(logger.Error).Infof("Unable to send password request to agent - %v\n", err)
+ return "", false
+ }
+
+ passwdRes, err := fe.recv()
+ if err != nil {
+ glog.V(logger.Error).Infof("Unable to recv password response from agent - %v\n", err)
+ return "", false
+ }
+
+ if passwd, ok := passwdRes.Result.(string); ok {
+ return passwd, true
+ }
+
+ return "", false
+
+}
+
// UnlockAccount asks the user agent for the user password and tries to unlock the account.
// It will try 3 attempts before giving up.
func (fe *RemoteFrontend) UnlockAccount(address []byte) bool {