diff options
author | Bas van Kervel <basvankervel@ziggo.nl> | 2015-06-08 16:41:04 +0800 |
---|---|---|
committer | Bas van Kervel <basvankervel@gmail.com> | 2015-06-11 20:01:39 +0800 |
commit | 8ebf2d8fad729a8261f237bb05b6073e6c1b652f (patch) | |
tree | dd941d95eb9efdfb348caa94618d62b4523a02e8 /rpc/shared | |
parent | 2f55a1d79853c1348fb1a4332fff98110167da80 (diff) | |
download | dexon-8ebf2d8fad729a8261f237bb05b6073e6c1b652f.tar.gz dexon-8ebf2d8fad729a8261f237bb05b6073e6c1b652f.tar.zst dexon-8ebf2d8fad729a8261f237bb05b6073e6c1b652f.zip |
added RPC/IPC support
Diffstat (limited to 'rpc/shared')
-rw-r--r-- | rpc/shared/types.go | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/rpc/shared/types.go b/rpc/shared/types.go index 46fd5552c..600d39541 100644 --- a/rpc/shared/types.go +++ b/rpc/shared/types.go @@ -1,6 +1,10 @@ package shared -import "encoding/json" +import ( + "encoding/json" + "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger/glog" +) // RPC request type Request struct { @@ -36,3 +40,24 @@ type ErrorObject struct { Message string `json:"message"` // Data interface{} `json:"data"` } + +func NewRpcResponse(id interface{}, jsonrpcver string, reply interface{}, err error) *interface{} { + var response interface{} + + switch err.(type) { + case nil: + response = &SuccessResponse{Jsonrpc: jsonrpcver, Id: id, Result: reply} + case *NotImplementedError: + jsonerr := &ErrorObject{-32601, err.Error()} + response = &ErrorResponse{Jsonrpc: jsonrpcver, Id: id, Error: jsonerr} + case *DecodeParamError, *InsufficientParamsError, *ValidationError, *InvalidTypeError: + jsonerr := &ErrorObject{-32602, err.Error()} + response = &ErrorResponse{Jsonrpc: jsonrpcver, Id: id, Error: jsonerr} + default: + jsonerr := &ErrorObject{-32603, err.Error()} + response = &ErrorResponse{Jsonrpc: jsonrpcver, Id: id, Error: jsonerr} + } + + glog.V(logger.Detail).Infof("Generated response: %T %s", response, response) + return &response +} |