Skip to content

Commit

Permalink
feat: set validator consensus address
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Aug 1, 2023
1 parent c22466e commit 10cc553
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codecTyped "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
slashingTypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
Expand Down Expand Up @@ -82,3 +83,24 @@ func (c *Converter) ValidatorFromCosmosValidator(
SigningInfo: valSigningInfo,
}
}

func (c *Converter) SetValidatorConsumerConsensusAddr(validator *types.Validator, consumerKey string) error {
consAddress, err := sdkTypes.ConsAddressFromBech32(consumerKey)
if err != nil {
return err
}

validator.ConsensusAddressValcons = consAddress.String()
validator.ConsensusAddressHex = fmt.Sprintf("%x", consAddress)

return nil
}

func (c *Converter) GetConsKeyFromBech32(addr string) (string, error) {
consAddress, err := sdkTypes.ConsAddressFromBech32(addr)
if err != nil {
return "", err
}

return consAddress.String(), nil
}
3 changes: 3 additions & 0 deletions pkg/data/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ func (m *Manager) GetValidatorsAndSigningInfoForConsumerChain(height int64) (typ
}

validator := m.converter.ValidatorFromCosmosValidator(validatorRaw, &signingInfo)
if err := m.converter.SetValidatorConsumerConsensusAddr(validator, consensusAddr); err != nil {
m.logger.Warn().Err(err).Msg("Could not set validator consumer consensus address")
}

mutex.Lock()
validators[index] = validator
Expand Down

0 comments on commit 10cc553

Please sign in to comment.