mirror of
https://github.com/wealdtech/ethdo.git
synced 2026-01-10 06:28:07 -05:00
Add epoch parameter to validator yield.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright © 2022 Weald Technology Trading.
|
||||
// Copyright © 2022, 2023 Weald Technology Trading.
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@@ -36,6 +36,7 @@ type command struct {
|
||||
|
||||
// Input.
|
||||
validators string
|
||||
epoch string
|
||||
|
||||
// Data access.
|
||||
eth2Client eth2client.Service
|
||||
@@ -63,6 +64,7 @@ func newCommand(_ context.Context) (*command, error) {
|
||||
verbose: viper.GetBool("verbose"),
|
||||
debug: viper.GetBool("debug"),
|
||||
json: viper.GetBool("json"),
|
||||
epoch: viper.GetString("epoch"),
|
||||
results: &output{},
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright © 2022 Weald Technology Trading.
|
||||
// Copyright © 2022, 2023 Weald Technology Trading.
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@@ -138,17 +138,21 @@ func (c *command) setup(ctx context.Context) error {
|
||||
return errors.New("connection does not provide validator information")
|
||||
}
|
||||
|
||||
validators, err := validatorsProvider.Validators(ctx, "head", nil)
|
||||
epoch, err := util.ParseEpoch(ctx, chainTime, c.epoch)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to obtain validators")
|
||||
return errors.Wrap(err, "failed to parse epoch")
|
||||
}
|
||||
|
||||
validators, err := validatorsProvider.Validators(ctx, fmt.Sprintf("%d", chainTime.FirstSlotOfEpoch(epoch)), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
currentEpoch := chainTime.CurrentEpoch()
|
||||
activeValidators := decimal.Zero
|
||||
activeValidatorBalance := decimal.Zero
|
||||
for _, validator := range validators {
|
||||
if validator.Validator.ActivationEpoch <= currentEpoch &&
|
||||
validator.Validator.ExitEpoch > currentEpoch {
|
||||
if validator.Validator.ActivationEpoch <= epoch &&
|
||||
validator.Validator.ExitEpoch > epoch {
|
||||
activeValidators = activeValidators.Add(one)
|
||||
activeValidatorBalance = activeValidatorBalance.Add(decimal.NewFromInt(int64(validator.Validator.EffectiveBalance)))
|
||||
}
|
||||
|
||||
@@ -48,10 +48,14 @@ func init() {
|
||||
validatorCmd.AddCommand(validatorYieldCmd)
|
||||
validatorFlags(validatorYieldCmd)
|
||||
validatorYieldCmd.Flags().String("validators", "", "Number of active validators (default fetches from chain)")
|
||||
validatorYieldCmd.Flags().String("epoch", "", "Epoch at which to calculate yield")
|
||||
}
|
||||
|
||||
func validatorYieldBindings(cmd *cobra.Command) {
|
||||
if err := viper.BindPFlag("validators", cmd.Flags().Lookup("validators")); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := viper.BindPFlag("epoch", cmd.Flags().Lookup("epoch")); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user