-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.go
More file actions
226 lines (212 loc) · 8.25 KB
/
block.go
File metadata and controls
226 lines (212 loc) · 8.25 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
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
package tokenviewapi
var (
pathCoinHeight = "/coin/latest/%s"
pathBlockHeader = "/block/%s/%s"
pathBlock = "/tx/%s/%d/%d/%d"
pathBlocks = "/blocks/%s/%d/%d"
pathTxDetail = "/tx/%s/%s"
pathTxConfirmation = "/tx/confirmation/%s/%s"
pathAddrMining = "/%s/address/mining/%s/%d/%d"
)
//CoinHeight 最新块高(单条链)
//https://services.tokenview.com/vipapi/coin/latest/{币简称小写}?apikey={apikey}
func (t *TokenViewAPI) CoinHeight(coin string) (resp int64, err error) {
var url = t.setUrl(pathCoinHeight, coin)
err = t.do(url, &resp)
return
}
type respBlockHeader struct {
Type string `json:"type"`
Network string `json:"network"`
BlockNo int `json:"block_no"`
Time int `json:"time"`
Fee string `json:"fee"`
Blockhash string `json:"blockhash"`
Reward string `json:"reward"`
Size int `json:"size"`
PreviousBlockhash string `json:"previous_blockhash"`
NextBlockhash string `json:"next_blockhash"`
Confirmations int `json:"confirmations"`
Miner string `json:"miner"`
Txs []struct {
Type string `json:"type"`
Network string `json:"network"`
BlockNo int `json:"block_no"`
Height int `json:"height"`
Index int `json:"index"`
Time int `json:"time"`
Txid string `json:"txid"`
Fee string `json:"fee"`
Confirmations int `json:"confirmations"`
Inputs []struct {
InputNo int `json:"input_no"`
Address string `json:"address"`
Value string `json:"value"`
} `json:"inputs"`
Outputs []struct {
OutputNo int `json:"output_no"`
Address string `json:"address"`
Value string `json:"value"`
} `json:"outputs"`
InputCnt int `json:"inputCnt"`
OutputCnt int `json:"outputCnt"`
} `json:"txs"`
SentValue string `json:"sent_value"`
MiningDifficulty string `json:"mining_difficulty"`
Merkleroot string `json:"merkleroot"`
TxCnt int `json:"txCnt"`
}
//BlockHeader 区块头详情
//https://services.tokenview.com/vipapi/block/{公链简称小写}/{块高或块hash}?apikey={apikey}
func (t *TokenViewAPI) BlockHeader(coin string, s string) (resp []*respBlockHeader, err error) {
var url = t.setUrl(pathBlockHeader, coin, s)
err = t.do(url, &resp)
return
}
type respBlock struct {
Type string `json:"type"`
Network string `json:"network"`
BlockNo int `json:"block_no"`
Height int `json:"height"`
BlockHash string `json:"blockHash"`
Index int `json:"index"`
Time int `json:"time"`
Txid string `json:"txid"`
Fee string `json:"fee"`
Confirmations int `json:"confirmations"`
From string `json:"from"`
To string `json:"to"`
Nonce int `json:"nonce"`
ToIsContract int `json:"toIsContract"`
GasPrice int64 `json:"gasPrice"`
GasLimit int `json:"gasLimit"`
Value string `json:"value"`
GasUsed int `json:"gasUsed"`
TokenTransfer []struct {
Index int `json:"index"`
Token string `json:"token"`
TokenAddr string `json:"tokenAddr"`
TokenSymbol string `json:"tokenSymbol"`
TokenDecimals string `json:"tokenDecimals"`
TokenInfo struct {
H string `json:"h"`
F string `json:"f"`
S string `json:"s"`
D string `json:"d"`
} `json:"tokenInfo"`
From string `json:"from"`
To string `json:"to"`
Value string `json:"value"`
} `json:"tokenTransfer"`
}
//BlockTx 区块交易列表
//https://services.tokenview.com/vipapi/{公链简称小写}/{块高}/{页码}/{每页交易条数}?apikey={apikey}
func (t *TokenViewAPI) Block(coin string, height, page, num int) (resp []*respBlock, err error) {
var url = t.setUrl(pathBlock, coin, height, page, num)
err = t.do(url, &resp)
return
}
type respBlocks struct {
Network string `json:"network"`
BlockNo int `json:"block_no"`
Time int `json:"time"`
Size int `json:"size"`
TxCnt int `json:"txCnt"`
SentValue string `json:"sentValue"`
Miner string `json:"miner"`
Fee string `json:"fee"`
Reward string `json:"reward"`
MiningDifficulty string `json:"miningDifficulty"`
GasLimit int `json:"gasLimit"`
GasPrice int64 `json:"gasPrice"`
GasUsed int `json:"gasUsed"`
}
//Blocks 区块列表
//https://services.tokenview.com/vipapi/blocks/{公链简称}/{页码}/{每页大小}?apikey={apikey}
func (t *TokenViewAPI) Blocks(coin string, page, num int) (resp []*respBlocks, err error) {
var url = t.setUrl(pathBlocks, coin, page, num)
err = t.do(url, &resp)
return
}
type respTxDetail struct {
Type string `json:"type"`
Network string `json:"network"`
BlockNo int `json:"block_no"`
Height int `json:"height"`
BlockHash string `json:"blockHash"`
Index int `json:"index"`
Time int `json:"time"`
Txid string `json:"txid"`
Fee string `json:"fee"`
Confirmations int `json:"confirmations"`
From string `json:"from"`
To string `json:"to"`
Nonce int `json:"nonce"`
ToIsContract int `json:"toIsContract"`
GasPrice int `json:"gasPrice"`
GasLimit int `json:"gasLimit"`
Value string `json:"value"`
InputData string `json:"inputData"`
GasUsed int `json:"gasUsed"`
TraceErr string `json:"traceErr"`
ReceiptErr string `json:"receiptErr"`
}
//TxDetail 某笔交易的交易详情
//https://services.tokenview.com/vipapi/tx/{公链简称小写}/{交易hash}?apikey={apikey}
func (t *TokenViewAPI) TxDetail(coin, hash string) (resp *respTxDetail, err error) {
var url = t.setUrl(pathTxDetail, coin, hash)
err = t.do(url, &resp)
return
}
type respTxConfirmation struct {
Network string `json:"network"`
TxId string `json:"txId"`
Confirmation int `json:"confirmation"`
}
//某笔交易的确认数
//https://services.tokenview.com/vipapi/tx/confirmation/{公链简称小写}/{交易hash}?apikey={apikey}
func (t *TokenViewAPI) TxConfirmation(coin, hash string) (resp *respTxConfirmation, err error) {
var url = t.setUrl(pathTxConfirmation, coin, hash)
err = t.do(url, &resp)
return
}
type respAddrMining struct {
Type string `json:"type"`
Network string `json:"network"`
BlockNo int `json:"block_no"`
Time int `json:"time"`
Fee string `json:"fee"`
Blockhash string `json:"blockhash"`
Reward string `json:"reward"`
Size int `json:"size"`
PreviousBlockhash string `json:"previous_blockhash"`
Confirmations int `json:"confirmations"`
Miner string `json:"miner"`
Txs []interface{} `json:"txs"`
Merkleroot string `json:"merkleroot"`
UnclesReward string `json:"unclesReward"`
MixHash string `json:"mixHash"`
GasLimit int `json:"gasLimit"`
LowestGasPrice int64 `json:"lowestGasPrice"`
GasUsed int `json:"gasUsed"`
Nonce string `json:"nonce"`
Sha3Uncles string `json:"sha3Uncles"`
ReceiptsRoot string `json:"receiptsRoot"`
CallTxCnt int `json:"callTxCnt"`
TokenTxCnt int `json:"tokenTxCnt"`
SentValue string `json:"sent_value"`
ExtraData string `json:"extraData"`
MiningDifficulty string `json:"mining_difficulty"`
TotalDifficulty string `json:"totalDifficulty"`
TxCnt int `json:"txCnt"`
Uncles []interface{} `json:"uncles"`
BaseFeePerGas int64 `json:"baseFeePerGas"`
BurntFee string `json:"burntFee"`
}
//ETH/ETC 等公链地址挖出的区块列表
//https://services.tokenview.com/vipapi/{公链简称小写}/address/mining/{address}/{页码}/{每页条数}?apikey={apikey}
func (t *TokenViewAPI) AddrMining(coin, addr string, page, num int) (resp []*respAddrMining, err error) {
var url = t.setUrl(pathAddrMining, coin, addr, page, num)
err = t.do(url, &resp)
return
}