-
Notifications
You must be signed in to change notification settings - Fork 105
/
voting.go
119 lines (98 loc) · 2.74 KB
/
voting.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
package node
import (
"fmt"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/urfave/cli"
"github.com/rocket-pool/smartnode/shared/services/gas"
"github.com/rocket-pool/smartnode/shared/services/rocketpool"
cliutils "github.com/rocket-pool/smartnode/shared/utils/cli"
)
func nodeSetVotingDelegate(c *cli.Context, nameOrAddress string) error {
// Get RP client
rp, err := rocketpool.NewClientFromCtx(c).WithReady()
if err != nil {
return err
}
defer rp.Close()
var address common.Address
var addressString string
if strings.Contains(nameOrAddress, ".") {
response, err := rp.ResolveEnsName(nameOrAddress)
if err != nil {
return err
}
address = response.Address
addressString = fmt.Sprintf("%s (%s)", nameOrAddress, address.Hex())
} else {
address, err = cliutils.ValidateAddress("delegate", nameOrAddress)
if err != nil {
return err
}
addressString = address.Hex()
}
// Get the gas estimation
gasEstimate, err := rp.EstimateSetSnapshotDelegateGas(address)
if err != nil {
return err
}
// Assign max fees
err = gas.AssignMaxFeeAndLimit(gasEstimate.GasInfo, rp, c.Bool("yes"))
if err != nil {
return err
}
// Prompt for confirmation
if !(c.Bool("yes") || cliutils.Confirm(fmt.Sprintf("Are you sure you want %s to represent your node in Rocket Pool governance proposals?", addressString))) {
fmt.Println("Cancelled.")
return nil
}
// Set delegate
response, err := rp.SetSnapshotDelegate(address)
if err != nil {
return err
}
fmt.Printf("Setting delegate...\n")
cliutils.PrintTransactionHash(rp, response.TxHash)
if _, err = rp.WaitForTransaction(response.TxHash); err != nil {
return err
}
// Log & return
fmt.Printf("The node's voting delegate was successfuly set to %s.\n", addressString)
return nil
}
func nodeClearVotingDelegate(c *cli.Context) error {
// Get RP client
rp, err := rocketpool.NewClientFromCtx(c).WithReady()
if err != nil {
return err
}
defer rp.Close()
// Get the gas estimation
gasEstimate, err := rp.EstimateClearSnapshotDelegateGas()
if err != nil {
return err
}
// Assign max fees
err = gas.AssignMaxFeeAndLimit(gasEstimate.GasInfo, rp, c.Bool("yes"))
if err != nil {
return err
}
// Prompt for confirmation
if !(c.Bool("yes") || cliutils.Confirm("Are you sure you remove your node's current delegate address for voting on governance proposals?")) {
fmt.Println("Cancelled.")
return nil
}
// Set delegate
response, err := rp.ClearSnapshotDelegate()
if err != nil {
return err
}
fmt.Printf("Removing delegate...\n")
cliutils.PrintTransactionHash(rp, response.TxHash)
if _, err = rp.WaitForTransaction(response.TxHash); err != nil {
return err
}
// Log & return
fmt.Println("The node's voting delegate has been removed.")
return nil
}