-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_blockchain.go
More file actions
115 lines (106 loc) · 2.99 KB
/
client_blockchain.go
File metadata and controls
115 lines (106 loc) · 2.99 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package bbrpc
import "errors"
// Getblockcount https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#getblockcount
func (c *Client) Getblockcount(fork *string) (*int, error) {
resp, err := c.sendCmd("getblockcount", struct {
Fork *string `json:"fork,omitempty"`
}{Fork: fork})
if err != nil {
return nil, err
}
var height int
err = futureParse(resp, &height)
return &height, err
}
// GetblockByHeight .
func (c *Client) GetblockByHeight(height uint64, fork *string) (*BlockInfo, error) {
hash, err := c.Getblockhash(int(height), fork)
if err != nil {
return nil, err
}
if len(hash) == 0 {
return nil, errors.New("no block hashs")
}
return c.Getblock(hash[0])
}
// Getblock https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#getblock
func (c *Client) Getblock(hash string) (*BlockInfo, error) {
resp, err := c.sendCmd("getblock", struct {
Block string `json:"block"`
}{Block: hash})
if err != nil {
return nil, err
}
var info BlockInfo
err = futureParse(resp, &info)
return &info, err
}
// Getblockdetail https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#getblockdetail
func (c *Client) Getblockdetail(blockHash string) (*BlockDetail, error) {
resp, err := c.sendCmd("getblockdetail", struct {
Block string `json:"block"`
}{blockHash})
if err != nil {
return nil, err
}
var info BlockDetail
err = futureParse(resp, &info)
return &info, err
}
// Getblockhash https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#getblockhash
func (c *Client) Getblockhash(height int, fork *string) ([]string, error) {
resp, err := c.sendCmd("getblockhash", struct {
Height int `json:"height"`
Fork *string `json:"fork,omitempty"`
}{Height: height, Fork: fork})
if err != nil {
return nil, err
}
var hash []string
err = futureParse(resp, &hash)
return hash, err
}
// Getforkheight https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#getforkheight
func (c *Client) Getforkheight(fork *string) (h int, err error) {
resp, err := c.sendCmd("getforkheight", struct {
Fork *string `json:"fork,omitempty"`
}{Fork: fork})
if err != nil {
return -1, err
}
err = futureParse(resp, &h)
return
}
func (c *Client) Listdelegate(count int) (ret []Delegate, error error) {
resp, err := c.sendCmd("listdelegate", struct {
Count int `json:"count"`
}{count})
if err != nil {
return nil, err
}
err = futureParse(resp, &ret)
return
}
// Listfork https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#listfork
func (c *Client) Listfork(all bool) (ret []ForkProfile, err error) {
resp, err := c.sendCmd("listfork", struct {
All bool `json:"all"`
}{All: all})
if err != nil {
return nil, err
}
err = futureParse(resp, &ret)
return
}
// Sendtransaction https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#sendtransaction
func (c *Client) Sendtransaction(txdata string) (*string, error) {
resp, err := c.sendCmd("sendtransaction", struct {
Txdata string `json:"txdata"`
}{Txdata: txdata})
if err != nil {
return nil, err
}
var txid string
err = futureParse(resp, &txid)
return &txid, err
}