-
Notifications
You must be signed in to change notification settings - Fork 8
/
blockApi.go
62 lines (50 loc) · 1.29 KB
/
blockApi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package hivego
import (
"encoding/json"
)
type getBlockRangeQueryParams struct {
StartingBlockNum int `json:"starting_block_num"`
Count int `json:"count"`
}
func (h *HiveRpcNode) GetBlockRange(startBlock int, count int) ([]json.RawMessage, error) {
if h.MaxConn == 0 {
h.MaxConn = 10
}
if h.MaxBatch == 0 {
h.MaxBatch = 4
}
var queries []hrpcQuery
for i := startBlock; i <= startBlock+count; {
params := getBlockRangeQueryParams{StartingBlockNum: i, Count: 500}
query := hrpcQuery{method: "block_api.get_block_range", params: params}
queries = append(queries, query)
i += 500
}
endpoint := h.address
res, err := h.rpcExecBatch(endpoint, queries)
if err != nil {
return nil, err
}
return res, nil
}
func (h *HiveRpcNode) GetBlockRangeFast(startBlock int, count int) ([][]byte, error) {
if h.MaxConn == 0 {
h.MaxConn = 10
}
if h.MaxBatch == 0 {
h.MaxBatch = 4
}
var queries []hrpcQuery
for i := startBlock; i <= startBlock+count; {
params := getBlockRangeQueryParams{StartingBlockNum: i, Count: 500}
query := hrpcQuery{method: "block_api.get_block_range", params: params}
queries = append(queries, query)
i += 500
}
endpoint := h.address
res, err := h.rpcExecBatchFast(endpoint, queries)
if err != nil {
return nil, err
}
return res, nil
}