This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
block.go
269 lines (223 loc) · 6.01 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
package cmds
type GetBlockCountCmd struct{}
func NewGetBlockCountCmd() *GetBlockCountCmd {
return &GetBlockCountCmd{}
}
type GetBlockhashCmd struct {
Order uint
}
// BlockDetails describes details of a tx in a block.
type BlockDetails struct {
Order uint64 `json:"order"`
Hash string `json:"hash"`
Index int `json:"index"`
Time int64 `json:"time"`
}
// RescanFinishedNtfn defines the rescanfinished JSON-RPC notification.
//
type RescanFinishedNtfn struct {
Hash string
Order uint64
Time int64
LastTxHash string
}
// RescanProgressNtfn defines the rescanprogress JSON-RPC notification.
//
type RescanProgressNtfn struct {
Hash string
Order uint64
Time int64
}
// NewRescanProgressNtfn returns a new instance which can be used to issue a
// rescanprogress JSON-RPC notification.
//
func NewRescanProgressNtfn(hash string, order uint64, time int64) *RescanProgressNtfn {
return &RescanProgressNtfn{
Hash: hash,
Order: order,
Time: time,
}
}
// NewRescanFinishedNtfn returns a new instance which can be used to issue a
// rescanfinished JSON-RPC notification.
//
func NewRescanFinishedNtfn(hash, txHash string, order uint64, time int64) *RescanFinishedNtfn {
return &RescanFinishedNtfn{
Hash: hash,
Order: order,
Time: time,
LastTxHash: txHash,
}
}
// RedeemingTxNtfn defines the redeemingtx JSON-RPC notification.
//
type RedeemingTxNtfn struct {
HexTx string
Block *BlockDetails
}
func NewGetBlockhashCmd(order uint) *GetBlockhashCmd {
return &GetBlockhashCmd{
Order: order,
}
}
type GetBlockhashByRangeCmd struct {
Start uint
End uint
}
func NewGetBlockhashByRangeCmd(start uint, end uint) *GetBlockhashByRangeCmd {
return &GetBlockhashByRangeCmd{
Start: start,
End: end,
}
}
type GetBlockCmd struct {
H string
Verbose bool
InclTx bool
FullTx bool
}
func NewGetBlockCmd(h string, verbose bool, inclTx bool, fullTx bool) *GetBlockCmd {
return &GetBlockCmd{
H: h,
Verbose: verbose,
InclTx: inclTx,
FullTx: fullTx,
}
}
type GetBlockByOrderCmd struct {
Order uint
Verbose bool
InclTx bool
FullTx bool
}
func NewGetBlockByOrderCmd(order uint, verbose bool, inclTx bool, fullTx bool) *GetBlockByOrderCmd {
return &GetBlockByOrderCmd{
Order: order,
Verbose: verbose,
InclTx: inclTx,
FullTx: fullTx,
}
}
type GetBlockV2Cmd struct {
H string
Verbose bool
InclTx bool
FullTx bool
}
func NewGetBlockV2Cmd(h string, verbose bool, inclTx bool, fullTx bool) *GetBlockCmd {
return &GetBlockCmd{
H: h,
Verbose: verbose,
InclTx: inclTx,
FullTx: fullTx,
}
}
type GetBestBlockHashCmd struct{}
func NewGetBestBlockHashCmd() *GetBestBlockHashCmd {
return &GetBestBlockHashCmd{}
}
type GetBlockTotalCmd struct{}
func NewGetBlockTotalCmd() *GetBlockTotalCmd {
return &GetBlockTotalCmd{}
}
type GetBlockHeaderCmd struct {
Hash string
Verbose bool
}
func NewGetBlockHeaderCmd(hash string, verbose bool) *GetBlockHeaderCmd {
return &GetBlockHeaderCmd{
Hash: hash,
Verbose: verbose,
}
}
type IsOnMainChainCmd struct {
H string
}
func NewIsOnMainChainCmd(h string) *IsOnMainChainCmd {
return &IsOnMainChainCmd{
H: h,
}
}
type GetMainChainHeightCmd struct{}
func NewGetMainChainHeightCmd() *GetMainChainHeightCmd {
return &GetMainChainHeightCmd{}
}
type GetBlockWeightCmd struct {
H string
}
func NewGetBlockWeightCmd(h string) *GetBlockWeightCmd {
return &GetBlockWeightCmd{
H: h,
}
}
type GetOrphansTotalCmd struct{}
func NewGetOrphansTotalCmd() *GetOrphansTotalCmd {
return &GetOrphansTotalCmd{}
}
type GetBlockByNumCmd struct {
ID uint
Verbose bool
InclTx bool
FullTx bool
}
func NewGetBlockByNumCmd(id uint, verbose bool, inclTx bool, fullTx bool) *GetBlockByNumCmd {
return &GetBlockByNumCmd{
ID: id,
Verbose: verbose,
InclTx: inclTx,
FullTx: fullTx,
}
}
type IsBlueCmd struct {
H string
}
func NewIsBlueCmd(h string) *IsBlueCmd {
return &IsBlueCmd{
H: h,
}
}
type IsCurrentCmd struct {
}
func NewIsCurrentCmd() *IsCurrentCmd {
return &IsCurrentCmd{}
}
type TipsCmd struct {
}
func NewTipsCmd() *TipsCmd {
return &TipsCmd{}
}
type GetCoinbaseCmd struct {
}
func NewGetCoinbaseCmd() *GetCoinbaseCmd {
return &GetCoinbaseCmd{}
}
type GetFeesCmd struct {
H string
}
func NewGetFeesCmd(h string) *GetFeesCmd {
return &GetFeesCmd{
H: h,
}
}
func init() {
flags := UsageFlag(0)
MustRegisterCmd("getBlockCount", (*GetBlockCountCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getBlockhash", (*GetBlockhashCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getBlockhashByRange", (*GetBlockhashByRangeCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getBlock", (*GetBlockCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getBlockV2", (*GetBlockV2Cmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getBlockByOrder", (*GetBlockByOrderCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getBestBlockHash", (*GetBestBlockHashCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getBlockTotal", (*GetBlockTotalCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getBlockHeader", (*GetBlockHeaderCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("isOnMainChain", (*IsOnMainChainCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getMainChainHeight", (*GetMainChainHeightCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getBlockWeight", (*GetBlockWeightCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getOrphansTotal", (*GetOrphansTotalCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getBlockByNum", (*GetBlockByNumCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("isBlue", (*IsBlueCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("isCurrent", (*IsCurrentCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("tips", (*TipsCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getCoinbase", (*GetCoinbaseCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getFees", (*GetFeesCmd)(nil), flags, DefaultServiceNameSpace)
}