diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-06-24 01:19:33 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-06-24 01:19:33 +0800 |
commit | 72e2613a9fe3205fa5a67b72b832e03b2357ee88 (patch) | |
tree | bbc987510d279d9e174ff8f684158d668131661e /rpc/shared/types.go | |
parent | 5daf8729be88eca87b302ebf7a46fc69cad0f6d0 (diff) | |
parent | 67e6f74e9af00ff011a6a02f18644804eb18cdaa (diff) | |
download | go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.gz go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.bz2 go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.lz go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.xz go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.zst go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.zip |
Merge branch 'release/0.9.32'v0.9.32
Diffstat (limited to 'rpc/shared/types.go')
-rw-r--r-- | rpc/shared/types.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/rpc/shared/types.go b/rpc/shared/types.go index 6a29fa88e..7c4b04e83 100644 --- a/rpc/shared/types.go +++ b/rpc/shared/types.go @@ -7,6 +7,21 @@ import ( "github.com/ethereum/go-ethereum/logger/glog" ) +// Ethereum RPC API interface +type EthereumApi interface { + // API identifier + Name() string + + // API version + ApiVersion() string + + // Execute the given request and returns the response or an error + Execute(*Request) (interface{}, error) + + // List of supported RCP methods this API provides + Methods() []string +} + // RPC request type Request struct { Id interface{} `json:"id"` @@ -42,6 +57,18 @@ type ErrorObject struct { // Data interface{} `json:"data"` } +// Create RPC error response, this allows for custom error codes +func NewRpcErrorResponse(id interface{}, jsonrpcver string, errCode int, err error) *interface{} { + var response interface{} + + jsonerr := &ErrorObject{errCode, err.Error()} + response = ErrorResponse{Jsonrpc: jsonrpcver, Id: id, Error: jsonerr} + + glog.V(logger.Detail).Infof("Generated error response: %s", response) + return &response +} + +// Create RPC response func NewRpcResponse(id interface{}, jsonrpcver string, reply interface{}, err error) *interface{} { var response interface{} |