forked from decred/dcrdata
-
Notifications
You must be signed in to change notification settings - Fork 1
/
apitypes.go
352 lines (309 loc) · 11.2 KB
/
apitypes.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// Copyright (c) 2017, Jonathan Chappelow
// See LICENSE for details.
package dcrdataapi
import (
"github.com/decred/dcrd/dcrjson"
"github.com/decred/dcrdata/txhelpers"
)
// much of the time, dcrdata will be using the types in dcrjson, but others are
// defined here
// BlockTransactions models an array of stake and regular transactions for a
// block
type BlockTransactions struct {
Tx []string `json:"tx"`
STx []string `json:"stx"`
}
// tx raw
// tx short (tx raw - extra context)
// txout
// scriptPubKey (hex -> decodescript -> result)
// vout
// vin
// Tx models TxShort with the number of confirmations and block info Block
type Tx struct {
TxShort
Confirmations int64 `json:"confirmations"`
Block *BlockID `json:"block,omitempty"`
}
// TxShort models info about transaction TxID
type TxShort struct {
TxID string `json:"txid"`
Size int32 `json:"size"`
Version int32 `json:"version"`
Locktime uint32 `json:"locktime"`
Expiry uint32 `json:"expiry"`
Vin []dcrjson.Vin `json:"vin"`
Vout []Vout `json:"vout"`
}
// TrimmedTx models data to resemble to result of the decoderawtransaction
// call
type TrimmedTx struct {
TxID string `json:"txid"`
Version int32 `json:"version"`
Locktime uint32 `json:"locktime"`
Expiry uint32 `json:"expiry"`
Vin []dcrjson.Vin `json:"vin"`
Vout []Vout `json:"vout"`
}
// VoteInfo models data about a SSGen transaction (vote)
type VoteInfo struct {
Validation BlockValidation `json:"block_validation"`
Version uint32 `json:"vote_version"`
Bits uint16 `json:"vote_bits"`
Choices []*txhelpers.VoteChoice `json:"vote_choices"`
}
// BlockValidation models data about a vote's decision on a block
type BlockValidation struct {
Hash string `json:"hash"`
Height int64 `json:"height"`
Validity bool `json:"validity"`
}
// BlockID models very basic info about a block
type BlockID struct {
BlockHash string `json:"blockhash"`
BlockHeight int64 `json:"blockheight"`
BlockIndex uint32 `json:"blockindex"`
Time int64 `json:"time"`
BlockTime int64 `json:"blocktime"`
}
// VoutMined appends a best block hash, number of confimations and if a
// transaction is a coinbase to a transaction output
type VoutMined struct {
Vout
BestBlock string `json:"bestblock"`
Confirmations int64 `json:"confirmations"`
Coinbase bool `json:"coinbase"`
}
// Vout defines a transaction output
type Vout struct {
Value float64 `json:"value"`
N uint32 `json:"n"`
Version uint16 `json:"version"`
ScriptPubKeyDecoded ScriptPubKey `json:"scriptPubKey"`
}
// VoutHexScript models the hex script for a transaction output
type VoutHexScript struct {
Value float64 `json:"value"`
N uint32 `json:"n"`
Version uint16 `json:"version"`
ScriptPubKeyHex string `json:"scriptPubKey"`
}
// ScriptPubKey is the result of decodescript(ScriptPubKeyHex)
type ScriptPubKey struct {
Asm string `json:"asm"`
ReqSigs int32 `json:"reqSigs,omitempty"`
Type string `json:"type"`
Addresses []string `json:"addresses,omitempty"`
CommitAmt *float64 `json:"commitamt,omitempty"`
}
// TxOut defines a decred transaction output.
type TxOut struct {
Value float64 `json:"value"`
Version uint16 `json:"version"`
PkScript string `json:"pkscript"`
Addresses []string `json:"addresses,omitempty"`
}
// TxIn defines a decred transaction input.
type TxIn struct {
// Non-witness
PreviousOutPoint OutPoint `json:"prevout"`
Sequence uint32 `json:"sequence"`
// Witness
ValueIn float64 `json:"value"`
BlockHeight uint32 `json:"blockheight"`
BlockIndex uint32 `json:"blockindex"`
SignatureScript string `json:"sigscript"`
}
// OutPoint is used to track previous transaction outputs.
type OutPoint struct {
Hash string `json:"hash"`
Index uint32 `json:"index"`
Tree int8 `json:"tree"`
}
// Address models the address string with the transactions as AddressTxShort
type Address struct {
Address string `json:"address"`
Transactions []*AddressTxShort `json:"address_transactions"`
}
// AddressTxRaw is modeled from SearchRawTransactionsResult but with size in
// place of hex
type AddressTxRaw struct {
Size int32 `json:"size"`
TxID string `json:"txid"`
Version int32 `json:"version"`
Locktime uint32 `json:"locktime"`
Vin []dcrjson.VinPrevOut `json:"vin"`
Vout []Vout `json:"vout"`
Confirmations int64 `json:"confirmations"`
BlockHash string `json:"blockhash"`
Time int64 `json:"time,omitempty"`
Blocktime int64 `json:"blocktime,omitempty"`
}
// AddressTxShort is a subset of AddressTxRaw with just the basic tx details
// pertaining the particular address
type AddressTxShort struct {
TxID string `json:"txid"`
Size int32 `json:"size"`
Time int64 `json:"time"`
Value float64 `json:"value"`
Confirmations int64 `json:"confirmations"`
}
// BlockDataWithTxType adds an array of TxRawWithTxType to
// dcrjson.GetBlockVerboseResult to include the stake transaction type
type BlockDataWithTxType struct {
*dcrjson.GetBlockVerboseResult
Votes []TxRawWithVoteInfo
Tickets []dcrjson.TxRawResult
Revs []dcrjson.TxRawResult
}
// TxRawWithVoteInfo adds the vote info to dcrjson.TxRawResult
type TxRawWithVoteInfo struct {
dcrjson.TxRawResult
VoteInfo VoteInfo
}
// TxRawWithTxType adds the stake transaction type to dcrjson.TxRawResult
type TxRawWithTxType struct {
dcrjson.TxRawResult
TxType string
}
// ScriptSig models the signature script used to redeem the origin transaction
// as a JSON object (non-coinbase txns only)
type ScriptSig struct {
Asm string `json:"asm"`
Hex string `json:"hex"`
}
// PrevOut represents previous output for an input Vin.
type PrevOut struct {
Addresses []string `json:"addresses,omitempty"`
Value float64 `json:"value"`
}
// VinPrevOut is like Vin except it includes PrevOut. It is used by
// searchrawtransaction
type VinPrevOut struct {
Coinbase string `json:"coinbase"`
Stakebase string `json:"stakebase"`
Txid string `json:"txid"`
Vout uint32 `json:"vout"`
Tree int8 `json:"tree"`
AmountIn *float64 `json:"amountin,omitempty"`
BlockHeight *uint32 `json:"blockheight,omitempty"`
BlockIndex *uint32 `json:"blockindex,omitempty"`
ScriptSig *ScriptSig `json:"scriptSig"`
PrevOut *PrevOut `json:"prevOut"`
Sequence uint32 `json:"sequence"`
}
// end copy-paste from dcrjson
// Status indicates the state of the server, including the API version and the
// software version.
type Status struct {
Ready bool `json:"ready"`
DBHeight uint32 `json:"db_height"`
Height uint32 `json:"node_height"`
NodeConnections int64 `json:"node_connections"`
APIVersion int `json:"api_version"`
DcrdataVersion string `json:"dcrdata_version"`
}
// TicketPoolInfo models data about ticket pool
type TicketPoolInfo struct {
Size uint32 `json:"size"`
Value float64 `json:"value"`
ValAvg float64 `json:"valavg"`
}
// TicketPoolValsAndSizes models two arrays, one each for ticket values and
// sizes for blocks StartHeight to EndHeight
type TicketPoolValsAndSizes struct {
StartHeight uint32 `json:"start_height"`
EndHeight uint32 `json:"end_height"`
Value []float64 `json:"value"`
Size []float64 `json:"size"`
}
// BlockDataBasic models primary information about block at height Height
type BlockDataBasic struct {
Height uint32 `json:"height"`
Size uint32 `json:"size"`
Hash string `json:"hash"`
Difficulty float64 `json:"diff"`
StakeDiff float64 `json:"sdiff"`
Time int64 `json:"time"`
//TicketPoolInfo
PoolInfo TicketPoolInfo `json:"ticket_pool"`
}
// BlockExplorerBasic models primary information about block at height Height
// for the block explorer.
type BlockExplorerBasic struct {
Height uint32 `json:"height"`
Size uint32 `json:"size"`
Voters uint16 `json:"votes"`
FreshStake uint8 `json:"tickets"`
Revocations uint8 `json:"revocations"`
StakeDiff float64 `json:"sdiff"`
Time int64 `json:"time"`
BlockExplorerExtraInfo
}
// BlockExplorerExtraInfo contains supplemental block metadata used by the
// explorer.
type BlockExplorerExtraInfo struct {
TxLen int `json:"tx"`
FormattedTime string `json:"formatted_time"`
CoinSupply int64 `json:"coin_supply"`
NextBlockSubsidy *dcrjson.GetBlockSubsidyResult `json:"next_block_subsidy"`
}
// StakeDiff represents data about the evaluated stake difficulty and estimates
type StakeDiff struct {
dcrjson.GetStakeDifficultyResult
Estimates dcrjson.EstimateStakeDiffResult `json:"estimates"`
IdxBlockInWindow int `json:"window_block_index"`
PriceWindowNum int `json:"window_number"`
}
// StakeInfoExtended models data about the fee, pool and stake difficulty
type StakeInfoExtended struct {
Feeinfo dcrjson.FeeInfoBlock `json:"feeinfo"`
StakeDiff float64 `json:"stakediff"`
PriceWindowNum int `json:"window_number"`
IdxBlockInWindow int `json:"window_block_index"`
PoolInfo TicketPoolInfo `json:"ticket_pool"`
}
// StakeInfoExtendedEstimates is similar to StakeInfoExtended but includes stake
// difficulty estimates with the stake difficulty
type StakeInfoExtendedEstimates struct {
Feeinfo dcrjson.FeeInfoBlock `json:"feeinfo"`
StakeDiff StakeDiff `json:"stakediff"`
PriceWindowNum int `json:"window_number"`
IdxBlockInWindow int `json:"window_block_index"`
PoolInfo TicketPoolInfo `json:"ticket_pool"`
}
// MempoolTicketFeeInfo models statistical ticket fee info at block height
// Height
type MempoolTicketFeeInfo struct {
Height uint32 `json:"height"`
Time int64 `json:"time"`
dcrjson.FeeInfoMempool
LowestMineable float64 `json:"lowest_mineable"`
}
// MempoolTicketFees models info about ticket fees at block height Height
type MempoolTicketFees struct {
Height uint32 `json:"height"`
Time int64 `json:"time"`
Length uint32 `json:"length"`
Total uint32 `json:"total"`
FeeRates []float64 `json:"top_fees"`
}
// TicketDetails models details about ticket Hash received at height Height
type TicketDetails struct {
Hash string `json:"hash"`
Fee float64 `json:"abs_fee"`
FeeRate float64 `json:"fee"`
Size int32 `json:"size"`
Height int64 `json:"height_received"`
}
// MempoolTicketDetails models basic mempool info with ticket details Tickets
type MempoolTicketDetails struct {
Height uint32 `json:"height"`
Time int64 `json:"time"`
Length uint32 `json:"length"`
Total uint32 `json:"total"`
Tickets TicketsDetails `json:"tickets"`
}
// TicketsDetails is an array of pointers of TicketDetails used in
// MempoolTicketDetails
type TicketsDetails []*TicketDetails