/
apitypes.go
773 lines (684 loc) · 24.7 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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
// Copyright (c) 2019, The Decred developers
// Copyright (c) 2017, Jonathan Chappelow
// See LICENSE for details.
package types
import (
"encoding/json"
"fmt"
"strings"
"sync"
"time"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types"
"github.com/decred/dcrdata/db/dbtypes/v2"
"github.com/decred/dcrdata/txhelpers/v3"
)
// TimeAPI is a fall back dbtypes.TimeDef wrapper that allows API endpoints that
// previously returned a timestamp instead of a formatted string time to continue
// working.
type TimeAPI struct {
S dbtypes.TimeDef
}
// String formats the time in a human-friendly layout.
func (t TimeAPI) String() string {
return t.S.String()
}
// UNIX returns the UNIX epoch time stamp.
func (t TimeAPI) UNIX() int64 {
return t.S.UNIX()
}
// MarshalJSON is set as the default marshalling function for TimeAPI struct.
func (t *TimeAPI) MarshalJSON() ([]byte, error) {
return json.Marshal(t.S.UNIX())
}
// UnmarshalJSON implements json.Unmarshaler.
func (t *TimeAPI) UnmarshalJSON(data []byte) error {
if t == nil {
return fmt.Errorf("TimeAPI: UnmarshalJSON on nil pointer")
}
var ts int64
if err := json.Unmarshal(data, &ts); err != nil {
return err
}
*t = NewTimeAPIFromUNIX(ts)
return nil
}
// NewTimeAPI constructs a TimeAPI from the given time.Time. It presets the
// timezone for formatting to UTC.
func NewTimeAPI(t time.Time) TimeAPI {
return TimeAPI{
S: dbtypes.NewTimeDef(t),
}
}
// NewTimeAPIFromUNIX constructs a TimeAPI from the given UNIX epoch time stamp
// in seconds. It presets the timezone for formatting to UTC.
func NewTimeAPIFromUNIX(t int64) TimeAPI {
return NewTimeAPI(time.Unix(t, 0))
}
// much of the time, dcrdata will be using the types in chainjson, 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 []chainjson.Vin `json:"vin"`
Vout []Vout `json:"vout"`
}
// AgendasInfo holds the high level details about an agenda.
type AgendasInfo struct {
Name string `json:"name"`
Description string `json:"description"`
*dbtypes.MileStone
VoteVersion uint32 `json:"voteversion"`
Mask uint16 `json:"mask"`
}
// AgendaAPIResponse holds two sets of AgendaVoteChoices charts data.
type AgendaAPIResponse struct {
ByHeight *dbtypes.AgendaVoteChoices `json:"by_height"`
ByTime *dbtypes.AgendaVoteChoices `json:"by_time"`
}
// 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 []chainjson.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"`
}
// BlockRaw contains the hexadecimal encoded bytes of a serialized block.
type BlockRaw struct {
Height uint32 `json:"height"`
Hash string `json:"hash"`
Hex string `json:"hex"`
}
// 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"`
}
// ScriptClass represent the type of a transaction output's pkscript. The values
// of this type are NOT compatible with dcrd's txscript.ScriptClass values! Use
// ScriptClassFromName to get a text representation of a ScriptClass.
type ScriptClass uint8
// Classes of script payment known about in the blockchain.
const (
ScriptClassNonStandard ScriptClass = iota // None of the recognized forms.
ScriptClassPubKey // Pay pubkey.
ScriptClassPubkeyAlt // Alternative signature pubkey.
ScriptClassPubKeyHash // Pay pubkey hash.
ScriptClassPubkeyHashAlt // Alternative signature pubkey hash.
ScriptClassScriptHash // Pay to script hash.
ScriptClassMultiSig // Multi signature.
ScriptClassNullData // Empty data-only (provably prunable).
ScriptClassStakeSubmission // Stake submission.
ScriptClassStakeGen // Stake generation
ScriptClassStakeRevocation // Stake revocation.
ScriptClassStakeSubChange // Change for stake submission tx.
ScriptClassInvalid
)
var scriptClassToName = map[ScriptClass]string{
ScriptClassNonStandard: "nonstandard",
ScriptClassPubKey: "pubkey",
ScriptClassPubkeyAlt: "pubkeyalt",
ScriptClassPubKeyHash: "pubkeyhash",
ScriptClassPubkeyHashAlt: "pubkeyhashalt",
ScriptClassScriptHash: "scripthash",
ScriptClassMultiSig: "multisig",
ScriptClassNullData: "nulldata",
ScriptClassStakeSubmission: "stakesubmission",
ScriptClassStakeGen: "stakegen",
ScriptClassStakeRevocation: "stakerevoke",
ScriptClassStakeSubChange: "sstxchange",
ScriptClassInvalid: "invalid",
}
var scriptNameToClass = map[string]ScriptClass{
"nonstandard": ScriptClassNonStandard,
"pubkey": ScriptClassPubKey,
"pubkeyalt": ScriptClassPubkeyAlt,
"pubkeyhash": ScriptClassPubKeyHash,
"pubkeyhashalt": ScriptClassPubkeyHashAlt,
"scripthash": ScriptClassScriptHash,
"multisig": ScriptClassMultiSig,
"nulldata": ScriptClassNullData,
"stakesubmission": ScriptClassStakeSubmission,
"stakegen": ScriptClassStakeGen,
"stakerevoke": ScriptClassStakeRevocation,
"sstxchange": ScriptClassStakeSubChange,
// No "invalid" mapping!
}
// ScriptClassFromName attempts to identify the ScriptClass for the given script
// class/type name. An unknown script name will return ScriptClassInvalid. This
// may be used to map the Type field of the ScriptPubKey data type to a known
// class. If dcrd's txscript package changes its strings, this function may be
// unable to identify the types from dcrd.
func ScriptClassFromName(name string) ScriptClass {
class, found := scriptNameToClass[strings.ToLower(name)]
if !found {
return ScriptClassInvalid // not even non-standard
}
return class
}
// IsValidScriptClass indicates the the provided string corresponds to a known
// ScriptClass (including "nonstandard"). Note that "invalid" is not valid,
// although a ScriptClassInvalid value mapping to "invalid" exists.
func IsValidScriptClass(name string) (isValid bool) {
_, isValid = scriptNameToClass[strings.ToLower(name)]
return
}
// String returns the name of the ScriptClass. If the ScriptClass is
// unrecognized it is treated as ScriptClassInvalid.
func (sc ScriptClass) String() string {
name, found := scriptClassToName[sc]
if !found {
return ScriptClassInvalid.String() // better be in scriptClassToName!
}
return name
}
// IsNullDataScript indicates if the script class name is a nulldata class.
func IsNullDataScript(name string) bool {
return name == ScriptClassNullData.String()
}
// ScriptPubKey is the result of decodescript(ScriptPubKeyHex)
type ScriptPubKey struct {
Asm string `json:"asm"`
Hex string `json:"hex"`
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"`
ScriptPubKeyDecoded ScriptPubKey `json:"scriptPubKey"`
}
// 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 []chainjson.VinPrevOut `json:"vin"`
Vout []Vout `json:"vout"`
Confirmations int64 `json:"confirmations"`
BlockHash string `json:"blockhash"`
Time TimeAPI `json:"time,omitempty"`
Blocktime TimeAPI `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 TimeAPI `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
// chainjson.GetBlockVerboseResult to include the stake transaction type
type BlockDataWithTxType struct {
*chainjson.GetBlockVerboseResult
Votes []TxRawWithVoteInfo
Tickets []chainjson.TxRawResult
Revs []chainjson.TxRawResult
}
// TxRawWithVoteInfo adds the vote info to chainjson.TxRawResult
type TxRawWithVoteInfo struct {
chainjson.TxRawResult
VoteInfo VoteInfo
}
// TxRawWithTxType adds the stake transaction type to chainjson.TxRawResult
type TxRawWithTxType struct {
chainjson.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 chainjson
// Status indicates the state of the server. All fields are mutex protected and
// and should be set with the getters and setters.
type Status struct {
sync.RWMutex
ready bool
dbHeight uint32
dbLastBlockTime int64
height uint32
nodeConnections int64
api APIStatus
}
// APIStatus is for the JSON-formatted response at /status.
type APIStatus 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"`
NetworkName string `json:"network_name"`
}
// NewStatus is the constructor for a new Status.
func NewStatus(nodeHeight uint32, conns int64, apiVersion int, dcrdataVersion, netName string) *Status {
return &Status{
height: nodeHeight,
nodeConnections: conns,
api: APIStatus{
APIVersion: apiVersion,
DcrdataVersion: dcrdataVersion,
NetworkName: netName,
},
}
}
// API is a method for creating an APIStatus from Status.
func (s *Status) API() APIStatus {
s.RLock()
defer s.RUnlock()
return APIStatus{
Ready: s.ready,
DBHeight: s.dbHeight,
DBLastBlockTime: s.dbLastBlockTime,
Height: s.height,
NodeConnections: s.nodeConnections,
APIVersion: s.api.APIVersion,
DcrdataVersion: s.api.DcrdataVersion,
NetworkName: s.api.NetworkName,
}
}
// Happy describes just how happy dcrdata is.
type Happy struct {
Happy bool `json:"happy"`
APIReady bool `json:"api_ready"`
TipAge int64 `json:"tip_age"`
NodeConnections int64 `json:"node_connections"`
}
// Happy indicates how dcrdata is or isn't happy.
func (s *Status) Happy() Happy {
s.RLock()
blockAge := time.Since(time.Unix(s.dbLastBlockTime, 0))
h := Happy{
APIReady: s.ready, // The DB is serving data from the network's best block.
TipAge: int64(blockAge.Seconds()),
NodeConnections: s.nodeConnections,
}
blocksBehind := s.height - s.dbHeight
s.RUnlock()
// If the DB is at node height, the age of the best block may be fairly
// large, corresponding to an extremely low likelihood block interval.
blockAgeLimit := 90 * time.Minute
// If the DB is not at node height, allow the DB to lag if the age of the
// best block in the DB is very recent, suggesting that the network's best
// block may still be processing.
if blocksBehind > 0 {
blockAgeLimit = 30 * time.Second // processing rarely takes longer than a couple seconds
}
h.Happy = blockAge < blockAgeLimit && h.NodeConnections > 0
return h
}
// Height is the last known node height.
func (s *Status) Height() uint32 {
s.RLock()
defer s.RUnlock()
return s.height
}
// SetHeight stores the node height. Additionally, Status.ready is set to true
// if Status.height is the same as Status.dbHeight.
func (s *Status) SetHeight(height uint32) {
s.Lock()
s.ready = height == s.dbHeight && s.nodeConnections > 0
s.height = height
s.Unlock()
}
// DBHeight is the block most recently stored in the DB.
func (s *Status) DBHeight() uint32 {
s.RLock()
defer s.RUnlock()
return s.dbHeight
}
// NodeConnections gets the number of node peer connections.
func (s *Status) NodeConnections() int64 {
s.RLock()
defer s.RUnlock()
return s.nodeConnections
}
// SetConnections sets the node connection count.
func (s *Status) SetConnections(conns int64) {
s.Lock()
s.nodeConnections = conns
s.ready = s.ready && s.nodeConnections > 0
s.Unlock()
}
// SetReady sets the ready state.
func (s *Status) SetReady(ready bool) {
s.Lock()
s.ready = ready
s.Unlock()
}
// Ready checks the ready state.
func (s *Status) Ready() bool {
s.Lock()
defer s.Unlock()
return s.ready
}
// DBUpdate updates both the height and time of the best DB block. Status.ready
// is set to true if Status.height is the same as Status.dbHeight and the node
// has connections.
func (s *Status) DBUpdate(height uint32, blockTime int64) {
s.Lock()
s.dbHeight = height
s.dbLastBlockTime = blockTime
s.ready = s.dbHeight == s.height
s.Unlock()
}
// 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 a block.
type BlockDataBasic struct {
Height uint32 `json:"height"`
Size uint32 `json:"size"`
Hash string `json:"hash"`
Difficulty float64 `json:"diff"`
StakeDiff float64 `json:"sdiff"`
Time TimeAPI `json:"time"`
NumTx uint32 `json:"txlength"`
MiningFee *int64 `json:"fees,omitempty"`
TotalSent *int64 `json:"total_sent,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 dbtypes.TimeDef `json:"time"`
BlockExplorerExtraInfo
}
// BlockExplorerExtraInfo contains supplemental block metadata used by the
// explorer.
type BlockExplorerExtraInfo struct {
TxLen int `json:"tx"`
CoinSupply int64 `json:"coin_supply"`
NextBlockSubsidy *chainjson.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 {
chainjson.GetStakeDifficultyResult
Estimates chainjson.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 {
Hash string `json:"hash"`
Feeinfo chainjson.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 {
Hash string `json:"hash"`
Feeinfo chainjson.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"`
chainjson.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
// TicketInfo combines spend and pool statuses and relevant block and spending
// transaction IDs.
type TicketInfo struct {
Status string `json:"status"`
PurchaseBlock *TinyBlock `json:"purchase_block"`
MaturityHeight uint32 `json:"maturity_height"`
ExpirationHeight uint32 `json:"expiration_height"`
LotteryBlock *TinyBlock `json:"lottery_block"`
Vote *string `json:"vote"`
Revocation *string `json:"revocation"`
}
// TinyBlock is the hash and height of a block.
type TinyBlock struct {
Hash string `json:"hash"`
Height uint32 `json:"height"`
}
// TicketPoolChartsData is for data used to display ticket pool statistics at
// /ticketpool.
type TicketPoolChartsData struct {
ChartHeight uint64 `json:"height"`
TimeChart *dbtypes.PoolTicketsData `json:"time_chart"`
PriceChart *dbtypes.PoolTicketsData `json:"price_chart"`
OutputsChart *dbtypes.PoolTicketsData `json:"outputs_chart"`
Mempool *PriceCountTime `json:"mempool"`
}
// PowerlessTicket is the purchase block height and value of a missed or expired
// ticket.
type PowerlessTicket struct {
Height uint32 `json:"h"`
Price float64 `json:"p"`
}
// PowerlessTickets contains expired and missed tickets sorted into slices of
// unspent and revoked.
type PowerlessTickets struct {
Unspent []PowerlessTicket `json:"unspent"`
Revoked []PowerlessTicket `json:"revoked"`
}
// PriceCountTime is a basic set of information about ticket in the mempool.
type PriceCountTime struct {
Price float64 `json:"price"`
Count int `json:"count"`
Time dbtypes.TimeDef `json:"time"`
}