From e94aa421c69b8eee2f2e06654f9a288cdfe4f546 Mon Sep 17 00:00:00 2001 From: "Daniel A. Nagy" Date: Fri, 8 May 2015 16:17:19 +0200 Subject: New API call for signatures. --- rpc/api.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 6ba0d93e2..28ba41c86 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -158,6 +158,17 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err v := api.xethAtStateNum(args.BlockNumber).CodeAtBytes(args.Address) *reply = newHexData(v) + case "eth_sign": + args := new(NewSigArgs) + if err := json.Unmarshal(req.Params, &args); err != nil { + return err + } + v, err := api.xeth.Sign(args.From, args.Data) + if err != nil { + return err + } + *reply = v + case "eth_sendTransaction", "eth_transact": args := new(NewTxArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit v1.2.3 From a487396b764c8dac409f9ee1ef32c29c4cefb7d9 Mon Sep 17 00:00:00 2001 From: "Daniel A. Nagy" Date: Fri, 8 May 2015 16:36:13 +0200 Subject: eth_sign added to API for signing arbitrary data. --- rpc/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 28ba41c86..7fab589f2 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -163,7 +163,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err if err := json.Unmarshal(req.Params, &args); err != nil { return err } - v, err := api.xeth.Sign(args.From, args.Data) + v, err := api.xeth().Sign(args.From, args.Data, false) if err != nil { return err } -- cgit v1.2.3 From 0ad5898c0f9b0d777818d89356b74606f4b3c988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 11 May 2015 11:53:53 +0300 Subject: rpc, xeth: fix #881, gracefully handle offline whisper --- rpc/api.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 6ba0d93e2..6a629ce8e 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -439,10 +439,18 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err *reply = newHexData(res) case "shh_version": + // Short circuit if whisper is not running + if api.xeth().Whisper() == nil { + return NewNotAvailableError(req.Method, "whisper offline") + } // Retrieves the currently running whisper protocol version *reply = api.xeth().WhisperVersion() case "shh_post": + // Short circuit if whisper is not running + if api.xeth().Whisper() == nil { + return NewNotAvailableError(req.Method, "whisper offline") + } // Injects a new message into the whisper network args := new(WhisperMessageArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -455,10 +463,18 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err *reply = true case "shh_newIdentity": + // Short circuit if whisper is not running + if api.xeth().Whisper() == nil { + return NewNotAvailableError(req.Method, "whisper offline") + } // Creates a new whisper identity to use for sending/receiving messages *reply = api.xeth().Whisper().NewIdentity() case "shh_hasIdentity": + // Short circuit if whisper is not running + if api.xeth().Whisper() == nil { + return NewNotAvailableError(req.Method, "whisper offline") + } // Checks if an identity if owned or not args := new(WhisperIdentityArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -467,6 +483,10 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err *reply = api.xeth().Whisper().HasIdentity(args.Identity) case "shh_newFilter": + // Short circuit if whisper is not running + if api.xeth().Whisper() == nil { + return NewNotAvailableError(req.Method, "whisper offline") + } // Create a new filter to watch and match messages with args := new(WhisperFilterArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -476,6 +496,10 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err *reply = newHexNum(big.NewInt(int64(id)).Bytes()) case "shh_uninstallFilter": + // Short circuit if whisper is not running + if api.xeth().Whisper() == nil { + return NewNotAvailableError(req.Method, "whisper offline") + } // Remove an existing filter watching messages args := new(FilterIdArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -484,6 +508,10 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err *reply = api.xeth().UninstallWhisperFilter(args.Id) case "shh_getFilterChanges": + // Short circuit if whisper is not running + if api.xeth().Whisper() == nil { + return NewNotAvailableError(req.Method, "whisper offline") + } // Retrieve all the new messages arrived since the last request args := new(FilterIdArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -492,12 +520,17 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err *reply = api.xeth().WhisperMessagesChanged(args.Id) case "shh_getMessages": + // Short circuit if whisper is not running + if api.xeth().Whisper() == nil { + return NewNotAvailableError(req.Method, "whisper offline") + } // Retrieve all the cached messages matching a specific, existing filter args := new(FilterIdArgs) if err := json.Unmarshal(req.Params, &args); err != nil { return err } *reply = api.xeth().WhisperMessages(args.Id) + case "eth_hashrate": *reply = newHexNum(api.xeth().HashRate()) -- cgit v1.2.3 From 21e52efdfed19c4376b830f8ad0e52a9e599f633 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 11 May 2015 15:43:14 +0200 Subject: cmd/geth, miner, backend, xeth: Fixed miner threads to be settable Miner threads are now settable through the admin interface (closes #897) and specify 0 CPU worker threads when eth_getWork is called (closes #916) --- rpc/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 309c161ad..d53a9917d 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -391,7 +391,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err } *reply = NewLogsRes(api.xeth().AllLogs(args.Earliest, args.Latest, args.Skip, args.Max, args.Address, args.Topics)) case "eth_getWork": - api.xeth().SetMining(true) + api.xeth().SetMining(true, 0) *reply = api.xeth().RemoteMining().GetWork() case "eth_submitWork": args := new(SubmitWorkArgs) -- cgit v1.2.3 From 66de3f0aa849849c5cf5ad84265f3f3ce8ca5282 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 12 May 2015 14:14:08 +0200 Subject: xeth, rpc: implement eth_estimateGas. Closes #930 --- rpc/api.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index d53a9917d..774d26ea2 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -186,16 +186,24 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err return err } *reply = v - case "eth_call": - args := new(CallArgs) - if err := json.Unmarshal(req.Params, &args); err != nil { + case "eth_estimateGas": + _, gas, err := api.doCall(req.Params) + if err != nil { return err } - v, err := api.xethAtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) + // TODO unwrap the parent method's ToHex call + if len(gas) == 0 { + *reply = newHexData([]byte{}) + } else { + *reply = newHexData(gas) + } + case "eth_call": + v, _, err := api.doCall(req.Params) if err != nil { return err } + // TODO unwrap the parent method's ToHex call if v == "0x0" { *reply = newHexData([]byte{}) @@ -571,3 +579,12 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err glog.V(logger.Detail).Infof("Reply: %T %s\n", reply, reply) return nil } + +func (api *EthereumApi) doCall(params json.RawMessage) (string, string, error) { + args := new(CallArgs) + if err := json.Unmarshal(params, &args); err != nil { + return "", "", err + } + + return api.xethAtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) +} -- cgit v1.2.3 From 260536a729337e47646d6d72d19d2095b6d71f4c Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 12 May 2015 15:02:44 +0200 Subject: rpc: hexData => hexNum --- rpc/api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 774d26ea2..066c81222 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -194,9 +194,9 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err // TODO unwrap the parent method's ToHex call if len(gas) == 0 { - *reply = newHexData([]byte{}) + *reply = newHexNum(0) } else { - *reply = newHexData(gas) + *reply = newHexNum(gas) } case "eth_call": v, _, err := api.doCall(req.Params) -- cgit v1.2.3