forked from planetdecred/dcrlibwallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
530 lines (457 loc) · 15.3 KB
/
types.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
package dcrlibwallet
import (
"context"
"fmt"
"net"
"decred.org/dcrwallet/v2/wallet/udb"
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/dcrutil/v4"
"github.com/planetdecred/dcrlibwallet/internal/vsp"
)
// WalletConfig defines options for configuring wallet behaviour.
// This is a subset of the config used by dcrwallet.
type WalletConfig struct {
// General
GapLimit uint32 // Allowed unused address gap between used addresses of accounts
ManualTickets bool // Do not discover new tickets through network synchronization
AllowHighFees bool // Do not perform high fee checks
RelayFee dcrutil.Amount // Transaction fee per kilobyte
AccountGapLimit int // Allowed gap of unused accounts
DisableCoinTypeUpgrades bool // Never upgrade from legacy to SLIP0044 coin type keys
// CSPP
MixSplitLimit int // Connection limit to CoinShuffle++ server per change amount
}
type CSPPConfig struct {
CSPPServer string
DialCSPPServer func(ctx context.Context, network, addr string) (net.Conn, error)
MixedAccount uint32
MixedAccountBranch uint32
TicketSplitAccount uint32
ChangeAccount uint32
}
type WalletsIterator struct {
currentIndex int
wallets []*Wallet
}
type BlockInfo struct {
Height int32
Timestamp int64
}
type Amount struct {
AtomValue int64
DcrValue float64
}
type TxFeeAndSize struct {
Fee *Amount
Change *Amount
EstimatedSignedSize int
}
type UnsignedTransaction struct {
UnsignedTransaction []byte
EstimatedSignedSize int
ChangeIndex int
TotalOutputAmount int64
TotalPreviousOutputAmount int64
}
type Balance struct {
Total int64
Spendable int64
ImmatureReward int64
ImmatureStakeGeneration int64
LockedByTickets int64
VotingAuthority int64
UnConfirmed int64
}
type Account struct {
WalletID int
Number int32
Name string
Balance *Balance
TotalBalance int64
ExternalKeyCount int32
InternalKeyCount int32
ImportedKeyCount int32
}
type AccountsIterator struct {
currentIndex int
accounts []*Account
}
type Accounts struct {
Count int
Acc []*Account
CurrentBlockHash []byte
CurrentBlockHeight int32
}
type PeerInfo struct {
ID int32 `json:"id"`
Addr string `json:"addr"`
AddrLocal string `json:"addr_local"`
Services string `json:"services"`
Version uint32 `json:"version"`
SubVer string `json:"sub_ver"`
StartingHeight int64 `json:"starting_height"`
BanScore int32 `json:"ban_score"`
}
type AccountMixerNotificationListener interface {
OnAccountMixerStarted(walletID int)
OnAccountMixerEnded(walletID int)
}
/** begin sync-related types */
type SyncProgressListener interface {
OnSyncStarted(wasRestarted bool)
OnPeerConnectedOrDisconnected(numberOfConnectedPeers int32)
OnCFiltersFetchProgress(cfiltersFetchProgress *CFiltersFetchProgressReport)
OnHeadersFetchProgress(headersFetchProgress *HeadersFetchProgressReport)
OnAddressDiscoveryProgress(addressDiscoveryProgress *AddressDiscoveryProgressReport)
OnHeadersRescanProgress(headersRescanProgress *HeadersRescanProgressReport)
OnSyncCompleted()
OnSyncCanceled(willRestart bool)
OnSyncEndedWithError(err error)
Debug(debugInfo *DebugInfo)
}
type GeneralSyncProgress struct {
TotalSyncProgress int32 `json:"totalSyncProgress"`
TotalTimeRemainingSeconds int64 `json:"totalTimeRemainingSeconds"`
}
type CFiltersFetchProgressReport struct {
*GeneralSyncProgress
beginFetchCFiltersTimeStamp int64
startCFiltersHeight int32
cfiltersFetchTimeSpent int64
totalFetchedCFiltersCount int32
TotalCFiltersToFetch int32 `json:"totalCFiltersToFetch"`
CurrentCFilterHeight int32 `json:"currentCFilterHeight"`
CFiltersFetchProgress int32 `json:"headersFetchProgress"`
}
type HeadersFetchProgressReport struct {
*GeneralSyncProgress
headersFetchTimeSpent int64
beginFetchTimeStamp int64
startHeaderHeight int32
totalFetchedHeadersCount int32
TotalHeadersToFetch int32 `json:"totalHeadersToFetch"`
CurrentHeaderHeight int32 `json:"currentHeaderHeight"`
CurrentHeaderTimestamp int64 `json:"currentHeaderTimestamp"`
HeadersFetchProgress int32 `json:"headersFetchProgress"`
}
type AddressDiscoveryProgressReport struct {
*GeneralSyncProgress
addressDiscoveryStartTime int64
totalDiscoveryTimeSpent int64
AddressDiscoveryProgress int32 `json:"addressDiscoveryProgress"`
WalletID int `json:"walletID"`
}
type HeadersRescanProgressReport struct {
*GeneralSyncProgress
TotalHeadersToScan int32 `json:"totalHeadersToScan"`
CurrentRescanHeight int32 `json:"currentRescanHeight"`
RescanProgress int32 `json:"rescanProgress"`
RescanTimeRemaining int64 `json:"rescanTimeRemaining"`
WalletID int `json:"walletID"`
}
type DebugInfo struct {
TotalTimeElapsed int64
TotalTimeRemaining int64
CurrentStageTimeElapsed int64
CurrentStageTimeRemaining int64
}
/** end sync-related types */
/** begin tx-related types */
type TxAndBlockNotificationListener interface {
OnTransaction(transaction string)
OnBlockAttached(walletID int, blockHeight int32)
OnTransactionConfirmed(walletID int, hash string, blockHeight int32)
}
// asyncTxAndBlockNotificationListener is a TxAndBlockNotificationListener that
// triggers notifcation callbacks asynchronously.
type asyncTxAndBlockNotificationListener struct {
l TxAndBlockNotificationListener
}
// OnTransaction satisfies the TxAndBlockNotificationListener interface and
// starts a goroutine to actually handle the notification using the embedded
// listener.
func (asyncTxBlockListener *asyncTxAndBlockNotificationListener) OnTransaction(transaction string) {
go asyncTxBlockListener.l.OnTransaction(transaction)
}
// OnBlockAttached satisfies the TxAndBlockNotificationListener interface and
// starts a goroutine to actually handle the notification using the embedded
// listener.
func (asyncTxBlockListener *asyncTxAndBlockNotificationListener) OnBlockAttached(walletID int, blockHeight int32) {
go asyncTxBlockListener.l.OnBlockAttached(walletID, blockHeight)
}
// OnTransactionConfirmed satisfies the TxAndBlockNotificationListener interface
// and starts a goroutine to actually handle the notification using the embedded
// listener.
func (asyncTxBlockListener *asyncTxAndBlockNotificationListener) OnTransactionConfirmed(walletID int, hash string, blockHeight int32) {
go asyncTxBlockListener.l.OnTransactionConfirmed(walletID, hash, blockHeight)
}
type BlocksRescanProgressListener interface {
OnBlocksRescanStarted(walletID int)
OnBlocksRescanProgress(*HeadersRescanProgressReport)
OnBlocksRescanEnded(walletID int, err error)
}
// Transaction is used with storm for tx indexing operations.
// For faster queries, the `Hash`, `Type` and `Direction` fields are indexed.
type Transaction struct {
WalletID int `json:"walletID"`
Hash string `storm:"id,unique" json:"hash"`
Type string `storm:"index" json:"type"`
Hex string `json:"hex"`
Timestamp int64 `storm:"index" json:"timestamp"`
BlockHeight int32 `storm:"index" json:"block_height"`
TicketSpender string `storm:"index" json:"ticket_spender"`
MixDenomination int64 `json:"mix_denom"`
MixCount int32 `json:"mix_count"`
Version int32 `json:"version"`
LockTime int32 `json:"lock_time"`
Expiry int32 `json:"expiry"`
Fee int64 `json:"fee"`
FeeRate int64 `json:"fee_rate"`
Size int `json:"size"`
Direction int32 `storm:"index" json:"direction"`
Amount int64 `json:"amount"`
Inputs []*TxInput `json:"inputs"`
Outputs []*TxOutput `json:"outputs"`
// Vote Info
VoteVersion int32 `json:"vote_version"`
LastBlockValid bool `json:"last_block_valid"`
VoteBits string `json:"vote_bits"`
VoteReward int64 `json:"vote_reward"`
TicketSpentHash string `storm:"unique" json:"ticket_spent_hash"`
DaysToVoteOrRevoke int32 `json:"days_to_vote_revoke"`
}
type TxInput struct {
PreviousTransactionHash string `json:"previous_transaction_hash"`
PreviousTransactionIndex int32 `json:"previous_transaction_index"`
PreviousOutpoint string `json:"previous_outpoint"`
Amount int64 `json:"amount"`
AccountNumber int32 `json:"account_number"`
}
type TxOutput struct {
Index int32 `json:"index"`
Amount int64 `json:"amount"`
Version int32 `json:"version"`
ScriptType string `json:"script_type"`
Address string `json:"address"`
Internal bool `json:"internal"`
AccountNumber int32 `json:"account_number"`
}
// TxInfoFromWallet contains tx data that relates to the querying wallet.
// This info is used with `DecodeTransaction` to compose the entire details of a transaction.
type TxInfoFromWallet struct {
WalletID int
Hex string
Timestamp int64
BlockHeight int32
Inputs []*WalletInput
Outputs []*WalletOutput
}
type WalletInput struct {
Index int32 `json:"index"`
AmountIn int64 `json:"amount_in"`
*WalletAccount
}
type WalletOutput struct {
Index int32 `json:"index"`
AmountOut int64 `json:"amount_out"`
Internal bool `json:"internal"`
Address string `json:"address"`
*WalletAccount
}
type WalletAccount struct {
AccountNumber int32 `json:"account_number"`
AccountName string `json:"account_name"`
}
type TransactionDestination struct {
Address string
AtomAmount int64
SendMax bool
}
type TransactionOverview struct {
All int
Sent int
Received int
Transferred int
Mixed int
Staking int
Coinbase int
}
/** end tx-related types */
/** begin ticket-related types */
type TicketPriceResponse struct {
TicketPrice int64
Height int32
}
type StakingOverview struct {
All int
Unmined int
Immature int
Live int
Voted int
Revoked int
Expired int
}
// TicketBuyerConfig defines configuration parameters for running
// an automated ticket buyer.
type TicketBuyerConfig struct {
VspHost string
PurchaseAccount int32
BalanceToMaintain int64
vspClient *vsp.Client
}
// VSPFeeStatus represents the current fee status of a ticket.
type VSPFeeStatus uint8
const (
// VSPFeeProcessStarted represents the state which process has being
// called but fee still not paid.
VSPFeeProcessStarted VSPFeeStatus = iota
// VSPFeeProcessPaid represents the state where the process has being
// paid, but not published.
VSPFeeProcessPaid
VSPFeeProcessErrored
// VSPFeeProcessConfirmed represents the state where the fee has been
// confirmed by the VSP.
VSPFeeProcessConfirmed
)
// String returns a human-readable interpretation of the vsp fee status.
func (status VSPFeeStatus) String() string {
switch udb.FeeStatus(status) {
case udb.VSPFeeProcessStarted:
return "fee process started"
case udb.VSPFeeProcessPaid:
return "fee paid"
case udb.VSPFeeProcessErrored:
return "fee payment errored"
case udb.VSPFeeProcessConfirmed:
return "fee confirmed by vsp"
default:
return fmt.Sprintf("invalid fee status %d", status)
}
}
// VSPTicketInfo is information about a ticket that is assigned to a VSP.
type VSPTicketInfo struct {
VSP string
FeeTxHash string
FeeTxStatus VSPFeeStatus
// ConfirmedByVSP is nil if the ticket status could not be obtained
// from the VSP, false if the VSP hasn't confirmed the fee and true
// if the VSP has fully registered the ticket.
ConfirmedByVSP *bool
// VoteChoices is only set if the ticket status was obtained from the
// VSP.
VoteChoices map[string]string
}
/** end ticket-related types */
/** begin politeia types */
type Proposal struct {
ID int `storm:"id,increment"`
Token string `json:"token" storm:"unique"`
Category int32 `json:"category" storm:"index"`
Name string `json:"name"`
State int32 `json:"state"`
Status int32 `json:"status"`
Timestamp int64 `json:"timestamp"`
UserID string `json:"userid"`
Username string `json:"username"`
NumComments int32 `json:"numcomments"`
Version string `json:"version"`
PublishedAt int64 `json:"publishedat"`
IndexFile string `json:"indexfile"`
IndexFileVersion string `json:"fileversion"`
VoteStatus int32 `json:"votestatus"`
VoteApproved bool `json:"voteapproved"`
YesVotes int32 `json:"yesvotes"`
NoVotes int32 `json:"novotes"`
EligibleTickets int32 `json:"eligibletickets"`
QuorumPercentage int32 `json:"quorumpercentage"`
PassPercentage int32 `json:"passpercentage"`
}
type ProposalOverview struct {
All int32
Discussion int32
Voting int32
Approved int32
Rejected int32
Abandoned int32
}
type ProposalVoteDetails struct {
EligibleTickets []*EligibleTicket
Votes []*ProposalVote
YesVotes int32
NoVotes int32
}
type EligibleTicket struct {
Hash string
Address string
}
type ProposalVote struct {
Ticket *EligibleTicket
Bit string
}
type ProposalNotificationListener interface {
OnProposalsSynced()
OnNewProposal(proposal *Proposal)
OnProposalVoteStarted(proposal *Proposal)
OnProposalVoteFinished(proposal *Proposal)
}
/** end politea proposal types */
type UnspentOutput struct {
TransactionHash []byte
OutputIndex uint32
OutputKey string
ReceiveTime int64
Amount int64
FromCoinbase bool
Tree int32
PkScript []byte
Addresses string // separated by commas
Confirmations int32
}
/** end politea proposal types */
/** begin vspd-related types */
type VspInfoResponse struct {
APIVersions []int64 `json:"apiversions"`
Timestamp int64 `json:"timestamp"`
PubKey []byte `json:"pubkey"`
FeePercentage float64 `json:"feepercentage"`
VspClosed bool `json:"vspclosed"`
Network string `json:"network"`
VspdVersion string `json:"vspdversion"`
Voting int64 `json:"voting"`
Voted int64 `json:"voted"`
Revoked int64 `json:"revoked"`
}
type VSP struct {
Host string
*VspInfoResponse
}
/** end vspd-related types */
/** begin agenda types */
// Agenda contains information about a consensus deployment
type Agenda struct {
AgendaID string `json:"agenda_id"`
Description string `json:"description"`
Mask uint32 `json:"mask"`
Choices []chaincfg.Choice `json:"choices"`
VotingPreference string `json:"voting_preference"`
StartTime int64 `json:"start_time"`
ExpireTime int64 `json:"expire_time"`
Status string `json:"status"`
}
// DcrdataAgenda models agenda information for the active network from the
// dcrdata api https://dcrdata.decred.org/api/agendas for mainnet or
// https://testnet.decred.org/api/agendas for testnet.
type DcrdataAgenda struct {
Name string `json:"name"`
Description string `json:"-"`
Status string `json:"status"`
VotingStarted int64 `json:"-"`
VotingDone int64 `json:"-"`
Activated int64 `json:"-"`
HardForked int64 `json:"-"`
StartTime string `json:"-"`
ExpireTime string `json:"-"`
VoteVersion uint32 `json:"-"`
Mask uint16 `json:"-"`
}
/** end agenda types */