/
types.go
208 lines (177 loc) · 5.72 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
package dcr
import (
"context"
"fmt"
"net"
"decred.org/dcrwallet/v3/wallet/udb"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/libwallet/internal/vsp"
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/dcrutil/v4"
)
// Amount implements the Asset amount interface for the DCR asset
type Amount dcrutil.Amount
// ToCoin returns the float64 version of the DCR formatted asset amount.
func (a Amount) ToCoin() float64 {
return dcrutil.Amount(a).ToCoin()
}
// String returns the string version of the DCR formatted asset amount.
func (a Amount) String() string {
return dcrutil.Amount(a).String()
}
// MulF64 multiplys the Amount with the provided float64 value.
func (a Amount) MulF64(f float64) sharedW.AssetAmount {
return Amount(dcrutil.Amount(a).MulF64(f))
}
// ToInt return the original unformatted amount DCRs
func (a Amount) ToInt() int64 {
return int64(dcrutil.Amount(a))
}
const (
AddressGapLimit uint32 = 20
ImportedAccountNumber = udb.ImportedAddrAccount
DefaultAccountNum = udb.DefaultAccountNum
)
type AccountsIterator struct {
currentIndex int
accounts []*sharedW.Account
}
type WalletsIterator struct {
CurrentIndex int
Wallets []*Asset
}
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 AccountMixerNotificationListener struct {
OnAccountMixerStarted func(walletID int)
OnAccountMixerEnded func(walletID int)
}
/** 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
// Client defines the vsp client needed to process more tickets requests.
Client *vsp.Client
// 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 */
/** 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 */
// TreasuryKeyPolicy records the voting policy for treasury spend transactions
// by a particular key, and possibly for a particular ticket being voted on by a
// VSP.
type TreasuryKeyPolicy struct {
PiKey string `json:"pi_key"`
TicketHash string `json:"ticket_hash"` // nil unless for per-ticket VSP policies
Policy string `json:"policy"`
}