Add websocket method getBlockHash
This commit is contained in:
parent
97e0844a4b
commit
1e8506bdf7
@ -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"`
|
||||
|
||||
@ -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 @@
|
||||
<div class="col-10" id="getInfoResult">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<input class="btn btn-secondary" type="button" value="getBlockHash" onclick="getBlockHash()">
|
||||
</div>
|
||||
<div class="col-8">
|
||||
<input type="text" class="form-control" placeholder="height" id="getBlockHashHeight" value="0">
|
||||
</div>
|
||||
<div class="col">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col" id="getBlockHashResult"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<input class="btn btn-secondary" type="button" value="getAccountInfo" onclick="getAccountInfo()">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user