Skip to content

Commit

Permalink
quick add of gov
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Jul 24, 2023
1 parent d289df0 commit 158ce7c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
7 changes: 6 additions & 1 deletion x/distribution/keeper/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,18 @@ func (k Keeper) AllocateTokensToValidator(ctx context.Context, val stakingtypes.
commission := tokens.MulDec(val.GetCommission())
shared := tokens.Sub(commission)

valStr, err := k.stakingKeeper.ValidatorAddressCodec().BytesToString(val.GetOperator())
if err != nil {
return err
}

// update current commission
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeCommission,
sdk.NewAttribute(sdk.AttributeKeyAmount, commission.String()),
sdk.NewAttribute(types.AttributeKeyValidator, val.GetOperator().String()),
sdk.NewAttribute(types.AttributeKeyValidator, valStr),
),
)
currentCommission, err := k.ValidatorsAccumulatedCommission.Get(ctx, val.GetOperator())
Expand Down
11 changes: 9 additions & 2 deletions x/gov/keeper/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ func (keeper Keeper) Tally(ctx context.Context, proposal v1.Proposal) (passes, b

// fetch all the bonded validators, insert them into currValidators
err = keeper.sk.IterateBondedValidatorsByPower(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) {
currValidators[validator.GetOperator().String()] = v1.NewValidatorGovInfo(
valStr, err := keeper.sk.ValidatorAddressCodec().BytesToString(validator.GetOperator())
if err != nil {
return false
}
currValidators[valStr] = v1.NewValidatorGovInfo(
validator.GetOperator(),
validator.GetBondedTokens(),
validator.GetDelegatorShares(),
Expand All @@ -50,7 +54,10 @@ func (keeper Keeper) Tally(ctx context.Context, proposal v1.Proposal) (passes, b
return false, err
}

valAddrStr := sdk.ValAddress(voter).String()
valAddrStr, err := keeper.sk.ValidatorAddressCodec().BytesToString(voter)
if err != nil {
return false, err
}
if val, ok := currValidators[valAddrStr]; ok {
val.Vote = vote.Options
currValidators[valAddrStr] = val
Expand Down
14 changes: 14 additions & 0 deletions x/gov/testutil/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x/gov/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ParamSubspace interface {

// StakingKeeper expected staking keeper (Validator and Delegator sets) (noalias)
type StakingKeeper interface {
ValidatorAddressCodec() addresscodec.Codec
// iterate through bonded validators by operator address, execute func for each validator
IterateBondedValidatorsByPower(
context.Context, func(index int64, validator stakingtypes.ValidatorI) (stop bool),
Expand Down

0 comments on commit 158ce7c

Please sign in to comment.