OSDN Git Service

Add rpc interface: get-current-block-hash (#80)
[bytom/bytom.git] / blockchain / reactor.go
index 8e551de..d4893ba 100644 (file)
@@ -1,7 +1,6 @@
 package blockchain
 
 import (
-       "blockchain/blockchain/rpc"
        "context"
        "fmt"
        "net/http"
@@ -16,8 +15,10 @@ import (
        "github.com/bytom/blockchain/asset"
        "github.com/bytom/blockchain/pin"
        "github.com/bytom/blockchain/pseudohsm"
+       "github.com/bytom/blockchain/rpc"
        ctypes "github.com/bytom/blockchain/rpc/types"
        "github.com/bytom/blockchain/txfeed"
+       "github.com/bytom/protocol/bc"
        "github.com/bytom/encoding/json"
        "github.com/bytom/errors"
        "github.com/bytom/mining/cpuminer"
@@ -161,6 +162,7 @@ func (bcr *BlockchainReactor) BuildHander() {
        m.Handle("/reset-password", jsonHandler(bcr.pseudohsmResetPassword))
        m.Handle("/update-alias", jsonHandler(bcr.pseudohsmUpdateAlias))
        m.Handle("/net-info", jsonHandler(bcr.getNetInfo))
+       m.Handle("/get-best-block-hash", jsonHandler(bcr.getBestBlockHash))
 
        latencyHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
                if l := latency(m, req); l != nil {
@@ -340,6 +342,10 @@ func (bcR *BlockchainReactor) getNetInfo() (*ctypes.ResultNetInfo, error) {
        return rpc.NetInfo(bcR.sw)
 }
 
+func (bcR *BlockchainReactor) getBestBlockHash() *bc.Hash {
+       return bcR.chain.BestBlockHash()
+}
+
 // BroadcastStatusRequest broadcasts `BlockStore` height.
 func (bcR *BlockchainReactor) BroadcastStatusResponse() {
        block, _ := bcR.chain.State()