-
Notifications
You must be signed in to change notification settings - Fork 112
/
invite-sc.go
94 lines (81 loc) · 2.5 KB
/
invite-sc.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
package pdao
import (
"fmt"
"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"
"github.com/urfave/cli"
)
func proposeSecurityCouncilInvite(c *cli.Context) error {
// Get RP client
rp, err := rocketpool.NewClientFromCtx(c).WithReady()
if err != nil {
return err
}
defer rp.Close()
// Check for Houston
houston, err := rp.IsHoustonDeployed()
if err != nil {
return fmt.Errorf("error checking if Houston has been deployed: %w", err)
}
if !houston.IsHoustonDeployed {
fmt.Println("This command cannot be used until Houston has been deployed.")
return nil
}
// Get the ID
id := c.String("id")
if id == "" {
id = cliutils.Prompt("Please enter an ID for the member you'd like to invite: (no spaces)", "^\\S+$", "Invalid ID")
}
id, err = cliutils.ValidateDAOMemberID("id", id)
if err != nil {
return err
}
// Get the address
addressString := c.String("address")
if addressString == "" {
addressString = cliutils.Prompt("Please enter the member's address:", "^0x[0-9a-fA-F]{40}$", "Invalid member address")
}
address, err := cliutils.ValidateAddress("address", addressString)
if err != nil {
return err
}
// Check submissions
canResponse, err := rp.PDAOCanProposeInviteToSecurityCouncil(id, address)
if err != nil {
return err
}
if !canResponse.CanPropose {
fmt.Println("Cannot propose inviting member:")
if canResponse.MemberAlreadyExists {
fmt.Printf("The node %s is already a member of the security council.\n", address.Hex())
}
if canResponse.IsRplLockingDisallowed {
fmt.Println("Please enable RPL locking using the command 'rocketpool node allow-rpl-locking' to raise proposals.")
}
return nil
}
// Assign max fee
err = gas.AssignMaxFeeAndLimit(canResponse.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 to propose inviting %s (%s) to the security council?", id, address.Hex()))) {
fmt.Println("Cancelled.")
return nil
}
// Submit
response, err := rp.PDAOProposeInviteToSecurityCouncil(id, address, canResponse.BlockNumber)
if err != nil {
return err
}
fmt.Printf("Proposing invitation to security council...\n")
cliutils.PrintTransactionHash(rp, response.TxHash)
if _, err = rp.WaitForTransaction(response.TxHash); err != nil {
return err
}
// Log & return
fmt.Println("Proposal successfully created.")
return nil
}