-
Notifications
You must be signed in to change notification settings - Fork 105
/
status.go
99 lines (87 loc) · 2.19 KB
/
status.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
package auction
import (
"github.com/rocket-pool/rocketpool-go/auction"
"github.com/urfave/cli"
"golang.org/x/sync/errgroup"
"github.com/rocket-pool/smartnode/shared/services"
"github.com/rocket-pool/smartnode/shared/types/api"
)
func getStatus(c *cli.Context) (*api.AuctionStatusResponse, error) {
// Get services
if err := services.RequireNodeWallet(c); err != nil {
return nil, err
}
if err := services.RequireRocketStorage(c); err != nil {
return nil, err
}
w, err := services.GetWallet(c)
if err != nil {
return nil, err
}
rp, err := services.GetRocketPool(c)
if err != nil {
return nil, err
}
// Response
response := api.AuctionStatusResponse{}
// Sync
var wg errgroup.Group
// Get auction contract RPL balances
wg.Go(func() error {
totalRplBalance, err := auction.GetTotalRPLBalance(rp, nil)
if err == nil {
response.TotalRPLBalance = totalRplBalance
}
return err
})
wg.Go(func() error {
allottedRplBalance, err := auction.GetAllottedRPLBalance(rp, nil)
if err == nil {
response.AllottedRPLBalance = allottedRplBalance
}
return err
})
wg.Go(func() error {
remainingRplBalance, err := auction.GetRemainingRPLBalance(rp, nil)
if err == nil {
response.RemainingRPLBalance = remainingRplBalance
}
return err
})
// Check if lot can be created
wg.Go(func() error {
sufficientRemainingRplForLot, err := getSufficientRemainingRPLForLot(rp)
if err == nil {
response.CanCreateLot = sufficientRemainingRplForLot
}
return err
})
// Get lot counts
wg.Go(func() error {
nodeAccount, err := w.GetNodeAccount()
if err != nil {
return err
}
lotCountDetails, err := getAllLotCountDetails(rp, nodeAccount.Address)
if err == nil {
for _, details := range lotCountDetails {
if details.AddressHasBid && details.Cleared {
response.LotCounts.ClaimAvailable++
}
if !details.Cleared && details.HasRemainingRpl {
response.LotCounts.BiddingAvailable++
}
if details.Cleared && details.HasRemainingRpl && !details.RplRecovered {
response.LotCounts.RPLRecoveryAvailable++
}
}
}
return err
})
// Wait for data
if err := wg.Wait(); err != nil {
return nil, err
}
// Return response
return &response, nil
}