types

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2019 License: Apache-2.0 Imports: 12 Imported by: 4

Documentation

Index

Constants

View Source
const (
	DefaultCodeSpace btypes.CodespaceType = "stake"

	CodeInvalidInput                     btypes.CodeType = 501 // 输入有误
	CodeOwnerNotExists                   btypes.CodeType = 502 // Owner账户不存在
	CodeOwnerNoEnoughToken               btypes.CodeType = 503 // Owner账户Tokens不足
	CodeValidatorExists                  btypes.CodeType = 504 // Validator已存在
	CodeOwnerHasValidator                btypes.CodeType = 505 // Owner已绑定有Validator
	CodeValidatorNotExists               btypes.CodeType = 506 // Validator不存在
	CodeValidatorIsActive                btypes.CodeType = 507 // Validator处于激活状态
	CodeValidatorIsInactive              btypes.CodeType = 508 // Validator处于非激活状态
	CodeValidatorInactiveIncome          btypes.CodeType = 509 // Validator处于非激活状态时收益非法
	CodeErrCommissionNegative            btypes.CodeType = 510 // Negative commission
	CodeErrCommissionHuge                btypes.CodeType = 511 // Validator处于非激活状态时收益非法
	CodeErrCommissionGTMaxRate           btypes.CodeType = 512 // Validator处于非激活状态时收益非法
	CodeErrCommissionChangeRateNegative  btypes.CodeType = 513 // Validator处于非激活状态时收益非法
	CodeErrCommissionChangeRateGTMaxRate btypes.CodeType = 514 // Validator处于非激活状态时收益非法
	CodeErrCommissionUpdateTime          btypes.CodeType = 515 // Validator处于非激活状态时收益非法
	CodeErrCommissionGTMaxChangeRate     btypes.CodeType = 516 // Validator处于非激活状态时收益非法
)

stake errors reserve 500 ~ 599.

View Source
const (
	AddrLen = 20

	MapperName = "validator"

	//------query-------
	Stake         = "stake"
	Delegation    = "delegation"
	Delegations   = "delegations"
	Owner         = "owner"
	Delegator     = "delegator"
	Unbondings    = "Unbondings"
	Redelegations = "Redelegations"
)
View Source
const (
	//Active 可获得挖矿奖励状态
	Active int8 = iota

	//Inactive
	Inactive

	//Inactive Code
	Revoke        InactiveCode = iota // 2
	MissVoteBlock                     // 3
	MaxValidator                      // 4
	DoubleSign                        // 5
)

Variables

View Source
var (
	EventTypeCreateValidator   = "create-validator"
	EventTypeModifyValidator   = "modify-validator"
	EventTypeRevokeValidator   = "revoke-validator"
	EventTypeActiveValidator   = "active-validator"
	EventTypeInactiveValidator = "inactive-validator"
	EventTypeCloseValidator    = "close-validator"

	EventTypeCreateDelegation   = "create-delegation"
	EventTypeModifyCompound     = "modify-compound"
	EventTypeUnbondDelegation   = "unbond-delegation"
	EventTypeCreateReDelegation = "create-redelegation"

	EventTypeSlash = "slash"

	AttributeKeyModule       = "stake"
	AttributeKeyHeight       = "height"
	AttributeKeyValidator    = "validator"
	AttributeKeyNewValidator = "new-validator"
	AttributeKeyOwner        = "owner"
	AttributeKeyDelegator    = "delegator"
	AttributeKeyTokens       = "tokens"
	AttributeKeyReason       = "reason"

	AttributeValueDoubleSign = "double_sign"
)
View Source
var (
	DelegationByDelValKey = []byte{0x31} // key: delegator add + validator owner add, value: delegationInfo
	DelegationByValDelKey = []byte{0x32} // key: validator owner add + delegator add, value: nil

	UnbondingHeightDelegatorValidatorKey = []byte{0x41} // key: height + delegator + validator add, value: the amount of qos going to be unbonded on this height
	UnbondingDelegatorHeightValidatorKey = []byte{0x42} // key: delegator + height + validator add, value: nil
	UnbondingValidatorHeightDelegatorKey = []byte{0x43} // key: validator + height + delegator add, value: nil

	RedelegationHeightDelegatorFromValidatorKey = []byte{0x51} // key: height + delegator + fromValidator add, value: redelegations going to be complete on this height
	RedelegationDelegatorHeightFromValidatorKey = []byte{0x52} // key: delegator + height + fromValidator add, value: nil
	RedelegationFromValidatorHeightDelegatorKey = []byte{0x53} // key: fromValidator + height + delegator add, value: nil

)
View Source
var (
	ParamSpace = "stake"

	// keys for stake p
	KeyMaxValidatorCnt             = []byte("max_validator_cnt")
	KeyValidatorVotingStatusLen    = []byte("voting_status_len")
	KeyValidatorVotingStatusLeast  = []byte("voting_status_least")
	KeyValidatorSurvivalSecs       = []byte("survival_secs")
	KeyDelegatorUnbondReturnHeight = []byte("unbond_return_height")
	KeyDelegatorRedelegationHeight = []byte("redelegation_height")
	KeyMaxEvidenceAge              = []byte("max_evidence_age")
	KeySlashFractionDoubleSign     = []byte("slash_fraction_double_sign")
	KeySlashFractionDowntime       = []byte("slash_fraction_downtime")
)

Functions

func BuildCurrentValidatorsAddressKey

func BuildCurrentValidatorsAddressKey() []byte

func BuildDelegationByDelValKey

func BuildDelegationByDelValKey(delAdd btypes.Address, valAdd btypes.Address) []byte

func BuildDelegationByValDelKey

func BuildDelegationByValDelKey(valAdd btypes.Address, delAdd btypes.Address) []byte

func BuildDelegationByValidatorPrefix

func BuildDelegationByValidatorPrefix(valAdd btypes.Address) []byte

func BuildGetDelegationCustomQueryPath

func BuildGetDelegationCustomQueryPath(deleAddr, owner btypes.Address) string

func BuildInactiveValidatorKey

func BuildInactiveValidatorKey(sec uint64, valAddress btypes.Address) []byte

func BuildInactiveValidatorKeyByTime

func BuildInactiveValidatorKeyByTime(inactiveTime time.Time, valAddress btypes.Address) []byte

func BuildOwnerWithValidatorKey

func BuildOwnerWithValidatorKey(ownerAddress btypes.Address) []byte

func BuildQueryDelegationsByDelegatorCustomQueryPath

func BuildQueryDelegationsByDelegatorCustomQueryPath(deleAddr btypes.Address) string

func BuildQueryDelegationsByOwnerCustomQueryPath

func BuildQueryDelegationsByOwnerCustomQueryPath(owner btypes.Address) string

func BuildQueryRedelegationsByDelegatorCustomQueryPath

func BuildQueryRedelegationsByDelegatorCustomQueryPath(deleAddr btypes.Address) string

func BuildQueryUnbondingsByDelegatorCustomQueryPath

func BuildQueryUnbondingsByDelegatorCustomQueryPath(deleAddr btypes.Address) string

func BuildRedelegationByDelegatorPrefix

func BuildRedelegationByDelegatorPrefix(delAddr btypes.Address) []byte

func BuildRedelegationByFromValidatorPrefix

func BuildRedelegationByFromValidatorPrefix(valAddr btypes.Address) []byte

func BuildRedelegationByHeightPrefix

func BuildRedelegationByHeightPrefix(height uint64) []byte

func BuildRedelegationDelegatorHeightFromValidatorKey

func BuildRedelegationDelegatorHeightFromValidatorKey(delAddr btypes.Address, height uint64, valAddr btypes.Address) []byte

func BuildRedelegationFromValidatorHeightDelegatorKey

func BuildRedelegationFromValidatorHeightDelegatorKey(valAddr btypes.Address, height uint64, delAddr btypes.Address) []byte

func BuildRedelegationHeightDelegatorFromValidatorKey

func BuildRedelegationHeightDelegatorFromValidatorKey(height uint64, delAdd btypes.Address, valAddr btypes.Address) []byte

func BuildStakeStoreQueryPath

func BuildStakeStoreQueryPath() []byte

func BuildUnbondingByDelegatorPrefix

func BuildUnbondingByDelegatorPrefix(delAddr btypes.Address) []byte

func BuildUnbondingByValidatorPrefix

func BuildUnbondingByValidatorPrefix(valAddr btypes.Address) []byte

func BuildUnbondingDelegationByHeightPrefix

func BuildUnbondingDelegationByHeightPrefix(height uint64) []byte

func BuildUnbondingDelegatorHeightValidatorKey

func BuildUnbondingDelegatorHeightValidatorKey(delAddr btypes.Address, height uint64, valAddr btypes.Address) []byte

func BuildUnbondingHeightDelegatorValidatorKey

func BuildUnbondingHeightDelegatorValidatorKey(height uint64, delAddr btypes.Address, valAddr btypes.Address) []byte

func BuildUnbondingValidatorHeightDelegatorKey

func BuildUnbondingValidatorHeightDelegatorKey(valAddr btypes.Address, height uint64, delAddr btypes.Address) []byte

func BuildValidatorByVotePower

func BuildValidatorByVotePower(votePower uint64, valAddress btypes.Address) []byte

func BuildValidatorKey

func BuildValidatorKey(valAddress btypes.Address) []byte

func BuildValidatorVoteInfoInWindowKey

func BuildValidatorVoteInfoInWindowKey(index uint64, valAddress btypes.Address) []byte

func BuildValidatorVoteInfoInWindowPrefixKey

func BuildValidatorVoteInfoInWindowPrefixKey(valAddress btypes.Address) []byte

func BuildValidatorVoteInfoKey

func BuildValidatorVoteInfoKey(valAddress btypes.Address) []byte

func BulidValidatorPrefixKey

func BulidValidatorPrefixKey() []byte

func ErrCodeValidatorInactiveIncome

func ErrCodeValidatorInactiveIncome(codeSpace btypes.CodespaceType, msg string) btypes.Error

func ErrCommissionChangeRateGTMaxRate

func ErrCommissionChangeRateGTMaxRate(codeSpace btypes.CodespaceType) btypes.Error

func ErrCommissionChangeRateNegative

func ErrCommissionChangeRateNegative(codeSpace btypes.CodespaceType) btypes.Error

func ErrCommissionGTMaxChangeRate

func ErrCommissionGTMaxChangeRate(codeSpace btypes.CodespaceType) btypes.Error

func ErrCommissionGTMaxRate

func ErrCommissionGTMaxRate(codeSpace btypes.CodespaceType) btypes.Error

func ErrCommissionHuge

func ErrCommissionHuge(codeSpace btypes.CodespaceType) btypes.Error

func ErrCommissionNegative

func ErrCommissionNegative(codeSpace btypes.CodespaceType) btypes.Error

func ErrCommissionUpdateTime

func ErrCommissionUpdateTime(codeSpace btypes.CodespaceType) btypes.Error

func ErrInvalidInput

func ErrInvalidInput(codeSpace btypes.CodespaceType, msg string) btypes.Error

func ErrOwnerHasValidator

func ErrOwnerHasValidator(codeSpace btypes.CodespaceType, msg string) btypes.Error

func ErrOwnerNoEnoughToken

func ErrOwnerNoEnoughToken(codeSpace btypes.CodespaceType, msg string) btypes.Error

func ErrOwnerNotExists

func ErrOwnerNotExists(codeSpace btypes.CodespaceType, msg string) btypes.Error

func ErrValidatorExists

func ErrValidatorExists(codeSpace btypes.CodespaceType, msg string) btypes.Error

func ErrValidatorIsActive

func ErrValidatorIsActive(codeSpace btypes.CodespaceType, msg string) btypes.Error

func ErrValidatorIsInactive

func ErrValidatorIsInactive(codeSpace btypes.CodespaceType, msg string) btypes.Error

func ErrValidatorNotExists

func ErrValidatorNotExists(codeSpace btypes.CodespaceType, msg string) btypes.Error

func GetDelegationValDelKeyAddress

func GetDelegationValDelKeyAddress(key []byte) (valAddr btypes.Address, deleAddr btypes.Address)

func GetRedelegationDelegatorHeightFromValidator

func GetRedelegationDelegatorHeightFromValidator(key []byte) (deleAddr btypes.Address, height uint64, valAddr btypes.Address)

func GetRedelegationFromValidatorHeightDelegator

func GetRedelegationFromValidatorHeightDelegator(key []byte) (valAddr btypes.Address, height uint64, deleAddr btypes.Address)

func GetRedelegationHeightDelegatorFromValidator

func GetRedelegationHeightDelegatorFromValidator(key []byte) (height uint64, deleAddr btypes.Address, valAddr btypes.Address)

func GetUnbondingDelegationDelegatorHeightValidator

func GetUnbondingDelegationDelegatorHeightValidator(key []byte) (deleAddr btypes.Address, height uint64, valAddr btypes.Address)

func GetUnbondingDelegationHeightDelegatorValidator

func GetUnbondingDelegationHeightDelegatorValidator(key []byte) (height uint64, deleAddr btypes.Address, valAddr btypes.Address)

func GetUnbondingDelegationValidatorHeightDelegator

func GetUnbondingDelegationValidatorHeightDelegator(key []byte) (valAddr btypes.Address, height uint64, deleAddr btypes.Address)

func GetValidatorByInactiveKey

func GetValidatorByInactiveKey() []byte

func GetValidatorByVotePowerKey

func GetValidatorByVotePowerKey() []byte

func GetValidatorVoteInfoAddr

func GetValidatorVoteInfoAddr(key []byte) btypes.Address

func GetValidatorVoteInfoInWindowIndexAddr

func GetValidatorVoteInfoInWindowIndexAddr(key []byte) (uint64, btypes.Address)

func GetValidatorVoteInfoInWindowKey

func GetValidatorVoteInfoInWindowKey() []byte

func GetValidatorVoteInfoKey

func GetValidatorVoteInfoKey() []byte

func ValidateGenesis

func ValidateGenesis(data GenesisState) error

Types

type Commission

type Commission struct {
	CommissionRates `json:"commission_rates" yaml:"commission_rates"`
	UpdateTime      time.Time `json:"update_time"` // the last time the commission rate was changed
}

Commission defines a commission parameters for a given validator.

func NewCommission

func NewCommission(rate, maxRate, maxChangeRate qtypes.Dec) Commission

NewCommission returns an initialized validator commission.

func NewCommissionWithTime

func NewCommissionWithTime(rate, maxRate, maxChangeRate qtypes.Dec, updatedAt time.Time) Commission

NewCommission returns an initialized validator commission with a specified update time which should be the current block BFT time.

func (Commission) Equal

func (c Commission) Equal(c2 Commission) bool

Equal checks if the given Commission object is equal to the receiving Commission object.

func (Commission) String

func (c Commission) String() string

String implements the Stringer interface for a Commission.

func (Commission) ValidateNewRate

func (c Commission) ValidateNewRate(newRate qtypes.Dec, blockTime time.Time) btypes.Error

ValidateNewRate performs basic sanity validation checks of a new commission rate. If validation fails, an SDK error is returned.

type CommissionRates

type CommissionRates struct {
	Rate          qtypes.Dec `json:"rate"`            // the commission rate charged to delegators, as a fraction
	MaxRate       qtypes.Dec `json:"max_rate"`        // maximum commission rate which validator can ever charge, as a fraction
	MaxChangeRate qtypes.Dec `json:"max_change_rate"` // maximum daily increase of the validator commission, as a fraction
}

CommissionRates defines the initial commission rates to be used for creating a validator.

func NewCommissionRates

func NewCommissionRates(rate, maxRate, maxChangeRate qtypes.Dec) CommissionRates

NewCommissionRates returns an initialized validator commission rates.

func (CommissionRates) Validate

func (c CommissionRates) Validate() btypes.Error

Validate performs basic sanity validation checks of initial commission parameters. If validation fails, an SDK error is returned.

type DelegationInfo

type DelegationInfo struct {
	DelegatorAddr btypes.Address `json:"delegator_addr"`
	ValidatorAddr btypes.Address `json:"validator_addr"`
	Amount        uint64         `json:"delegate_amount"` // 委托数量。TODO 注意溢出处理
	IsCompound    bool           `json:"is_compound"`     // 是否复投
}

func NewDelegationInfo

func NewDelegationInfo(delAddr btypes.Address, valAddr btypes.Address, amount uint64, isCompound bool) DelegationInfo

type DelegationInfoState

type DelegationInfoState struct {
	DelegatorAddr   btypes.Address `json:"delegator_addr"`
	ValidatorPubKey crypto.PubKey  `json:"validator_pub_key"`
	Amount          uint64         `json:"delegate_amount"`
	IsCompound      bool           `json:"is_compound"`
}

type Description

type Description struct {
	Moniker string `json:"moniker"` // name
	Website string `json:"website"` // optional website link
	Details string `json:"details"` // optional details
}

Description - description fields for a validator

type GenesisState

type GenesisState struct {
	GenTxs                 []txs.TxStd                      `json:"gen_txs"`
	Params                 Params                           `json:"params"`
	Validators             []Validator                      `json:"validators"`            //validatorKey, validatorByOwnerKey,validatorByInactiveKey,validatorByVotePowerKey
	ValidatorsVoteInfo     []ValidatorVoteInfoState         `json:"val_votes_info"`        //validatorVoteInfoKey
	ValidatorsVoteInWindow []ValidatorVoteInWindowInfoState `json:"val_votes_in_window"`   //validatorVoteInfoInWindowKey
	DelegatorsInfo         []DelegationInfoState            `json:"delegators_info"`       //DelegationByDelValKey, DelegationByValDelKey
	DelegatorsUnbondInfo   []UnbondingDelegationInfo        `json:"delegator_unbond_info"` //UnbondingHeightDelegatorKey
	ReDelegationsInfo      []RedelegationInfo               `json:"redelegations_info"`    //ReDelegationHeightDelegatorKey
	CurrentValidators      []Validator                      `json:"current_validators"`    // currentValidatorsAddressKey
}

func DefaultGenesisState

func DefaultGenesisState() GenesisState

func NewGenesisState

func NewGenesisState(params Params,
	validators []Validator,
	validatorsVoteInfo []ValidatorVoteInfoState,
	validatorsVoteInWindow []ValidatorVoteInWindowInfoState,
	delegatorsInfo []DelegationInfoState,
	delegatorsUnbondInfo []UnbondingDelegationInfo,
	reDelegationsInfo []RedelegationInfo,
	currentValidators []Validator) GenesisState

type Hooks

type Hooks interface {
	AfterValidatorCreated(ctx context.Context, val btypes.Address)

	BeforeValidatorRemoved(ctx context.Context, val btypes.Address)

	AfterDelegationCreated(ctx context.Context, val btypes.Address, del btypes.Address)
	BeforeDelegationModified(ctx context.Context, val btypes.Address, del btypes.Address, updateTokes uint64)

	AfterValidatorSlashed(ctx context.Context, slashedTokes uint64)
}

type InactiveCode

type InactiveCode int8

type Params

type Params struct {
	MaxValidatorCnt             uint32        `json:"max_validator_cnt"`
	ValidatorVotingStatusLen    uint32        `json:"voting_status_len"`
	ValidatorVotingStatusLeast  uint32        `json:"voting_status_least"`
	ValidatorSurvivalSecs       uint32        `json:"survival_secs"`
	DelegatorUnbondReturnHeight uint32        `json:"unbond_return_height"`
	DelegatorRedelegationHeight uint32        `json:"redelegation_height"`
	MaxEvidenceAge              time.Duration `json:"max_evidence_age"`
	SlashFractionDoubleSign     types.Dec     `json:"slash_fraction_double_sign"`
	SlashFractionDowntime       types.Dec     `json:"slash_fraction_downtime"`
}

func DefaultParams

func DefaultParams() Params

func NewParams

func NewParams(maxValidatorCnt, validatorVotingStatusLen, validatorVotingStatusLeast, validatorSurvivalSecs,
	delegatorUnbondReturnHeight uint32, delegatorRedelegationHeight uint32, maxEvidenceAge time.Duration,
	slashFractionDoubleSign types.Dec, slashFractionDowntime types.Dec) Params

func (*Params) GetParamSpace

func (p *Params) GetParamSpace() string

func (*Params) KeyValuePairs

func (p *Params) KeyValuePairs() qtypes.KeyValuePairs

func (*Params) Validate

func (p *Params) Validate(key string, value string) (interface{}, btypes.Error)

type RedelegationInfo

type RedelegationInfo struct {
	DelegatorAddr  btypes.Address `json:"delegator_addr"`
	FromValidator  btypes.Address `json:"from_validator"`
	ToValidator    btypes.Address `json:"to_validator"`
	Amount         uint64         `json:"delegate_amount"`
	Height         uint64         `json:"height"`
	CompleteHeight uint64         `json:"complete_height"`
	IsCompound     bool           `json:"is_compound"` // 是否复投
}

re delegate

func NewRedelegateInfo

func NewRedelegateInfo(delAddr btypes.Address, fromValAddr btypes.Address, toValAddr btypes.Address, amount uint64, height uint64, completeHeight uint64, isCompound bool) RedelegationInfo

type UnbondingDelegationInfo

type UnbondingDelegationInfo struct {
	DelegatorAddr  btypes.Address `json:"delegator_addr"`
	ValidatorAddr  btypes.Address `json:"validator_addr"`
	Height         uint64         `json:"height"`
	CompleteHeight uint64         `json:"complete_height"`
	Amount         uint64         `json:"delegate_amount"`
}

unbond

func NewUnbondingDelegationInfo

func NewUnbondingDelegationInfo(delAddr btypes.Address, valAddr btypes.Address, height uint64, completeHeight uint64, amount uint64) UnbondingDelegationInfo

type Validator

type Validator struct {
	Owner           btypes.Address `json:"owner"`
	ValidatorPubKey crypto.PubKey  `json:"pub_key"`
	BondTokens      uint64         `json:"bond_tokens"` //不能超过int64最大值
	Description     Description    `json:"description"`
	Commission      Commission     `json:"commission"`

	Status         int8         `json:"status"`
	InactiveCode   InactiveCode `json:"inactive_code"`
	InactiveTime   time.Time    `json:"inactive_time"`
	InactiveHeight uint64       `json:"inactive_height"`

	MinPeriod  uint64 `json:"min_period"`
	BondHeight uint64 `json:"bond_height"`
}

func (Validator) GetBondTokens

func (val Validator) GetBondTokens() uint64

func (Validator) GetOwner

func (val Validator) GetOwner() btypes.Address

func (Validator) GetValidatorAddress

func (val Validator) GetValidatorAddress() btypes.Address

func (Validator) GetValidatorPubKey

func (val Validator) GetValidatorPubKey() crypto.PubKey

func (Validator) IsActive

func (val Validator) IsActive() bool

func (Validator) ToABCIValidator

func (val Validator) ToABCIValidator() (abciVal abci.Validator)

func (Validator) ToABCIValidatorUpdate

func (val Validator) ToABCIValidatorUpdate(isRemoved bool) (abciVal abci.ValidatorUpdate)

type ValidatorVoteInWindowInfoState

type ValidatorVoteInWindowInfoState struct {
	ValidatorPubKey crypto.PubKey `json:"validator_pub_key"`
	Index           uint64        `json:"index"`
	Vote            bool          `json:"vote"`
}

type ValidatorVoteInfo

type ValidatorVoteInfo struct {
	StartHeight         uint64 `json:"startHeight"`
	IndexOffset         uint64 `json:"indexOffset"` //统计截止高度=StartHeight+IndexOffset-1
	MissedBlocksCounter uint64 `json:"missedBlocksCounter"`
}

func NewValidatorVoteInfo

func NewValidatorVoteInfo(startHeight, indexOffset, missedBlocksCounter uint64) ValidatorVoteInfo

type ValidatorVoteInfoState

type ValidatorVoteInfoState struct {
	ValidatorPubKey crypto.PubKey     `json:"validator_pub_key"`
	VoteInfo        ValidatorVoteInfo `json:"vote_info"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL