Add getBlockFiltersBatch websocket method
This commit is contained in:
parent
4b6f19632d
commit
a1a17b4331
@ -2200,6 +2200,48 @@ func (w *Worker) GetBlockRaw(bid string) (*BlockRaw, error) {
|
||||
return &BlockRaw{Hex: hex}, err
|
||||
}
|
||||
|
||||
// GetBlockFiltersBatch returns array of block filter data in the format ["height:hash:filter",...] if blocks greater than bestKnownBlockHash
|
||||
func (w *Worker) GetBlockFiltersBatch(bestKnownBlockHash string, pageSize int) ([]string, error) {
|
||||
if w.is.BlockGolombFilterP == 0 {
|
||||
return nil, NewAPIError("Not supported", true)
|
||||
}
|
||||
if pageSize > 10000 {
|
||||
return nil, NewAPIError("pageSize max 10000", true)
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 1000
|
||||
}
|
||||
bi, err := w.chain.GetBlockInfo(bestKnownBlockHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bestHeight, _, err := w.db.GetBestBlock()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
from := bi.Height + 1
|
||||
to := bestHeight + 1
|
||||
if from >= to {
|
||||
return []string{}, nil
|
||||
}
|
||||
if to-from > uint32(pageSize) {
|
||||
to = from + uint32(pageSize)
|
||||
}
|
||||
r := make([]string, 0, to-from)
|
||||
for i := from; i < to; i++ {
|
||||
blockHash, err := w.db.GetBlockHash(uint32(i))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
blockFilter, err := w.db.GetBlockFilter(blockHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r = append(r, fmt.Sprintf("%d:%s:%s", i, blockHash, blockFilter))
|
||||
}
|
||||
return r, err
|
||||
}
|
||||
|
||||
// ComputeFeeStats computes fee distribution in defined blocks and logs them to log
|
||||
func (w *Worker) ComputeFeeStats(blockFrom, blockTo int, stopCompute chan os.Signal) error {
|
||||
bestheight, _, err := w.db.GetBestBlock()
|
||||
|
||||
@ -357,6 +357,13 @@ export interface WsBlockReq {
|
||||
pageSize?: number;
|
||||
page?: number;
|
||||
}
|
||||
export interface WsBlockFilterReq {
|
||||
blockHash: string;
|
||||
}
|
||||
export interface WsBlockFiltersBatchReq {
|
||||
bestKnownBlockHash: string;
|
||||
pageSize?: number;
|
||||
}
|
||||
export interface WsAccountUtxoReq {
|
||||
descriptor: string;
|
||||
}
|
||||
|
||||
@ -45,6 +45,8 @@ func main() {
|
||||
t.Add(server.WsBlockHashReq{})
|
||||
t.Add(server.WsBlockHashRes{})
|
||||
t.Add(server.WsBlockReq{})
|
||||
t.Add(server.WsBlockFilterReq{})
|
||||
t.Add(server.WsBlockFiltersBatchReq{})
|
||||
t.Add(server.WsAccountUtxoReq{})
|
||||
t.Add(server.WsBalanceHistoryReq{})
|
||||
t.Add(server.WsTransactionReq{})
|
||||
|
||||
@ -359,6 +359,14 @@ var requestHandlers = map[string]func(*WebsocketServer, *websocketChannel, *WsRe
|
||||
}
|
||||
return
|
||||
},
|
||||
"getBlockFiltersBatch": func(s *WebsocketServer, c *websocketChannel, req *WsReq) (rv interface{}, err error) {
|
||||
r := WsBlockFiltersBatchReq{}
|
||||
err = json.Unmarshal(req.Params, &r)
|
||||
if err == nil {
|
||||
rv, err = s.getBlockFiltersBatch(&r)
|
||||
}
|
||||
return
|
||||
},
|
||||
"subscribeNewBlock": func(s *WebsocketServer, c *websocketChannel, req *WsReq) (rv interface{}, err error) {
|
||||
return s.subscribeNewBlock(c, req)
|
||||
},
|
||||
@ -658,6 +666,10 @@ func (s *WebsocketServer) getBlockFilter(r *WsBlockFilterReq) (res string, err e
|
||||
return s.db.GetBlockFilter(r.BlockHash)
|
||||
}
|
||||
|
||||
func (s *WebsocketServer) getBlockFiltersBatch(r *WsBlockFiltersBatchReq) (res []string, err error) {
|
||||
return s.api.GetBlockFiltersBatch(r.BlockHash, r.PageSize)
|
||||
}
|
||||
|
||||
type subscriptionResponse struct {
|
||||
Subscribed bool `json:"subscribed"`
|
||||
}
|
||||
|
||||
@ -85,6 +85,11 @@ type WsBlockFilterReq struct {
|
||||
BlockHash string `json:"blockHash"`
|
||||
}
|
||||
|
||||
type WsBlockFiltersBatchReq struct {
|
||||
BlockHash string `json:"bestKnownBlockHash"`
|
||||
PageSize int `json:"pageSize,omitempty"`
|
||||
}
|
||||
|
||||
type WsTransactionSpecificReq struct {
|
||||
Txid string `json:"txid"`
|
||||
}
|
||||
|
||||
@ -413,7 +413,7 @@
|
||||
|
||||
function getBlockFilter() {
|
||||
const method = 'getBlockFilter';
|
||||
let blockHash = document.getElementById('getBlockFilterBlockHash').value;
|
||||
const blockHash = document.getElementById('getBlockFilterBlockHash').value;
|
||||
const params = {
|
||||
blockHash,
|
||||
};
|
||||
@ -422,6 +422,19 @@
|
||||
});
|
||||
}
|
||||
|
||||
function getBlockFiltersBatch() {
|
||||
const method = 'getBlockFiltersBatch';
|
||||
const bestKnownBlockHash = document.getElementById('getBlockFiltersBatchBlockHash').value;
|
||||
const pageSize = parseInt(document.getElementById("getBlockFiltersBatchPageSize").value);
|
||||
const params = {
|
||||
bestKnownBlockHash,
|
||||
};
|
||||
if (pageSize) params.pageSize = pageSize;
|
||||
send(method, params, function (result) {
|
||||
document.getElementById('getBlockFiltersBatchResult').innerText = JSON.stringify(result).replace(/,/g, ", ");
|
||||
});
|
||||
}
|
||||
|
||||
function subscribeNewFiatRatesTicker() {
|
||||
const method = 'subscribeFiatRates';
|
||||
var currency = document.getElementById('subscribeFiatRatesCurrency').value;
|
||||
@ -704,13 +717,27 @@
|
||||
<div class="col-2">
|
||||
<input class="btn btn-secondary" type="button" value="get block filter" onclick="getBlockFilter()">
|
||||
</div>
|
||||
<div class="col-5">
|
||||
<div class="col-8">
|
||||
<input type="text" class="form-control" id="getBlockFilterBlockHash" value="000000000000001cb4edd91be03b6775abd351fb51b1fbb0871fc1451454f362" placeholder="block hash">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col" id="getBlockFilterResult"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-2">
|
||||
<input class="btn btn-secondary" type="button" value="get block filter batch" onclick="getBlockFiltersBatch()">
|
||||
</div>
|
||||
<div class="col-10">
|
||||
<div class="row" style="margin: 0;">
|
||||
<input type="text" class="form-control" id="getBlockFiltersBatchBlockHash" style="width: 80%; margin-right: 5px;" value="000000000000001cb4edd91be03b6775abd351fb51b1fbb0871fc1451454f362" placeholder="best known block hash">
|
||||
<input type="text" class="form-control" placeholder="page size" style="width: 15%;" id="getBlockFiltersBatchPageSize" value="">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col" id="getBlockFiltersBatchResult"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<input class="btn btn-secondary" type="button" value="subscribe new block" onclick="subscribeNewBlock()">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user