-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathwithdraw-rpl.go
More file actions
77 lines (64 loc) · 1.89 KB
/
withdraw-rpl.go
File metadata and controls
77 lines (64 loc) · 1.89 KB
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
package faucet
import (
"fmt"
"github.com/rocket-pool/rocketpool-go/utils/eth"
"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"
"github.com/rocket-pool/smartnode/shared/utils/math"
)
func withdrawRpl(c *cli.Context) 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
}
// Check RPL can be withdrawn
canWithdraw, err := rp.CanFaucetWithdrawRpl()
if err != nil {
return err
}
if !canWithdraw.CanWithdraw {
fmt.Println("Cannot withdraw legacy RPL from the faucet:")
if canWithdraw.InsufficientFaucetBalance {
fmt.Println("The faucet does not have any legacy RPL for withdrawal")
}
if canWithdraw.InsufficientAllowance {
fmt.Println("You don't have any allowance remaining for the withdrawal period")
}
if canWithdraw.InsufficientNodeBalance {
fmt.Println("You don't have enough GoETH to pay the faucet withdrawal fee")
}
return nil
}
// Assign max fees
err = gas.AssignMaxFeeAndLimit(canWithdraw.GasInfo, rp, c.Bool("yes"))
if err != nil {
return err
}
// Prompt for confirmation
if !(c.Bool("yes") || cliutils.Confirm("Are you sure you want to withdraw legacy RPL from the faucet?")) {
fmt.Println("Cancelled.")
return nil
}
// Withdraw RPL
response, err := rp.FaucetWithdrawRpl()
if err != nil {
return err
}
fmt.Printf("Withdrawing legacy RPL...\n")
cliutils.PrintTransactionHash(rp, response.TxHash)
if _, err = rp.WaitForTransaction(response.TxHash); err != nil {
return err
}
// Log & return
fmt.Printf("Successfully withdrew %.6f legacy RPL from the faucet.\n", math.RoundDown(eth.WeiToEth(&response.Amount), 6))
return nil
}