aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-02-06 03:44:30 +0800
committerobscuren <geffobscura@gmail.com>2015-02-06 03:44:30 +0800
commitd00e2731e50f5b535e5deba63ea7f93168906712 (patch)
treead910fd3335d5bc7b7741196b91e340d4322a503 /rpc
parentdb7c34a9df19d5a8a3a02a5e3d4cafcffa18dcb8 (diff)
parent429077a5a043ea6664f795ab34ad09ec2f65286f (diff)
downloaddexon-d00e2731e50f5b535e5deba63ea7f93168906712.tar
dexon-d00e2731e50f5b535e5deba63ea7f93168906712.tar.gz
dexon-d00e2731e50f5b535e5deba63ea7f93168906712.tar.bz2
dexon-d00e2731e50f5b535e5deba63ea7f93168906712.tar.lz
dexon-d00e2731e50f5b535e5deba63ea7f93168906712.tar.xz
dexon-d00e2731e50f5b535e5deba63ea7f93168906712.tar.zst
dexon-d00e2731e50f5b535e5deba63ea7f93168906712.zip
Merge branch 'develop' of https://github.com/tgerring/go-ethereum into tgerring-develop
Conflicts: rpc/http/server.go
Diffstat (limited to 'rpc')
-rw-r--r--rpc/http/server.go13
-rw-r--r--rpc/message.go25
-rw-r--r--rpc/ws/server.go35
3 files changed, 36 insertions, 37 deletions
diff --git a/rpc/http/server.go b/rpc/http/server.go
index bcfd46234..7dcd6b867 100644
--- a/rpc/http/server.go
+++ b/rpc/http/server.go
@@ -84,6 +84,7 @@ func (s *RpcHttpServer) Start() {
}
func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
+ var jsonrpcver string = "2.0"
fn := func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
@@ -91,20 +92,22 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
reqParsed, reqerr := JSON.ParseRequestBody(req)
if reqerr != nil {
- JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: rpc.ErrorParseRequest})
+ jsonerr := &rpc.RpcErrorObject{-32700, rpc.ErrorParseRequest}
+ JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr})
return
}
var response interface{}
reserr := api.GetRequestReply(&reqParsed, &response)
if reserr != nil {
- rpchttplogger.Errorln(reserr)
- JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: reserr.Error()})
+ rpchttplogger.Warnln(reserr)
+ jsonerr := &rpc.RpcErrorObject{-32603, reserr.Error()}
+ JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: &reqParsed.ID, Error: jsonerr})
return
}
- rpchttplogger.DebugDetailf("Generated response: %T %s", response, response)
- JSON.Send(w, &rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response})
+ rpchttplogger.Debugf("Generated response: %T %s", response, response)
+ JSON.Send(w, &rpc.RpcSuccessResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Result: response})
}
return http.HandlerFunc(fn)
diff --git a/rpc/message.go b/rpc/message.go
index 0845a2239..e110bdf3e 100644
--- a/rpc/message.go
+++ b/rpc/message.go
@@ -33,30 +33,29 @@ const (
ErrorDecodeArgs = "Error: Could not decode arguments"
)
-type ErrorResponse struct {
- Error bool `json:"error"`
- ErrorText string `json:"errorText"`
+type RpcRequest struct {
+ JsonRpc string `json:"jsonrpc"`
+ ID int `json:"id"`
+ Method string `json:"method"`
+ Params []json.RawMessage `json:"params"`
}
type RpcSuccessResponse struct {
ID int `json:"id"`
JsonRpc string `json:"jsonrpc"`
- Error bool `json:"error"`
Result interface{} `json:"result"`
}
type RpcErrorResponse struct {
- ID int `json:"id"`
- JsonRpc string `json:"jsonrpc"`
- Error bool `json:"error"`
- ErrorText string `json:"errortext"`
+ ID *int `json:"id"`
+ JsonRpc string `json:"jsonrpc"`
+ Error *RpcErrorObject `json:"error"`
}
-type RpcRequest struct {
- JsonRpc string `json:"jsonrpc"`
- ID int `json:"id"`
- Method string `json:"method"`
- Params []json.RawMessage `json:"params"`
+type RpcErrorObject struct {
+ Code int `json:"code"`
+ Message string `json:"message"`
+ // Data interface{} `json:"data"`
}
func NewErrorResponse(msg string) error {
diff --git a/rpc/ws/server.go b/rpc/ws/server.go
index 2853181ec..6be4e8ce9 100644
--- a/rpc/ws/server.go
+++ b/rpc/ws/server.go
@@ -22,35 +22,30 @@ import (
"net/http"
"code.google.com/p/go.net/websocket"
- "github.com/ethereum/go-ethereum/eth"
- "github.com/ethereum/go-ethereum/event/filter"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/xeth"
)
var wslogger = logger.NewLogger("RPC-WS")
+var JSON rpc.JsonWrapper
type WebSocketServer struct {
- eth *eth.Ethereum
- filterManager *filter.FilterManager
- port int
- doneCh chan bool
- listener net.Listener
+ pipe *xeth.XEth
+ port int
+ doneCh chan bool
+ listener net.Listener
}
-func NewWebSocketServer(eth *eth.Ethereum, port int) (*WebSocketServer, error) {
+func NewWebSocketServer(pipe *xeth.XEth, port int) (*WebSocketServer, error) {
sport := fmt.Sprintf(":%d", port)
l, err := net.Listen("tcp", sport)
if err != nil {
return nil, err
}
- filterManager := filter.NewFilterManager(eth.EventMux())
- go filterManager.Start()
-
- return &WebSocketServer{eth,
- filterManager,
+ return &WebSocketServer{
+ pipe,
port,
make(chan bool),
l,
@@ -75,7 +70,7 @@ func (self *WebSocketServer) Start() {
wslogger.Infof("Starting RPC-WS server on port %d", self.port)
go self.handlerLoop()
- api := rpc.NewEthereumApi(xeth.New(self.eth))
+ api := rpc.NewEthereumApi(self.pipe)
h := self.apiHandler(api)
http.Handle("/ws", h)
@@ -96,27 +91,29 @@ func (s *WebSocketServer) apiHandler(api *rpc.EthereumApi) http.Handler {
}
func sockHandler(api *rpc.EthereumApi) websocket.Handler {
+ var jsonrpcver string = "2.0"
fn := func(conn *websocket.Conn) {
for {
wslogger.Debugln("Handling request")
var reqParsed rpc.RpcRequest
if err := websocket.JSON.Receive(conn, &reqParsed); err != nil {
- wslogger.Debugln(rpc.ErrorParseRequest)
- websocket.JSON.Send(conn, rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: rpc.ErrorParseRequest})
+ jsonerr := &rpc.RpcErrorObject{-32700, rpc.ErrorParseRequest}
+ JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr})
continue
}
var response interface{}
reserr := api.GetRequestReply(&reqParsed, &response)
if reserr != nil {
- wslogger.Errorln(reserr)
- websocket.JSON.Send(conn, rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: reserr.Error()})
+ wslogger.Warnln(reserr)
+ jsonerr := &rpc.RpcErrorObject{-32603, reserr.Error()}
+ JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: &reqParsed.ID, Error: jsonerr})
continue
}
wslogger.Debugf("Generated response: %T %s", response, response)
- websocket.JSON.Send(conn, rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response})
+ JSON.Send(conn, &rpc.RpcSuccessResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Result: response})
}
}
return websocket.Handler(fn)