-
Notifications
You must be signed in to change notification settings - Fork 285
/
Copy pathballot.go
34 lines (29 loc) · 959 Bytes
/
ballot.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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/terra-project/core/x/oracle/internal/types"
)
// OrganizeBallotByDenom collects all oracle votes for the period, categorized by the votes' denom parameter
func (k Keeper) OrganizeBallotByDenom(ctx sdk.Context) (votes map[string]types.ExchangeRateBallot) {
votes = map[string]types.ExchangeRateBallot{}
handler := func(vote types.ExchangeRateVote) (stop bool) {
validator := k.StakingKeeper.Validator(ctx, vote.Voter)
// organize ballot only for the active validators
if validator != nil && validator.IsBonded() && !validator.IsJailed() {
power := validator.GetConsensusPower()
if !vote.ExchangeRate.IsPositive() {
// Make the power of abstain vote zero
power = 0
}
votes[vote.Denom] = append(votes[vote.Denom],
types.NewVoteForTally(
vote,
power,
),
)
}
return false
}
k.IterateExchangeRateVotes(ctx, handler)
return
}