@@ -439,10 +439,18 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
439439 * reply = newHexData (res )
440440
441441 case "shh_version" :
442+ // Short circuit if whisper is not running
443+ if api .xeth ().Whisper () == nil {
444+ return NewNotAvailableError (req .Method , "whisper offline" )
445+ }
442446 // Retrieves the currently running whisper protocol version
443447 * reply = api .xeth ().WhisperVersion ()
444448
445449 case "shh_post" :
450+ // Short circuit if whisper is not running
451+ if api .xeth ().Whisper () == nil {
452+ return NewNotAvailableError (req .Method , "whisper offline" )
453+ }
446454 // Injects a new message into the whisper network
447455 args := new (WhisperMessageArgs )
448456 if err := json .Unmarshal (req .Params , & args ); err != nil {
@@ -455,10 +463,18 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
455463 * reply = true
456464
457465 case "shh_newIdentity" :
466+ // Short circuit if whisper is not running
467+ if api .xeth ().Whisper () == nil {
468+ return NewNotAvailableError (req .Method , "whisper offline" )
469+ }
458470 // Creates a new whisper identity to use for sending/receiving messages
459471 * reply = api .xeth ().Whisper ().NewIdentity ()
460472
461473 case "shh_hasIdentity" :
474+ // Short circuit if whisper is not running
475+ if api .xeth ().Whisper () == nil {
476+ return NewNotAvailableError (req .Method , "whisper offline" )
477+ }
462478 // Checks if an identity if owned or not
463479 args := new (WhisperIdentityArgs )
464480 if err := json .Unmarshal (req .Params , & args ); err != nil {
@@ -467,6 +483,10 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
467483 * reply = api .xeth ().Whisper ().HasIdentity (args .Identity )
468484
469485 case "shh_newFilter" :
486+ // Short circuit if whisper is not running
487+ if api .xeth ().Whisper () == nil {
488+ return NewNotAvailableError (req .Method , "whisper offline" )
489+ }
470490 // Create a new filter to watch and match messages with
471491 args := new (WhisperFilterArgs )
472492 if err := json .Unmarshal (req .Params , & args ); err != nil {
@@ -476,6 +496,10 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
476496 * reply = newHexNum (big .NewInt (int64 (id )).Bytes ())
477497
478498 case "shh_uninstallFilter" :
499+ // Short circuit if whisper is not running
500+ if api .xeth ().Whisper () == nil {
501+ return NewNotAvailableError (req .Method , "whisper offline" )
502+ }
479503 // Remove an existing filter watching messages
480504 args := new (FilterIdArgs )
481505 if err := json .Unmarshal (req .Params , & args ); err != nil {
@@ -484,6 +508,10 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
484508 * reply = api .xeth ().UninstallWhisperFilter (args .Id )
485509
486510 case "shh_getFilterChanges" :
511+ // Short circuit if whisper is not running
512+ if api .xeth ().Whisper () == nil {
513+ return NewNotAvailableError (req .Method , "whisper offline" )
514+ }
487515 // Retrieve all the new messages arrived since the last request
488516 args := new (FilterIdArgs )
489517 if err := json .Unmarshal (req .Params , & args ); err != nil {
@@ -492,12 +520,17 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
492520 * reply = api .xeth ().WhisperMessagesChanged (args .Id )
493521
494522 case "shh_getMessages" :
523+ // Short circuit if whisper is not running
524+ if api .xeth ().Whisper () == nil {
525+ return NewNotAvailableError (req .Method , "whisper offline" )
526+ }
495527 // Retrieve all the cached messages matching a specific, existing filter
496528 args := new (FilterIdArgs )
497529 if err := json .Unmarshal (req .Params , & args ); err != nil {
498530 return err
499531 }
500532 * reply = api .xeth ().WhisperMessages (args .Id )
533+
501534 case "eth_hashrate" :
502535 * reply = newHexNum (api .xeth ().HashRate ())
503536
0 commit comments