-
Notifications
You must be signed in to change notification settings - Fork 0
/
validators.go
52 lines (41 loc) · 1.42 KB
/
validators.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
package staking
import (
"fmt"
modulestypes "github.com/rarimo/bdjuno/modules/types"
parsecmdtypes "github.com/forbole/juno/v4/cmd/parse/types"
"github.com/forbole/juno/v4/types/config"
"github.com/spf13/cobra"
"github.com/rarimo/bdjuno/database"
"github.com/rarimo/bdjuno/modules/staking"
)
// validatorsCmd returns a Cobra command that allows to fix the validator infos for all validators.
func validatorsCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
return &cobra.Command{
Use: "validators",
Short: "Fix the information about validators taking them from the latest known height",
RunE: func(cmd *cobra.Command, args []string) error {
parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig)
if err != nil {
return err
}
sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig)
if err != nil {
return err
}
// Get the database
db := database.Cast(parseCtx.Database)
// Build the staking module
stakingModule := staking.NewModule(sources.StakingSource, parseCtx.EncodingConfig.Codec, db)
// Get latest height
height, err := parseCtx.Node.LatestHeight()
if err != nil {
return fmt.Errorf("error while getting latest block height: %s", err)
}
err = stakingModule.RefreshAllValidatorInfos(height)
if err != nil {
return fmt.Errorf("error while refreshing all validators infos: %s", err)
}
return nil
},
}
}