forked from prysmaticlabs/prysmbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
current.go
58 lines (56 loc) · 2.53 KB
/
current.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
package main
import (
"context"
"fmt"
"github.com/gogo/protobuf/types"
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
)
func getHeadCommandResult(command string) string {
switch command {
case headSlot.command, headSlot.shorthand:
chainHead, err := beaconClient.GetChainHead(context.Background(), &types.Empty{})
if err != nil {
log.WithError(err).Error(err, "failed to get chain head")
return "Could not get current slot."
}
return fmt.Sprintf(headSlot.responseText, chainHead.HeadSlot)
case headEpoch.command, headEpoch.shorthand:
chainHead, err := beaconClient.GetChainHead(context.Background(), &types.Empty{})
if err != nil {
log.WithError(err).Error(err, "failed to get chain head")
return "Could not get current epoch."
}
return fmt.Sprintf(headEpoch.responseText, chainHead.HeadEpoch)
case headJustifiedEpoch.command, headJustifiedEpoch.shorthand:
chainHead, err := beaconClient.GetChainHead(context.Background(), &types.Empty{})
if err != nil {
log.WithError(err).Error(err, "failed to get chain head")
return "Could not get current justified epoch."
}
return fmt.Sprintf(headJustifiedEpoch.responseText, chainHead.JustifiedEpoch)
case headFinalizedEpoch.command, headFinalizedEpoch.shorthand:
chainHead, err := beaconClient.GetChainHead(context.Background(), &types.Empty{})
if err != nil {
log.WithError(err).Error(err, "failed to get chain head")
return "Could not get current head finalized epoch."
}
return fmt.Sprintf(headFinalizedEpoch.responseText, chainHead.FinalizedEpoch)
case currentParticipation.command, currentParticipation.shorthand, currentTotalBalance.command, currentTotalBalance.shorthand:
req := ð.GetValidatorParticipationRequest{}
participation, err := beaconClient.GetValidatorParticipation(context.Background(), req)
if err != nil {
log.WithError(err).Error(err, "failed to get chain head")
return "Could not get current participation/total balance."
}
if command == currentParticipation.command || command == currentParticipation.shorthand{
return fmt.Sprintf(currentParticipation.responseText, participation.Epoch, participation.Participation.GlobalParticipationRate*100)
} else if command == currentTotalBalance.command || command == currentTotalBalance.shorthand{
inEther := float64(participation.Participation.EligibleEther) / float64(params.BeaconConfig().GweiPerEth)
return fmt.Sprintf(currentTotalBalance.responseText, participation.Epoch, inEther)
}
default:
return ""
}
return ""
}