Documentation
¶
Index ¶
- Constants
- Variables
- func BuildCurrentValidatorsAddressKey() []byte
- func BuildDelegationByDelValKey(delAdd btypes.Address, valAdd btypes.Address) []byte
- func BuildDelegationByValDelKey(valAdd btypes.Address, delAdd btypes.Address) []byte
- func BuildDelegationByValidatorPrefix(valAdd btypes.Address) []byte
- func BuildGetDelegationCustomQueryPath(deleAddr, owner btypes.Address) string
- func BuildInactiveValidatorKey(sec uint64, valAddress btypes.Address) []byte
- func BuildInactiveValidatorKeyByTime(inactiveTime time.Time, valAddress btypes.Address) []byte
- func BuildOwnerWithValidatorKey(ownerAddress btypes.Address) []byte
- func BuildQueryDelegationsByDelegatorCustomQueryPath(deleAddr btypes.Address) string
- func BuildQueryDelegationsByOwnerCustomQueryPath(owner btypes.Address) string
- func BuildQueryRedelegationsByDelegatorCustomQueryPath(deleAddr btypes.Address) string
- func BuildQueryUnbondingsByDelegatorCustomQueryPath(deleAddr btypes.Address) string
- func BuildRedelegationByDelegatorPrefix(delAddr btypes.Address) []byte
- func BuildRedelegationByFromValidatorPrefix(valAddr btypes.Address) []byte
- func BuildRedelegationByHeightPrefix(height uint64) []byte
- func BuildRedelegationDelegatorHeightFromValidatorKey(delAddr btypes.Address, height uint64, valAddr btypes.Address) []byte
- func BuildRedelegationFromValidatorHeightDelegatorKey(valAddr btypes.Address, height uint64, delAddr btypes.Address) []byte
- func BuildRedelegationHeightDelegatorFromValidatorKey(height uint64, delAdd btypes.Address, valAddr btypes.Address) []byte
- func BuildStakeStoreQueryPath() []byte
- func BuildUnbondingByDelegatorPrefix(delAddr btypes.Address) []byte
- func BuildUnbondingByValidatorPrefix(valAddr btypes.Address) []byte
- func BuildUnbondingDelegationByHeightPrefix(height uint64) []byte
- func BuildUnbondingDelegatorHeightValidatorKey(delAddr btypes.Address, height uint64, valAddr btypes.Address) []byte
- func BuildUnbondingHeightDelegatorValidatorKey(height uint64, delAddr btypes.Address, valAddr btypes.Address) []byte
- func BuildUnbondingValidatorHeightDelegatorKey(valAddr btypes.Address, height uint64, delAddr btypes.Address) []byte
- func BuildValidatorByVotePower(votePower uint64, valAddress btypes.Address) []byte
- func BuildValidatorKey(valAddress btypes.Address) []byte
- func BuildValidatorVoteInfoInWindowKey(index uint64, valAddress btypes.Address) []byte
- func BuildValidatorVoteInfoInWindowPrefixKey(valAddress btypes.Address) []byte
- func BuildValidatorVoteInfoKey(valAddress btypes.Address) []byte
- func BulidValidatorPrefixKey() []byte
- func ErrCodeValidatorInactiveIncome(codeSpace btypes.CodespaceType, msg string) btypes.Error
- func ErrCommissionChangeRateGTMaxRate(codeSpace btypes.CodespaceType) btypes.Error
- func ErrCommissionChangeRateNegative(codeSpace btypes.CodespaceType) btypes.Error
- func ErrCommissionGTMaxChangeRate(codeSpace btypes.CodespaceType) btypes.Error
- func ErrCommissionGTMaxRate(codeSpace btypes.CodespaceType) btypes.Error
- func ErrCommissionHuge(codeSpace btypes.CodespaceType) btypes.Error
- func ErrCommissionNegative(codeSpace btypes.CodespaceType) btypes.Error
- func ErrCommissionUpdateTime(codeSpace btypes.CodespaceType) btypes.Error
- func ErrInvalidInput(codeSpace btypes.CodespaceType, msg string) btypes.Error
- func ErrOwnerHasValidator(codeSpace btypes.CodespaceType, msg string) btypes.Error
- func ErrOwnerNoEnoughToken(codeSpace btypes.CodespaceType, msg string) btypes.Error
- func ErrOwnerNotExists(codeSpace btypes.CodespaceType, msg string) btypes.Error
- func ErrValidatorExists(codeSpace btypes.CodespaceType, msg string) btypes.Error
- func ErrValidatorIsActive(codeSpace btypes.CodespaceType, msg string) btypes.Error
- func ErrValidatorIsInactive(codeSpace btypes.CodespaceType, msg string) btypes.Error
- func ErrValidatorNotExists(codeSpace btypes.CodespaceType, msg string) btypes.Error
- func GetDelegationValDelKeyAddress(key []byte) (valAddr btypes.Address, deleAddr btypes.Address)
- func GetRedelegationDelegatorHeightFromValidator(key []byte) (deleAddr btypes.Address, height uint64, valAddr btypes.Address)
- func GetRedelegationFromValidatorHeightDelegator(key []byte) (valAddr btypes.Address, height uint64, deleAddr btypes.Address)
- func GetRedelegationHeightDelegatorFromValidator(key []byte) (height uint64, deleAddr btypes.Address, valAddr btypes.Address)
- func GetUnbondingDelegationDelegatorHeightValidator(key []byte) (deleAddr btypes.Address, height uint64, valAddr btypes.Address)
- func GetUnbondingDelegationHeightDelegatorValidator(key []byte) (height uint64, deleAddr btypes.Address, valAddr btypes.Address)
- func GetUnbondingDelegationValidatorHeightDelegator(key []byte) (valAddr btypes.Address, height uint64, deleAddr btypes.Address)
- func GetValidatorByInactiveKey() []byte
- func GetValidatorByVotePowerKey() []byte
- func GetValidatorVoteInfoAddr(key []byte) btypes.Address
- func GetValidatorVoteInfoInWindowIndexAddr(key []byte) (uint64, btypes.Address)
- func GetValidatorVoteInfoInWindowKey() []byte
- func GetValidatorVoteInfoKey() []byte
- func ValidateGenesis(data GenesisState) error
- type Commission
- type CommissionRates
- type DelegationInfo
- type DelegationInfoState
- type Description
- type GenesisState
- type Hooks
- type InactiveCode
- type Params
- type RedelegationInfo
- type UnbondingDelegationInfo
- type Validator
- func (val Validator) GetBondTokens() uint64
- func (val Validator) GetOwner() btypes.Address
- func (val Validator) GetValidatorAddress() btypes.Address
- func (val Validator) GetValidatorPubKey() crypto.PubKey
- func (val Validator) IsActive() bool
- func (val Validator) ToABCIValidator() (abciVal abci.Validator)
- func (val Validator) ToABCIValidatorUpdate(isRemoved bool) (abciVal abci.ValidatorUpdate)
- type ValidatorVoteInWindowInfoState
- type ValidatorVoteInfo
- type ValidatorVoteInfoState
Constants ¶
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.
const ( AddrLen = 20 MapperName = "validator" //------query------- Stake = "stake" Delegation = "delegation" Delegations = "delegations" Owner = "owner" Delegator = "delegator" Unbondings = "Unbondings" Redelegations = "Redelegations" )
const ( //Active 可获得挖矿奖励状态 Active int8 = iota //Inactive Inactive //Inactive Code Revoke InactiveCode = iota // 2 MissVoteBlock // 3 MaxValidator // 4 DoubleSign // 5 )
Variables ¶
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" )
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 )
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 BuildStakeStoreQueryPath ¶
func BuildStakeStoreQueryPath() []byte
func BuildValidatorKey ¶
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 GetValidatorByInactiveKey ¶
func GetValidatorByInactiveKey() []byte
func GetValidatorByVotePowerKey ¶
func GetValidatorByVotePowerKey() []byte
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 ¶
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 ¶
type DelegationInfoState ¶
type Description ¶
type Description struct {
Moniker string `json:"moniker"` // name
Logo string `json:"logo"` // optional logo link
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 (*Params) GetParamSpace ¶
func (*Params) KeyValuePairs ¶
func (p *Params) KeyValuePairs() qtypes.KeyValuePairs
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
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
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 (Validator) GetValidatorAddress ¶
func (Validator) GetValidatorPubKey ¶
func (Validator) ToABCIValidator ¶
func (Validator) ToABCIValidatorUpdate ¶
func (val Validator) ToABCIValidatorUpdate(isRemoved bool) (abciVal abci.ValidatorUpdate)
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"`
}