2018-05-09 18:39:14 -07:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2018-06-28 17:54:47 -07:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
"github.com/tendermint/tendermint/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
|
2018-05-11 14:58:28 -07:00
|
|
|
type BondStatus byte
|
2018-05-09 18:39:14 -07:00
|
|
|
|
|
|
|
// nolint
|
|
|
|
const (
|
2018-05-15 20:32:18 -07:00
|
|
|
Unbonded BondStatus = 0x00
|
2018-05-11 14:58:28 -07:00
|
|
|
Unbonding BondStatus = 0x01
|
2018-05-15 20:32:18 -07:00
|
|
|
Bonded BondStatus = 0x02
|
2018-05-09 18:39:14 -07:00
|
|
|
)
|
|
|
|
|
2018-05-26 14:21:29 -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"
|
2018-05-26 14:21:29 -07:00
|
|
|
case 0x01:
|
|
|
|
return "Unbonding"
|
|
|
|
case 0x02:
|
|
|
|
return "Bonded"
|
|
|
|
default:
|
2018-07-13 13:46:14 -07:00
|
|
|
panic("improper use of BondStatusToString")
|
2018-05-26 14:21:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-13 13:46:14 -07:00
|
|
|
// nolint
|
|
|
|
func (b BondStatus) Equal(b2 BondStatus) bool {
|
|
|
|
return byte(b) == byte(b2)
|
|
|
|
}
|
|
|
|
|
2018-05-09 18:39:14 -07:00
|
|
|
// validator for a delegated proof of stake system
|
|
|
|
type Validator interface {
|
2018-06-29 20:34:55 -07:00
|
|
|
GetRevoked() bool // whether the validator is revoked
|
2018-06-06 09:38:13 -07:00
|
|
|
GetMoniker() string // moniker of the validator
|
2018-05-24 15:12:40 -07:00
|
|
|
GetStatus() BondStatus // status of the validator
|
2018-07-06 00:06:53 -07:00
|
|
|
GetOwner() AccAddress // owner AccAddress to receive/return validators coins
|
2018-05-24 15:12:40 -07:00
|
|
|
GetPubKey() crypto.PubKey // validation pubkey
|
|
|
|
GetPower() Rat // validation power
|
2018-07-18 00:42:18 -07:00
|
|
|
GetTokens() Rat // validation tokens
|
2018-06-21 17:19:14 -07:00
|
|
|
GetDelegatorShares() Rat // Total out standing delegator shares
|
2018-05-24 15:12:40 -07:00
|
|
|
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-07-02 08:57:33 -07:00
|
|
|
Power: v.GetPower().RoundInt64(),
|
2018-05-09 18:39:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// properties for the set of all validators
|
|
|
|
type ValidatorSet interface {
|
2018-07-06 00:06:53 -07:00
|
|
|
// iterate through validator by owner-AccAddress, execute func for each validator
|
2018-05-17 11:09:35 -07:00
|
|
|
IterateValidators(Context,
|
|
|
|
func(index int64, validator Validator) (stop bool))
|
|
|
|
|
2018-07-06 00:06:53 -07:00
|
|
|
// iterate through bonded validator by pubkey-AccAddress, execute func for each validator
|
2018-05-17 11:09:35 -07:00
|
|
|
IterateValidatorsBonded(Context,
|
|
|
|
func(index int64, validator Validator) (stop bool))
|
|
|
|
|
2018-07-24 19:12:48 -07:00
|
|
|
Validator(Context, AccAddress) Validator // get a particular validator by owner AccAddress
|
|
|
|
ValidatorByPubKey(Context, crypto.PubKey) Validator // get a particular validator by signing PubKey
|
|
|
|
TotalPower(Context) Rat // total power of the validator set
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-06-29 20:34:55 -07:00
|
|
|
// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
|
|
|
|
Slash(Context, crypto.PubKey, int64, int64, Rat)
|
|
|
|
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 {
|
2018-07-06 00:06:53 -07:00
|
|
|
GetDelegator() AccAddress // delegator AccAddress for the bond
|
|
|
|
GetValidator() AccAddress // validator owner AccAddress for the bond
|
|
|
|
GetBondShares() Rat // amount of validator's shares
|
2018-05-09 18:39:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2018-07-06 00:06:53 -07:00
|
|
|
// iterate through all delegations from one delegator by validator-AccAddress,
|
2018-05-17 11:09:35 -07:00
|
|
|
// execute func for each validator
|
2018-07-06 00:06:53 -07:00
|
|
|
IterateDelegations(ctx Context, delegator AccAddress,
|
2018-05-17 11:09:35 -07:00
|
|
|
fn func(index int64, delegation Delegation) (stop bool))
|
2018-05-09 18:39:14 -07:00
|
|
|
}
|