-
Notifications
You must be signed in to change notification settings - Fork 0
/
proposals.go
200 lines (166 loc) · 4.79 KB
/
proposals.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
package odao
import (
"bytes"
"encoding/hex"
"fmt"
"strings"
"github.com/Seb369888/poolsea-go/dao"
"github.com/Seb369888/poolsea-go/types"
"github.com/urfave/cli"
"github.com/Seb369888/smartnode/shared/services/rocketpool"
cliutils "github.com/Seb369888/smartnode/shared/utils/cli"
)
func filterProposalState(state string, stateFilter string) bool {
// Easy out
if stateFilter == "" {
return false
}
// Check comma separated list for the state
filterStates := strings.Split(stateFilter, ",")
for _, fs := range filterStates {
if fs == state {
return false
}
}
// Not found
return true
}
func getProposals(c *cli.Context, stateFilter string) error {
// Get RP client
rp, err := rocketpool.NewClientFromCtx(c)
if err != nil {
return err
}
defer rp.Close()
// Check and assign the EC status
err = cliutils.CheckClientStatus(rp)
if err != nil {
return err
}
// Get oracle DAO proposals
allProposals, err := rp.TNDAOProposals()
if err != nil {
return err
}
// Get oracle DAO members
allMembers, err := rp.TNDAOMembers()
if err != nil {
return err
}
// Get proposals by state
stateProposals := map[string][]dao.ProposalDetails{}
for _, proposal := range allProposals.Proposals {
stateName := proposal.State.String()
if _, ok := stateProposals[stateName]; !ok {
stateProposals[stateName] = []dao.ProposalDetails{}
}
stateProposals[stateName] = append(stateProposals[stateName], proposal)
}
// Proposal states print order
proposalStates := []string{"Pending", "Active", "Succeeded", "Executed", "Cancelled", "Defeated", "Expired"}
proposalStateInputs := []string{"pending", "active", "succeeded", "executed", "cancelled", "defeated", "expired"}
// Print & return
count := 0
for i, stateName := range proposalStates {
proposals, ok := stateProposals[stateName]
if !ok {
continue
}
// Check filter
if filterProposalState(proposalStateInputs[i], stateFilter) {
continue
}
// Proposal state count
fmt.Printf("%d %s proposal(s):\n", len(proposals), stateName)
fmt.Println("")
// Proposals
for _, proposal := range proposals {
for _, member := range allMembers.Members {
if bytes.Equal(proposal.ProposerAddress.Bytes(), member.Address.Bytes()) {
fmt.Printf("%d: %s - Proposed by: %s (%s)\n", proposal.ID, proposal.Message, member.ID, proposal.ProposerAddress)
}
}
}
count += len(proposals)
fmt.Println()
}
if count == 0 {
fmt.Println("There are no matching oracle DAO proposals.")
}
return nil
}
func getProposal(c *cli.Context, id uint64) error {
// Get RP client
rp, err := rocketpool.NewClientFromCtx(c)
if err != nil {
return err
}
defer rp.Close()
// Check and assign the EC status
err = cliutils.CheckClientStatus(rp)
if err != nil {
return err
}
// Get oracle DAO proposals
allProposals, err := rp.TNDAOProposals()
if err != nil {
return err
}
// Get oracle DAO members
allMembers, err := rp.TNDAOMembers()
if err != nil {
return err
}
// Find the proposal
var proposal *dao.ProposalDetails
for i, p := range allProposals.Proposals {
if p.ID == id {
proposal = &allProposals.Proposals[i]
break
}
}
// Find the proposer
var memberID string
for _, member := range allMembers.Members {
if bytes.Equal(proposal.ProposerAddress.Bytes(), member.Address.Bytes()) {
memberID = member.ID
}
}
if proposal == nil {
fmt.Printf("Proposal with ID %d does not exist.\n", id)
return nil
}
// Main details
fmt.Printf("Proposal ID: %d\n", proposal.ID)
fmt.Printf("Message: %s\n", proposal.Message)
fmt.Printf("Payload: %s\n", proposal.PayloadStr)
fmt.Printf("Payload (bytes): %s\n", hex.EncodeToString(proposal.Payload))
fmt.Printf("Proposed by: %s (%s)\n", memberID, proposal.ProposerAddress.Hex())
fmt.Printf("Created at: %s\n", cliutils.GetDateTimeString(proposal.CreatedTime))
// Start block - pending proposals
if proposal.State == types.Pending {
fmt.Printf("Starts at: %s\n", cliutils.GetDateTimeString(proposal.StartTime))
}
// End block - active proposals
if proposal.State == types.Active {
fmt.Printf("Ends at: %s\n", cliutils.GetDateTimeString(proposal.EndTime))
}
// Expiry block - succeeded proposals
if proposal.State == types.Succeeded {
fmt.Printf("Expires at: %s\n", cliutils.GetDateTimeString(proposal.ExpiryTime))
}
// Vote details
fmt.Printf("Votes required: %.2f\n", proposal.VotesRequired)
fmt.Printf("Votes for: %.2f\n", proposal.VotesFor)
fmt.Printf("Votes against: %.2f\n", proposal.VotesAgainst)
if proposal.MemberVoted {
if proposal.MemberSupported {
fmt.Printf("Node has voted: for\n")
} else {
fmt.Printf("Node has voted: against\n")
}
} else {
fmt.Printf("Node has voted: no\n")
}
return nil
}