/
apitypes.go
415 lines (365 loc) · 13.3 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
// Copyright (c) 2017, Jonathan Chappelow
// See LICENSE for details.
package types
import (
"github.com/decred/dcrd/dcrjson"
"github.com/decred/dcrdata/v3/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 RPC.
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"`
}
// Txns models the multi transaction post data structure
type Txns struct {
Transactions []string `json:"transactions"`
}
// 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"`
Spend *TxInputID `json:"spend,omitempty"`
}
// TxInputID specifies a transaction input as hash:vin_index.
type TxInputID struct {
Hash string `json:"hash"`
Index uint32 `json:"vin_index"`
}
// 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"`
}
// AddressTotals represents the number and value of spent and unspent outputs
// for an address.
type AddressTotals struct {
Address string `json:"address"`
BlockHash string `json:"blockhash"`
BlockHeight uint64 `json:"blockheight"`
NumSpent int64 `json:"num_stxos"`
NumUnspent int64 `json:"num_utxos"`
CoinsSpent float64 `json:"dcr_spent"`
CoinsUnspent float64 `json:"dcr_unspent"`
}
// 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,omitempty"`
Hex string `json:"hex,omitempty"`
}
// 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"`
DBLastBlockTime int64 `json:"db_block_time"`
Height uint32 `json:"node_height"`
NodeConnections int64 `json:"node_connections"`
APIVersion int `json:"api_version"`
DcrdataVersion string `json:"dcrdata_version"`
}
// CoinSupply models the coin supply at a certain best block.
type CoinSupply struct {
Height int64 `json:"block_height"`
Hash string `json:"block_hash"`
Mined int64 `json:"supply_mined"`
Ultimate int64 `json:"supply_ultimate"`
}
// TicketPoolInfo models data about ticket pool
type TicketPoolInfo struct {
Height uint32 `json:"height"`
Size uint32 `json:"size"`
Value float64 `json:"value"`
ValAvg float64 `json:"valavg"`
Winners []string `json:"winners"`
}
// 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,omitemtpy"`
Size uint32 `json:"size,omitemtpy"`
Hash string `json:"hash,omitemtpy"`
Difficulty float64 `json:"diff,omitemtpy"`
StakeDiff float64 `json:"sdiff,omitemtpy"`
Time int64 `json:"time,omitemtpy"`
NumTx uint32 `json:"txlength,omitempty"`
// TicketPoolInfo may be nil for side chain blocks.
PoolInfo *TicketPoolInfo `json:"ticket_pool,omitempty"`
}
// NewBlockDataBasic constructs a *BlockDataBasic with pointer fields allocated.
func NewBlockDataBasic() *BlockDataBasic {
return &BlockDataBasic{
PoolInfo: new(TicketPoolInfo),
}
}
// 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"`
}
// BlockTransactionCounts contains the regular and stake transaction counts for
// a block.
type BlockTransactionCounts struct {
Tx int `json:"tx"`
STx int `json:"stx"`
}
// BlockSubsidies contains the block reward proportions for a certain block
// height. The stake_reward is per vote, while total is for a certain number of
// votes.
type BlockSubsidies struct {
BlockNum int64 `json:"height"`
BlockHash string `json:"hash,omitempty"`
Work int64 `json:"work_reward"`
Stake int64 `json:"stake_reward"`
NumVotes int16 `json:"num_votes,omitempty"`
TotalStake int64 `json:"stake_reward_total,omitempty"`
Tax int64 `json:"project_subsidy"`
Total int64 `json:"total,omitempty"`
}
// 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"`
}
// NewStakeInfoExtended constructs a *StakeInfoExtended with pointer fields
// allocated.
func NewStakeInfoExtended() *StakeInfoExtended {
return &StakeInfoExtended{
PoolInfo: new(TicketPoolInfo),
}
}
// 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