OSDN Git Service

Fix rpc server error (#195)
authorGuanghua Guo <1536310027@qq.com>
Mon, 11 Dec 2017 02:23:02 +0000 (10:23 +0800)
committerGitHub <noreply@github.com>
Mon, 11 Dec 2017 02:23:02 +0000 (10:23 +0800)
blockchain/rpc_reactor.go

index 9dcef5b..9e64f6e 100644 (file)
@@ -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
 }