"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"
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 {
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()
"reset-password": {resetPassword},
"update-alias": {updateAlias},
"net-info": {netInfo},
+ "get-best-block-hash": {getBestBlockHash},
}
func main() {
client.Call(context.Background(), "/net-info", nil, &response)
fmt.Printf("net info:%v\n", response)
}
+
+func getBestBlockHash(client *rpc.Client, args []string) {
+ var response interface{}
+ client.Call(context.Background(), "/get-best-block-hash", nil, &response)
+ fmt.Printf("best-block-hash:%v\n", response)
+}
return c.state.height
}
+func (c *Chain) BestBlockHash() *bc.Hash {
+ c.state.cond.L.Lock()
+ defer c.state.cond.L.Unlock()
+ return c.state.hash
+}
+
func (c *Chain) inMainchain(block *legacy.Block) bool {
hash, ok := c.state.mainChain[block.Height]
if !ok {