Implement Bitcore socket.io method getInfo
This commit is contained in:
parent
92aa4f0c7f
commit
dc14eb58b6
@ -132,6 +132,9 @@ var onMessageHandlers = map[string]func(*SocketIoServer, json.RawMessage) (inter
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
},
|
},
|
||||||
|
"\"getInfo\"": func(s *SocketIoServer, params json.RawMessage) (rv interface{}, err error) {
|
||||||
|
return s.getInfo()
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SocketIoServer) onMessage(c *gosocketio.Channel, req map[string]json.RawMessage) interface{} {
|
func (s *SocketIoServer) onMessage(c *gosocketio.Channel, req map[string]json.RawMessage) interface{} {
|
||||||
@ -256,7 +259,7 @@ type resultGetBlockHeader struct {
|
|||||||
|
|
||||||
func (s *SocketIoServer) getBlockHeader(height uint32, hash string) (res resultGetBlockHeader, err error) {
|
func (s *SocketIoServer) getBlockHeader(height uint32, hash string) (res resultGetBlockHeader, err error) {
|
||||||
if hash == "" {
|
if hash == "" {
|
||||||
// trezor is only interested in hash
|
// trezor is interested only in hash
|
||||||
if height == 0 {
|
if height == 0 {
|
||||||
height, hash, err = s.db.GetBestBlock()
|
height, hash, err = s.db.GetBestBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -314,6 +317,34 @@ func (s *SocketIoServer) estimateSmartFee(blocks int, conservative bool) (res re
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type resultGetInfo struct {
|
||||||
|
Result struct {
|
||||||
|
Version int `json:"version"`
|
||||||
|
ProtocolVersion int `json:"protocolVersion"`
|
||||||
|
Blocks int `json:"blocks"`
|
||||||
|
TimeOffset int `json:"timeOffset"`
|
||||||
|
Connections int `json:"connections"`
|
||||||
|
Proxy string `json:"proxy"`
|
||||||
|
Difficulty float64 `json:"difficulty"`
|
||||||
|
Testnet bool `json:"testnet"`
|
||||||
|
RelayFee float64 `json:"relayFee"`
|
||||||
|
Errors string `json:"errors"`
|
||||||
|
Network string `json:"network"`
|
||||||
|
Subversion string `json:"subversion"`
|
||||||
|
LocalServices string `json:"localServices"`
|
||||||
|
} `json:"result"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SocketIoServer) getInfo() (res resultGetInfo, err error) {
|
||||||
|
// trezor is interested only in best block height
|
||||||
|
height, _, err := s.db.GetBestBlock()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
res.Result.Blocks = int(height)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SocketIoServer) onSubscribe(c *gosocketio.Channel, req map[string]json.RawMessage) interface{} {
|
func (s *SocketIoServer) onSubscribe(c *gosocketio.Channel, req map[string]json.RawMessage) interface{} {
|
||||||
glog.Info(c.Id(), " onSubscribe ", req)
|
glog.Info(c.Id(), " onSubscribe ", req)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -81,6 +81,21 @@
|
|||||||
const params = [blocks, conservative];
|
const params = [blocks, conservative];
|
||||||
return socket.send({ method, params }, f);
|
return socket.send({ method, params }, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getInfo() {
|
||||||
|
lookupSyncStatus(function (result) {
|
||||||
|
console.log('getInfo sent successfully');
|
||||||
|
console.log(result);
|
||||||
|
document.getElementById('getInfoResult').innerText = JSON.stringify(result).replace(/,/g, ", ");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function lookupSyncStatus(f) {
|
||||||
|
const method = 'getInfo';
|
||||||
|
const params = [];
|
||||||
|
return socket.send({ method, params }, f);
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@ -146,7 +161,13 @@
|
|||||||
<div class="col" id="estimateSmartFeeResult">
|
<div class="col" id="estimateSmartFeeResult">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<input class="btn btn-secondary" type="button" value="getInfo" onclick="getInfo()">
|
||||||
|
</div>
|
||||||
|
<div class="col-10" id="getInfoResult">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user