-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.go
66 lines (48 loc) · 2.19 KB
/
block.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
package rpcclient
import (
"github.com/omarhachach/rpcclient-core/types"
)
// GetBlock returns hex-encoded data for the block.
func (c *Client) GetBlock(hash string) (string, error) {
var hex string
return hex, c.SendReq("getblock", &hex, hash, 0)
}
// GetBlockVerbose returns an object with information about the block.
func (c *Client) GetBlockVerbose(hash string) (*types.Block, error) {
var block *types.Block
return block, c.SendReq("getblock", &block, hash, 1)
}
// GetBlockVerboseTx returns an object with information about the block and the included transactions.
func (c *Client) GetBlockVerboseTx(hash string) (*types.BlockTx, error) {
var block *types.BlockTx
return block, c.SendReq("getblock", &block, hash, 2)
}
// GetBlockHash gets the hash of block in best-block-chain at height provided.
func (c *Client) GetBlockHash(height int) (string, error) {
var blockhash string
return blockhash, c.SendReq("getblockhash", &blockhash, height)
}
// GetBlockHeader returns a serialized, hex-encoded data for the blockheader.
func (c *Client) GetBlockHeader(blockhash string) (string, error) {
var blockheader string
return blockheader, c.SendReq("getblockheader", &blockheader, blockhash, false)
}
// GetBlockHeaderVerbose retrieves a block's header.
func (c *Client) GetBlockHeaderVerbose(blockhash string) (*types.BlockHeader, error) {
var blockheader *types.BlockHeader
return blockheader, c.SendReq("getblockheader", &blockheader, blockhash, true)
}
// GetBlockStats computes the per block statstics for a given block.
func (c *Client) GetBlockStats(blockhash string) (*types.BlockStats, error) {
var blockstats *types.BlockStats
return blockstats, c.SendReq("getblockstats", &blockstats, blockhash)
}
// GetBlockStatsHeight is the same as GetBlockStats but uses the block height to find the block.
func (c *Client) GetBlockStatsHeight(blockheight int) (*types.BlockStats, error) {
var blockstats *types.BlockStats
return blockstats, c.SendReq("getblockstats", &blockstats, blockheight)
}
// PreciousBlock treats a block as if it were received before others with the same work.
func (c *Client) PreciousBlock(blockhash string) error {
return c.SendReq("preciousblock", new(bool), blockhash)
}