aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api.go
diff options
context:
space:
mode:
authorDaniel A. Nagy <nagy.da@gmail.com>2015-05-11 18:47:14 +0800
committerDaniel A. Nagy <nagy.da@gmail.com>2015-05-11 18:47:14 +0800
commita9e1d38612cfde56c285a5de5b5bfe5326bdc9b5 (patch)
tree6c16d3e2b216fdf0027a477a8975c9052930e34a /rpc/api.go
parent1fe70a66ba2ef0f148affa7a72b4e65023474859 (diff)
parent5176fbc6faaa5e7f0305ad7f2b896c092781deaa (diff)
downloadgo-tangerine-a9e1d38612cfde56c285a5de5b5bfe5326bdc9b5.tar
go-tangerine-a9e1d38612cfde56c285a5de5b5bfe5326bdc9b5.tar.gz
go-tangerine-a9e1d38612cfde56c285a5de5b5bfe5326bdc9b5.tar.bz2
go-tangerine-a9e1d38612cfde56c285a5de5b5bfe5326bdc9b5.tar.lz
go-tangerine-a9e1d38612cfde56c285a5de5b5bfe5326bdc9b5.tar.xz
go-tangerine-a9e1d38612cfde56c285a5de5b5bfe5326bdc9b5.tar.zst
go-tangerine-a9e1d38612cfde56c285a5de5b5bfe5326bdc9b5.zip
Merge branch 'develop' of github.com:ethereum/go-ethereum into develop
Conflicts: rpc/jeth.go
Diffstat (limited to 'rpc/api.go')
-rw-r--r--rpc/api.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/rpc/api.go b/rpc/api.go
index 7fab589f2..309c161ad 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -450,10 +450,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 {
@@ -466,10 +474,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 {
@@ -478,6 +494,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 {
@@ -487,6 +507,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 {
@@ -495,6 +519,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 {
@@ -503,12 +531,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())