-
Notifications
You must be signed in to change notification settings - Fork 16
/
types.go
197 lines (181 loc) · 4.49 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
package governance
import (
"strings"
"github.com/pkg/errors"
"github.com/Oneledger/protocol/chains/bitcoin"
ethchain "github.com/Oneledger/protocol/chains/ethereum"
"github.com/Oneledger/protocol/data/delegation"
"github.com/Oneledger/protocol/data/evidence"
"github.com/Oneledger/protocol/data/fees"
"github.com/Oneledger/protocol/data/network_delegation"
"github.com/Oneledger/protocol/data/ons"
"github.com/Oneledger/protocol/data/rewards"
)
type GovernanceState struct {
FeeOption fees.FeeOption `json:"feeOption"`
ETHCDOption ethchain.ChainDriverOption `json:"ethchaindriverOption"`
BTCCDOption bitcoin.ChainDriverOption `json:"bitcoinChainDriverOption"`
ONSOptions ons.Options `json:"onsOptions"`
PropOptions ProposalOptionSet `json:"propOptions"`
StakingOptions delegation.Options `json:"stakingOptions"`
DelegOptions network_delegation.Options `json:"delegOptions"`
EvidenceOptions evidence.Options `json:"evidenceOptions"`
RewardOptions rewards.Options `json:"rewardOptions"`
}
type (
ProposalID string
ProposalType int
ProposalStatus int
ProposalOutcome int
ProposalState int
VoteOpinion int
VoteResult int
)
func (id ProposalID) String() string {
return string(id)
}
func (id ProposalID) Err() error {
switch {
case len(id) == 0:
return errors.New("proposal id is empty")
case len(id) != SHA256LENGTH:
return errors.New("proposal id length is incorrect")
}
return nil
}
func NewProposalState(prefix string) ProposalState {
prefix = strings.ToLower(prefix)
switch prefix {
case "active":
return ProposalStateActive
case "passed":
return ProposalStatePassed
case "failed":
return ProposalStateFailed
case "finalized":
return ProposalStateFinalized
case "finalizeFailed":
return ProposalStateFinalizeFailed
default:
return ProposalStateInvalid
}
}
func (state ProposalState) String() string {
switch state {
case ProposalStateInvalid:
return "Invalid"
case ProposalStateActive:
return "Active"
case ProposalStatePassed:
return "Passed"
case ProposalStateFailed:
return "Failed"
case ProposalStateFinalized:
return "Finalized"
case ProposalStateFinalizeFailed:
return "FinalizeFailed"
default:
return "Invalid state"
}
}
func NewProposalType(propType string) ProposalType {
propType = strings.ToLower(propType)
switch propType {
case "codechange":
return ProposalTypeCodeChange
case "configupdate":
return ProposalTypeConfigUpdate
case "general":
return ProposalTypeGeneral
default:
return ProposalTypeInvalid
}
}
func (propType ProposalType) String() string {
switch propType {
case ProposalTypeCodeChange:
return "Code change"
case ProposalTypeConfigUpdate:
return "Config update"
case ProposalTypeGeneral:
return "General"
default:
return "Invalid type"
}
}
func (status ProposalStatus) String() string {
switch status {
case ProposalStatusFunding:
return "Funding"
case ProposalStatusVoting:
return "Voting"
case ProposalStatusCompleted:
return "Completed"
default:
return "Invalid status"
}
}
func (outCome ProposalOutcome) String() string {
switch outCome {
case ProposalOutcomeInProgress:
return "In progress"
case ProposalOutcomeInsufficientFunds:
return "Failed [insufficient funds]"
case ProposalOutcomeInsufficientVotes:
return "Failed [insufficient votes]"
case ProposalOutcomeCancelled:
return "Failed [cancelled]"
case ProposalOutcomeCompletedYes:
return "PassedYes"
case ProposalOutcomeCompletedNo:
return "PassedNo"
default:
return "Invalid outcome"
}
}
func NewVoteOpinion(opin string) VoteOpinion {
opin = strings.ToUpper(opin)
switch opin {
case "YES":
return OPIN_POSITIVE
case "NO":
return OPIN_NEGATIVE
case "GIVEUP":
return OPIN_GIVEUP
default:
return OPIN_UNKNOWN
}
}
func (opinion VoteOpinion) String() string {
switch opinion {
case OPIN_UNKNOWN:
return "Unknown"
case OPIN_POSITIVE:
return "Positive"
case OPIN_NEGATIVE:
return "Negative"
case OPIN_GIVEUP:
return "Giveup"
default:
return "Invalid opinion"
}
}
func (opinion VoteOpinion) Err() error {
opName := opinion.String()
if opName == "" {
return errors.New("vote opinion must be one of [UNKNOWN, POSITIVE, NEGATIVE, GIVEUP]")
}
return nil
}
func (opinion VoteResult) String() string {
switch opinion {
case VOTE_RESULT_PASSED:
return "Passed"
case VOTE_RESULT_FAILED:
return "Failed"
case VOTE_RESULT_TBD:
return "To be determined"
default:
return "Invalid vote result"
}
}