implement TotalPower
This commit is contained in:
parent
9d7e893226
commit
60869ff427
|
@ -16,7 +16,6 @@ func init() {
|
||||||
type Validator = abci.Validator
|
type Validator = abci.Validator
|
||||||
|
|
||||||
type ValidatorSetKeeper interface {
|
type ValidatorSetKeeper interface {
|
||||||
Hash(Context) []byte
|
|
||||||
GetValidators(Context) []*Validator
|
GetValidators(Context) []*Validator
|
||||||
Size(Context) int
|
Size(Context) int
|
||||||
IsValidator(Context, Address) bool
|
IsValidator(Context, Address) bool
|
||||||
|
|
|
@ -498,10 +498,6 @@ func (k Keeper) setPool(ctx sdk.Context, p Pool) {
|
||||||
|
|
||||||
// Implements sdk.ValidatorSetKeeper
|
// Implements sdk.ValidatorSetKeeper
|
||||||
|
|
||||||
func (k Keeper) Hash() []byte {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (k Keeper) Size(ctx sdk.Context) int {
|
func (k Keeper) Size(ctx sdk.Context) int {
|
||||||
return len(k.GetValidators(ctx))
|
return len(k.GetValidators(ctx))
|
||||||
}
|
}
|
||||||
|
@ -536,6 +532,14 @@ func (k Keeper) GetByIndex(ctx sdk.Context, index int) *sdk.Validator {
|
||||||
return &val
|
return &val
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) TotalPower() sdk.Rat {
|
func (k Keeper) TotalPower(ctx sdk.Context) sdk.Rat {
|
||||||
return sdk.ZeroRat
|
valset := k.GetValidators(ctx)
|
||||||
|
|
||||||
|
res := sdk.ZeroRat
|
||||||
|
|
||||||
|
for _, v := range valset {
|
||||||
|
res = res.Add(v.Power)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue