aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/shared
diff options
context:
space:
mode:
Diffstat (limited to 'rpc/shared')
-rw-r--r--rpc/shared/types.go27
-rw-r--r--rpc/shared/utils.go27
2 files changed, 54 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{}
diff --git a/rpc/shared/utils.go b/rpc/shared/utils.go
new file mode 100644
index 000000000..e5d6ad417
--- /dev/null
+++ b/rpc/shared/utils.go
@@ -0,0 +1,27 @@
+package shared
+
+import "strings"
+
+const (
+ AdminApiName = "admin"
+ EthApiName = "eth"
+ DbApiName = "db"
+ DebugApiName = "debug"
+ MergedApiName = "merged"
+ MinerApiName = "miner"
+ NetApiName = "net"
+ ShhApiName = "shh"
+ TxPoolApiName = "txpool"
+ PersonalApiName = "personal"
+ Web3ApiName = "web3"
+
+ JsonRpcVersion = "2.0"
+)
+
+var (
+ // All API's
+ AllApis = strings.Join([]string{
+ AdminApiName, DbApiName, EthApiName, DebugApiName, MinerApiName, NetApiName,
+ ShhApiName, TxPoolApiName, PersonalApiName, Web3ApiName,
+ }, ",")
+)