diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-05-15 19:12:40 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-05-15 19:12:40 +0800 |
commit | 158efbaa459c534bfb53624e1df7f65e7e8ca24a (patch) | |
tree | a177a56d2e1dd40d741bf0cc5552be57714d8d79 | |
parent | 3ac34ee3c4a3a7b875fc672a958075455d0181bc (diff) | |
parent | 44a7f997c3c2743634e3fe9db2ead1b8b6a02778 (diff) | |
download | go-tangerine-158efbaa459c534bfb53624e1df7f65e7e8ca24a.tar.gz go-tangerine-158efbaa459c534bfb53624e1df7f65e7e8ca24a.tar.zst go-tangerine-158efbaa459c534bfb53624e1df7f65e7e8ca24a.zip |
Merge pull request #984 from tgerring/issue924
Omit replies for RPC notification requests
-rw-r--r-- | rpc/http.go | 24 |
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 } |