-
Notifications
You must be signed in to change notification settings - Fork 14
/
method.go
67 lines (57 loc) · 1.39 KB
/
method.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
63
64
65
66
67
// tokucore
//
// Copyright 2019 by KeyFuse Labs
// BSD License
package xrpc
import (
"encoding/json"
)
// GetBlockHash -- get block hash by height.
func (c *Client) GetBlockHash(height int) (string, error) {
rawResp, err := c.call("getblockhash", height)
if err != nil {
return "", err
}
resp := ""
if err = json.Unmarshal(*rawResp.Result, &resp); err != nil {
return "", err
}
return resp, nil
}
// GetBlockCount -- gets block number of blocks in the longest blockchain.
func (c *Client) GetBlockCount() (int, error) {
rawResp, err := c.call("getblockcount")
if err != nil {
return 0, err
}
resp := 0
if err = json.Unmarshal(*rawResp.Result, &resp); err != nil {
return 0, err
}
return resp, nil
}
// GetBlockHeader -- gets block header by block hash.
func (c *Client) GetBlockHeader(hash string) (*BlockHeaderResult, error) {
rawResp, err := c.call("getblockheader", hash)
if err != nil {
return nil, err
}
resp := &BlockHeaderResult{}
if err = json.Unmarshal(*rawResp.Result, resp); err != nil {
return nil, err
}
return resp, nil
}
// GetBlock -- gets verbose block by hash.
func (c *Client) GetBlock(hash string) (*BlockResult, error) {
// Verbose > 2 is more.
rawResp, err := c.call("getblock", hash, 3)
if err != nil {
return nil, err
}
resp := &BlockResult{}
if err = json.Unmarshal(*rawResp.Result, resp); err != nil {
return nil, err
}
return resp, nil
}