From 34bb115bc11201b64a428ad73771e6d18a9cb3fb Mon Sep 17 00:00:00 2001 From: Guanghua Guo <1536310027@qq.com> Date: Mon, 11 Dec 2017 10:19:12 +0800 Subject: [PATCH] Fix rpc server error (#194) --- blockchain/rpc_reactor.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/blockchain/rpc_reactor.go b/blockchain/rpc_reactor.go index 9dcef5b0..9e64f6e2 100644 --- a/blockchain/rpc_reactor.go +++ b/blockchain/rpc_reactor.go @@ -1,7 +1,9 @@ package blockchain import ( + "time" "net/http" + log "github.com/sirupsen/logrus" "github.com/bytom/errors" @@ -78,4 +80,15 @@ func (bcr *BlockchainReactor) BuildHander() { m.Handle("/get-block-transactions-count-by-height", jsonHandler(bcr.getBlockTransactionsCountByHeight)) m.Handle("/block-height", jsonHandler(bcr.blockHeight)) m.Handle("/is-mining", jsonHandler(bcr.isMining)) + m.Handle("/gas-rate", jsonHandler(bcr.gasRate)) + + latencyHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + if l := latency(m, req); l != nil { + defer l.RecordSince(time.Now()) + } + m.ServeHTTP(w, req) + }) + handler := maxBytes(latencyHandler) // TODO(tessr): consider moving this to non-core specific mux + + bcr.handler = handler } -- 2.11.0