aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-05-15 19:12:40 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-05-15 19:12:40 +0800
commit158efbaa459c534bfb53624e1df7f65e7e8ca24a (patch)
treea177a56d2e1dd40d741bf0cc5552be57714d8d79
parent3ac34ee3c4a3a7b875fc672a958075455d0181bc (diff)
parent44a7f997c3c2743634e3fe9db2ead1b8b6a02778 (diff)
downloaddexon-158efbaa459c534bfb53624e1df7f65e7e8ca24a.tar.gz
dexon-158efbaa459c534bfb53624e1df7f65e7e8ca24a.tar.zst
dexon-158efbaa459c534bfb53624e1df7f65e7e8ca24a.zip
Merge pull request #984 from tgerring/issue924
Omit replies for RPC notification requests
-rw-r--r--rpc/http.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/rpc/http.go b/rpc/http.go
index c5bb10c80..9b3fa5142 100644
--- a/rpc/http.go
+++ b/rpc/http.go
@@ -87,7 +87,9 @@ func JSONRPC(pipe *xeth.XEth) http.Handler {
var reqSingle RpcRequest
if err := json.Unmarshal(body, &reqSingle); err == nil {
response := RpcResponse(api, &reqSingle)
- send(w, &response)
+ if reqSingle.Id != nil {
+ send(w, &response)
+ }
return
}
@@ -96,11 +98,27 @@ func JSONRPC(pipe *xeth.XEth) http.Handler {
if err := json.Unmarshal(body, &reqBatch); err == nil {
// Build response batch
resBatch := make([]*interface{}, len(reqBatch))
+ resCount := 0
+
for i, request := range reqBatch {
response := RpcResponse(api, &request)
- resBatch[i] = response
+ // this leaves nil entries in the response batch for later removal
+ if request.Id != nil {
+ resBatch[i] = response
+ resCount = resCount + 1
+ }
}
- send(w, resBatch)
+
+ // make response omitting nil entries
+ respBatchComp := make([]*interface{}, resCount)
+ for _, v := range resBatch {
+ if v != nil {
+ respBatchComp[len(respBatchComp)-resCount] = v
+ resCount = resCount - 1
+ }
+ }
+
+ send(w, respBatchComp)
return
}