implement TotalPower

This commit is contained in:
mossid 2018-04-17 23:38:12 +02:00 committed by rigelrozanski
parent 9d7e893226
commit 60869ff427
2 changed files with 10 additions and 7 deletions

View File

@ -16,7 +16,6 @@ func init() {
type Validator = abci.Validator
type ValidatorSetKeeper interface {
Hash(Context) []byte
GetValidators(Context) []*Validator
Size(Context) int
IsValidator(Context, Address) bool

View File

@ -498,10 +498,6 @@ func (k Keeper) setPool(ctx sdk.Context, p Pool) {
// Implements sdk.ValidatorSetKeeper
func (k Keeper) Hash() []byte {
return nil
}
func (k Keeper) Size(ctx sdk.Context) int {
return len(k.GetValidators(ctx))
}
@ -536,6 +532,14 @@ func (k Keeper) GetByIndex(ctx sdk.Context, index int) *sdk.Validator {
return &val
}
func (k Keeper) TotalPower() sdk.Rat {
return sdk.ZeroRat
func (k Keeper) TotalPower(ctx sdk.Context) sdk.Rat {
valset := k.GetValidators(ctx)
res := sdk.ZeroRat
for _, v := range valset {
res = res.Add(v.Power)
}
return res
}