cosmos-sdk/types/stake.go

88 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))
Merge PR #1119: Unbonding, Redelegation * stake/fees spec updates * staking overview.md revisions, moving files * docs reorganization * staking spec state revisions * transaction stake updates * complete staking spec update * WIP adding unbonding/redelegation commands * added msg types for unbonding, redelegation * stake sub-package reorg * working stake reorg * modify lcd tests to not use hardcoded json strings * add description update * index keys * key managment for unbonding redelegation complete * update stake errors * completed handleMsgCompleteUnbonding fn * updated to use begin/complete unbonding/redelegation * fix token shares bug * develop docs into unbonding * got non-tests compiling after merge develop * working fixing tests * PrivlegedKeeper -> PrivilegedKeeper * tests compile * fix some tests * fixing tests * remove PrivilegedKeeper * get unbonding bug * only rpc sig verification failed tests now * move percent unbonding/redelegation to the CLI and out of handler logic * remove min unbonding height * add lcd txs * add pool sanity checks, fix a buncha tests * fix ante. set lcd log to debug (#1322) * redelegation tests, adding query functionality for bonds * add self-delegations at genesis ref #1165 * PR comments (mostly) addressed * cleanup, added Query LCD functionality * test cleanup/fixes * fix governance test * SlashValidatorSet -> ValidatorSet * changelog * stake lcd fix * x/auth: fix chainID in ante * fix lcd test * fix lint, update lint make command for spelling * lowercase error string * don't expose coinkeeper in staking * remove a few duplicate lines in changelog * chain_id in stake lcd tests * added transient redelegation * 'transient' => 'transitive' * Re-add nolint instruction * Fix tiny linter error
2018-06-26 19:00:12 -07:00
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
}