aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/comms
diff options
context:
space:
mode:
authorBas van Kervel <bas@ethdev.com>2015-06-25 18:01:28 +0800
committerBas van Kervel <bas@ethdev.com>2015-06-25 18:01:28 +0800
commit6d92fdc0df12337c2ffb8e6d19c83653f1a00ff2 (patch)
treeb0717ba3da3f9db94a062536dc4382cc16477ec1 /rpc/comms
parent22c7ce0162f2d14a7340e00e93697780c91d2087 (diff)
downloadgo-tangerine-6d92fdc0df12337c2ffb8e6d19c83653f1a00ff2.tar
go-tangerine-6d92fdc0df12337c2ffb8e6d19c83653f1a00ff2.tar.gz
go-tangerine-6d92fdc0df12337c2ffb8e6d19c83653f1a00ff2.tar.bz2
go-tangerine-6d92fdc0df12337c2ffb8e6d19c83653f1a00ff2.tar.lz
go-tangerine-6d92fdc0df12337c2ffb8e6d19c83653f1a00ff2.tar.xz
go-tangerine-6d92fdc0df12337c2ffb8e6d19c83653f1a00ff2.tar.zst
go-tangerine-6d92fdc0df12337c2ffb8e6d19c83653f1a00ff2.zip
added support for batch requests
Diffstat (limited to 'rpc/comms')
-rw-r--r--rpc/comms/comms.go38
1 files changed, 29 insertions, 9 deletions
diff --git a/rpc/comms/comms.go b/rpc/comms/comms.go
index bfe625758..1374bde3f 100644
--- a/rpc/comms/comms.go
+++ b/rpc/comms/comms.go
@@ -47,7 +47,7 @@ func handle(conn net.Conn, api shared.EthereumApi, c codec.Codec) {
codec := c.New(conn)
for {
- req, err := codec.ReadRequest()
+ requests, isBatch, err := codec.ReadRequest()
if err == io.EOF {
codec.Close()
return
@@ -57,15 +57,35 @@ func handle(conn net.Conn, api shared.EthereumApi, c codec.Codec) {
return
}
- var rpcResponse interface{}
- res, err := api.Execute(req)
+ if isBatch {
+ responses := make([]*interface{}, len(requests))
+ responseCount := 0
+ for _, req := range requests {
+ res, err := api.Execute(req)
+ if req.Id != nil {
+ rpcResponse := shared.NewRpcResponse(req.Id, req.Jsonrpc, res, err)
+ responses[responseCount] = rpcResponse
+ responseCount += 1
+ }
+ }
- rpcResponse = shared.NewRpcResponse(req.Id, req.Jsonrpc, res, err)
- err = codec.WriteResponse(rpcResponse)
- if err != nil {
- glog.V(logger.Error).Infof("comms send err - %v\n", err)
- codec.Close()
- return
+ err = codec.WriteResponse(responses[:responseCount])
+ if err != nil {
+ glog.V(logger.Error).Infof("comms send err - %v\n", err)
+ codec.Close()
+ return
+ }
+ } else {
+ var rpcResponse interface{}
+ res, err := api.Execute(requests[0])
+
+ rpcResponse = shared.NewRpcResponse(requests[0].Id, requests[0].Jsonrpc, res, err)
+ err = codec.WriteResponse(rpcResponse)
+ if err != nil {
+ glog.V(logger.Error).Infof("comms send err - %v\n", err)
+ codec.Close()
+ return
+ }
}
}
}