diff --git a/server/websocket.go b/server/websocket.go index afda0c16..4002123d 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -227,6 +227,16 @@ var requestHandlers = map[string]func(*WebsocketServer, *websocketChannel, *webs "getInfo": func(s *WebsocketServer, c *websocketChannel, req *websocketReq) (rv interface{}, err error) { return s.getInfo() }, + "getBlockHash": func(s *WebsocketServer, c *websocketChannel, req *websocketReq) (rv interface{}, err error) { + r := struct { + Height int `json:"height"` + }{} + err = json.Unmarshal(req.Params, &r) + if err == nil { + rv, err = s.getBlockHash(r.Height) + } + return + }, "estimateFee": func(s *WebsocketServer, c *websocketChannel, req *websocketReq) (rv interface{}, err error) { return s.estimateFee(c, req.Params) }, @@ -365,6 +375,19 @@ func (s *WebsocketServer) getInfo() (interface{}, error) { }, nil } +func (s *WebsocketServer) getBlockHash(height int) (interface{}, error) { + h, err := s.db.GetBlockHash(uint32(height)) + if err != nil { + return nil, err + } + type hash struct { + Hash string `json:"hash"` + } + return &hash{ + Hash: h, + }, nil +} + func (s *WebsocketServer) estimateFee(c *websocketChannel, params []byte) (interface{}, error) { type estimateFeeReq struct { Blocks []int `json:"blocks"` diff --git a/static/test-websocket.html b/static/test-websocket.html index 5af7a7f8..3fe8e4ab 100644 --- a/static/test-websocket.html +++ b/static/test-websocket.html @@ -106,6 +106,17 @@ }); } + function getBlockHash() { + const method = 'getBlockHash'; + const height = parseInt(document.getElementById("getBlockHashHeight").value); + const params = { + height + }; + send(method, params, function (result) { + document.getElementById('getBlockHashResult').innerText = JSON.stringify(result).replace(/,/g, ", "); + }); + } + function getAccountInfo() { const descriptor = document.getElementById('getAccountInfoDescriptor').value.trim(); const selectDetails = document.getElementById('getAccountInfoDetails'); @@ -251,6 +262,19 @@
+
+
+ +
+
+ +
+
+
+
+
+
+