cosmos-sdk/types/stake.go

87 lines
2.8 KiB
Go
Raw Normal View History

2018-05-09 18:39:14 -07:00
package types
import (
abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-crypto"
2018-06-04 16:42:01 -07:00
tmtypes "github.com/tendermint/tendermint/types"
2018-05-09 18:39:14 -07:00
)
// status of a validator
type BondStatus byte
2018-05-09 18:39:14 -07:00
// nolint
const (
Unbonded BondStatus = 0x00
Unbonding BondStatus = 0x01
Bonded BondStatus = 0x02
2018-05-09 18:39:14 -07:00
)
//BondStatusToString for pretty prints of Bond Status
func BondStatusToString(b BondStatus) string {
switch b {
case 0x00:
2018-05-28 16:27:34 -07:00
return "Unbonded"
case 0x01:
return "Unbonding"
case 0x02:
return "Bonded"
default:
return ""
}
}
2018-05-09 18:39:14 -07:00
// validator for a delegated proof of stake system
type Validator interface {
GetMoniker() string // moniker of the validator
GetStatus() BondStatus // status of the validator
GetOwner() Address // owner address to receive/return validators coins
GetPubKey() crypto.PubKey // validation pubkey
GetPower() Rat // validation power
2018-06-21 17:19:14 -07:00
GetDelegatorShares() Rat // Total out standing delegator shares
GetBondHeight() int64 // height in which the validator became active
2018-05-09 18:39:14 -07:00
}
// validator which fulfills abci validator interface for use in Tendermint
func ABCIValidator(v Validator) abci.Validator {
return abci.Validator{
2018-06-04 16:42:01 -07:00
PubKey: tmtypes.TM2PB.PubKey(v.GetPubKey()),
2018-05-09 18:39:14 -07:00
Power: v.GetPower().Evaluate(),
}
}
// properties for the set of all validators
type ValidatorSet interface {
// iterate through validator by owner-address, execute func for each validator
IterateValidators(Context,
func(index int64, validator Validator) (stop bool))
// iterate through bonded validator by pubkey-address, execute func for each validator
IterateValidatorsBonded(Context,
func(index int64, validator Validator) (stop bool))
Validator(Context, Address) Validator // get a particular validator by owner address
TotalPower(Context) Rat // total power of the validator set
Slash(Context, crypto.PubKey, int64, Rat) // slash the validator and delegators of the validator, specifying offence height & slash fraction
Revoke(Context, crypto.PubKey) // revoke a validator
Unrevoke(Context, crypto.PubKey) // unrevoke a validator
2018-05-09 18:39:14 -07:00
}
//_______________________________________________________________________________
// delegation bond for a delegated proof of stake system
type Delegation interface {
GetDelegator() Address // delegator address for the bond
GetValidator() Address // validator owner address for the bond
GetBondShares() Rat // amount of validator's shares
}
// properties for the set of all delegations for a particular
type DelegationSet interface {
2018-06-21 17:19:14 -07:00
GetValidatorSet() ValidatorSet // validator set for which delegation set is based upon
2018-05-09 18:39:14 -07:00
// iterate through all delegations from one delegator by validator-address,
// execute func for each validator
2018-06-21 17:19:14 -07:00
IterateDelegations(ctx Context, delegator Address,
fn func(index int64, delegation Delegation) (stop bool))
2018-05-09 18:39:14 -07:00
}