rebase on develop

This commit is contained in:
mossid 2018-04-25 16:12:59 +02:00 committed by rigelrozanski
parent 2198908d02
commit 9d7e893226
3 changed files with 78 additions and 6 deletions

26
types/validator_set.go Normal file
View File

@ -0,0 +1,26 @@
package types
import (
abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-crypto"
"github.com/cosmos/cosmos-sdk/wire"
)
var cdc = wire.NewCodec()
func init() {
crypto.RegisterAmino(cdc)
}
type Validator = abci.Validator
type ValidatorSetKeeper interface {
Hash(Context) []byte
GetValidators(Context) []*Validator
Size(Context) int
IsValidator(Context, Address) bool
GetByAddress(Context, Address) (int, *Validator)
GetByIndex(Context, int) *Validator
TotalPower(Context) Rat
}

View File

@ -493,3 +493,49 @@ func (k Keeper) setPool(ctx sdk.Context, p Pool) {
store.Set(PoolKey, b) store.Set(PoolKey, b)
k.pool = Pool{} //clear the cache k.pool = Pool{} //clear the cache
} }
//__________________________________________________________________________
// Implements sdk.ValidatorSetKeeper
func (k Keeper) Hash() []byte {
return nil
}
func (k Keeper) Size(ctx sdk.Context) int {
return len(k.GetValidators(ctx))
}
func (k Keeper) IsValidator(ctx sdk.Context, addr sdk.Address) bool {
for _, v := range k.GetValidators(ctx) {
if bytes.Equal(v.Address, addr) {
return true
}
}
return false
}
func (k Keeper) GetByAddress(ctx sdk.Context, addr sdk.Address) (int, *sdk.Validator) {
for i, v := range k.GetValidators(ctx) {
if bytes.Equal(v.Address, addr) {
val := v.abciValidator(k.cdc)
return i, &val
}
}
return -1, nil
}
func (k Keeper) GetByIndex(ctx sdk.Context, index int) *sdk.Validator {
valset := k.GetValidators(ctx)
if index < 0 || index >= len(valset) {
return nil
}
val := valset[index].abciValidator(k.cdc)
return &val
}
func (k Keeper) TotalPower() sdk.Rat {
return sdk.ZeroRat
}

View File

@ -2,9 +2,9 @@ package stake
import ( import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
abci "github.com/tendermint/abci/types"
crypto "github.com/tendermint/go-crypto" crypto "github.com/tendermint/go-crypto"
"github.com/cosmos/cosmos-sdk/wire"
) )
// GenesisState - all staking state that must be provided at genesis // GenesisState - all staking state that must be provided at genesis
@ -159,8 +159,8 @@ type Validator struct {
} }
// abci validator from stake validator type // abci validator from stake validator type
func (v Validator) abciValidator(cdc *wire.Codec) abci.Validator { func (v Validator) abciValidator(cdc *wire.Codec) sdk.Validator {
return abci.Validator{ return sdk.Validator{
PubKey: v.PubKey.Bytes(), PubKey: v.PubKey.Bytes(),
Power: v.Power.Evaluate(), Power: v.Power.Evaluate(),
} }
@ -168,8 +168,8 @@ func (v Validator) abciValidator(cdc *wire.Codec) abci.Validator {
// abci validator from stake validator type // abci validator from stake validator type
// with zero power used for validator updates // with zero power used for validator updates
func (v Validator) abciValidatorZero(cdc *wire.Codec) abci.Validator { func (v Validator) abciValidatorZero(cdc *wire.Codec) sdk.Validator {
return abci.Validator{ return sdk.Validator{
PubKey: v.PubKey.Bytes(), PubKey: v.PubKey.Bytes(),
Power: 0, Power: 0,
} }