Skip to content

Commit

Permalink
refactor: move getValidator into getValidatorsets
Browse files Browse the repository at this point in the history
  • Loading branch information
jim380 committed Sep 17, 2023
1 parent 481f917 commit 47f06b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
15 changes: 4 additions & 11 deletions rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,15 @@ func GetData(cfg *config.Config, blockHeight int64, blockData Blocks, denom stri
rd.getSlashingParams(*cfg)
rd.getInflation(*cfg, denom)
rd.getGovInfo(*cfg)
rd.getValidatorsets(*cfg, blockHeight)
rd.getValidator(*cfg)
// TO-DO if consumer chain, use cosmoshub's ConsPubKey
valMap, found := rd.Validatorsets[rd.Validator.ConsPubKey.Key]
if len(rd.Validatorsets) != 0 && !found {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", "Validator not found in the active set"))
}

valInfo := rd.getValidatorsets(*cfg, blockHeight)
rd.getBalances(*cfg)
rd.getRewardsCommission(*cfg)
rd.getSigningInfo(*cfg, valMap[0])
rd.getSigningInfo(*cfg, valInfo[0])

consHexAddr := utils.Bech32AddrToHexAddr(valMap[0])
consHexAddr := utils.Bech32AddrToHexAddr(valInfo[0])
rd.getCommit(blockData, consHexAddr)
zap.L().Info("", zap.Bool("Success", true), zap.String("Moniker", rd.Validator.Description.Moniker))
zap.L().Info("", zap.Bool("Success", true), zap.String("VP", valMap[1]))
zap.L().Info("", zap.Bool("Success", true), zap.String("VP", valInfo[1]))
zap.L().Info("", zap.Bool("Success", true), zap.String("Precommit", fmt.Sprintf("%f", rd.Commit.ValidatorPrecommitStatus)))
zap.L().Info("\t", zap.Bool("Success", true), zap.String("Balances", fmt.Sprint(rd.Balances)))
zap.L().Info("\t", zap.Bool("Success", true), zap.String("Rewards", fmt.Sprint(rd.Rewards)))
Expand Down
18 changes: 17 additions & 1 deletion rest/validatorsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type consPubKeyValSet struct {
Key string `json:"key"`
}

func (rd *RESTData) getValidatorsets(cfg config.Config, currentBlockHeight int64) {
func (rd *RESTData) getValidatorsets(cfg config.Config, currentBlockHeight int64) []string {
var vSetsResultFinal map[string][]string

if cfg.IsLegacySDKVersion() {
Expand Down Expand Up @@ -118,6 +118,22 @@ func (rd *RESTData) getValidatorsets(cfg config.Config, currentBlockHeight int64
zap.L().Debug("", zap.Bool("Success", true), zap.String(key, strings.Join(value, ", ")))
}

if len(rd.Validatorsets) == 0 {
zap.L().Warn("", zap.Bool("Success", false), zap.String("err", "Validator set is empty"))
}

rd.getValidator(cfg)
valInfo := rd.locateValidatorInActiveSet()
return valInfo
}

// TO-DO if consumer chain, use cosmoshub's ConsPubKey
func (rd *RESTData) locateValidatorInActiveSet() []string {
valInfo, found := rd.Validatorsets[rd.Validator.ConsPubKey.Key]
if !found {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", "Validator not found in the active set"))
}
return valInfo
}

func Sort(mapValue map[string][]string) map[string][]string {
Expand Down

0 comments on commit 47f06b8

Please sign in to comment.