Merge pull request #984 from tgerring/issue924
Omit replies for RPC notification requests
This commit is contained in:
commit
158efbaa45
20
rpc/http.go
20
rpc/http.go
@ -87,7 +87,9 @@ func JSONRPC(pipe *xeth.XEth) http.Handler {
|
|||||||
var reqSingle RpcRequest
|
var reqSingle RpcRequest
|
||||||
if err := json.Unmarshal(body, &reqSingle); err == nil {
|
if err := json.Unmarshal(body, &reqSingle); err == nil {
|
||||||
response := RpcResponse(api, &reqSingle)
|
response := RpcResponse(api, &reqSingle)
|
||||||
|
if reqSingle.Id != nil {
|
||||||
send(w, &response)
|
send(w, &response)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,11 +98,27 @@ func JSONRPC(pipe *xeth.XEth) http.Handler {
|
|||||||
if err := json.Unmarshal(body, &reqBatch); err == nil {
|
if err := json.Unmarshal(body, &reqBatch); err == nil {
|
||||||
// Build response batch
|
// Build response batch
|
||||||
resBatch := make([]*interface{}, len(reqBatch))
|
resBatch := make([]*interface{}, len(reqBatch))
|
||||||
|
resCount := 0
|
||||||
|
|
||||||
for i, request := range reqBatch {
|
for i, request := range reqBatch {
|
||||||
response := RpcResponse(api, &request)
|
response := RpcResponse(api, &request)
|
||||||
|
// this leaves nil entries in the response batch for later removal
|
||||||
|
if request.Id != nil {
|
||||||
resBatch[i] = response
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user