types

package
v0.0.0-...-b5e13e0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

nolint

Index

Constants

View Source
const (
	// ModuleName is the name of the staking module
	ModuleName = "staking"

	// StoreKey is the string store representation
	StoreKey = ModuleName

	// TStoreKey is the string transient store representation
	TStoreKey = "transient_" + ModuleName

	// QuerierRoute is the querier route for the staking module
	QuerierRoute = ModuleName

	// RouterKey is the msg router key for the staking module
	RouterKey = ModuleName
)
View Source
const (
	// DefaultUnbondingTime reflects three weeks in seconds as the default
	// unbonding time.
	// TODO: Justify our choice of default here.
	DefaultUnbondingTime time.Duration = time.Second * 60 * 60 * 24 * 3

	// Default maximum number of bonded validators
	DefaultMaxValidators uint16 = 100

	// Default maximum entries in a UBD/RED pair
	DefaultMaxEntries uint16 = 7
)
View Source
const (
	// TODO: Why can't we just have one string description which can be JSON by convention
	MaxMonikerLength  = 70
	MaxIdentityLength = 3000
	MaxWebsiteLength  = 140
	MaxDetailsLength  = 280
)

nolint

View Source
const DoNotModifyDesc = "[do-not-modify]"

constant used in flags to indicate that description field should not be updated

Variables

View Source
var (
	// 各个键的类型
	KeyUnbondingTime = []byte("UnbondingTime")
	KeyMaxValidators = []byte("MaxValidators")
	KeyMaxEntries    = []byte("KeyMaxEntries")

	// 绑定的钱的面额的key
	KeyBondDenom = []byte("BondDenom")
)

nolint - Keys for parameter access 参数访问的键

View Source
var MsgCdc *codec.Codec

generic sealed codec to be used throughout sdk

Functions

func ErrBadDelegationAddr

func ErrBadDelegationAddr(codespace sdk.CodespaceType) sdk.Error

func ErrBadDelegationAmount

func ErrBadDelegationAmount(codespace sdk.CodespaceType) sdk.Error

func ErrBadDelegatorAddr

func ErrBadDelegatorAddr(codespace sdk.CodespaceType) sdk.Error

func ErrBadDenom

func ErrBadDenom(codespace sdk.CodespaceType) sdk.Error

func ErrBadRedelegationAddr

func ErrBadRedelegationAddr(codespace sdk.CodespaceType) sdk.Error

func ErrBadRedelegationDst

func ErrBadRedelegationDst(codespace sdk.CodespaceType) sdk.Error

func ErrBadRemoveValidator

func ErrBadRemoveValidator(codespace sdk.CodespaceType) sdk.Error

func ErrBadSharesAmount

func ErrBadSharesAmount(codespace sdk.CodespaceType) sdk.Error

func ErrBadSharesPercent

func ErrBadSharesPercent(codespace sdk.CodespaceType) sdk.Error

func ErrBadValidatorAddr

func ErrBadValidatorAddr(codespace sdk.CodespaceType) sdk.Error

func ErrBothShareMsgsGiven

func ErrBothShareMsgsGiven(codespace sdk.CodespaceType) sdk.Error

func ErrCommissionChangeRateGTMaxRate

func ErrCommissionChangeRateGTMaxRate(codespace sdk.CodespaceType) sdk.Error

func ErrCommissionChangeRateNegative

func ErrCommissionChangeRateNegative(codespace sdk.CodespaceType) sdk.Error

func ErrCommissionGTMaxChangeRate

func ErrCommissionGTMaxChangeRate(codespace sdk.CodespaceType) sdk.Error

func ErrCommissionGTMaxRate

func ErrCommissionGTMaxRate(codespace sdk.CodespaceType) sdk.Error

func ErrCommissionHuge

func ErrCommissionHuge(codespace sdk.CodespaceType) sdk.Error

func ErrCommissionNegative

func ErrCommissionNegative(codespace sdk.CodespaceType) sdk.Error

func ErrCommissionUpdateTime

func ErrCommissionUpdateTime(codespace sdk.CodespaceType) sdk.Error

func ErrDelegationValidatorEmpty

func ErrDelegationValidatorEmpty(codespace sdk.CodespaceType) sdk.Error

func ErrDelegatorShareExRateInvalid

func ErrDelegatorShareExRateInvalid(codespace sdk.CodespaceType) sdk.Error

func ErrDescriptionLength

func ErrDescriptionLength(codespace sdk.CodespaceType, descriptor string, got, max int) sdk.Error

func ErrInsufficientShares

func ErrInsufficientShares(codespace sdk.CodespaceType) sdk.Error

func ErrMaxRedelegationEntries

func ErrMaxRedelegationEntries(codespace sdk.CodespaceType) sdk.Error

func ErrMaxUnbondingDelegationEntries

func ErrMaxUnbondingDelegationEntries(codespace sdk.CodespaceType) sdk.Error

func ErrMinSelfDelegationDecreased

func ErrMinSelfDelegationDecreased(codespace sdk.CodespaceType) sdk.Error

func ErrMinSelfDelegationInvalid

func ErrMinSelfDelegationInvalid(codespace sdk.CodespaceType) sdk.Error

func ErrMissingSignature

func ErrMissingSignature(codespace sdk.CodespaceType) sdk.Error

func ErrNeitherShareMsgsGiven

func ErrNeitherShareMsgsGiven(codespace sdk.CodespaceType) sdk.Error

func ErrNilDelegatorAddr

func ErrNilDelegatorAddr(codespace sdk.CodespaceType) sdk.Error

func ErrNilValidatorAddr

func ErrNilValidatorAddr(codespace sdk.CodespaceType) sdk.Error

validator

func ErrNoDelegation

func ErrNoDelegation(codespace sdk.CodespaceType) sdk.Error

func ErrNoDelegatorForAddress

func ErrNoDelegatorForAddress(codespace sdk.CodespaceType) sdk.Error

func ErrNoRedelegation

func ErrNoRedelegation(codespace sdk.CodespaceType) sdk.Error

func ErrNoUnbondingDelegation

func ErrNoUnbondingDelegation(codespace sdk.CodespaceType) sdk.Error

func ErrNoValidatorFound

func ErrNoValidatorFound(codespace sdk.CodespaceType) sdk.Error

func ErrNotEnoughDelegationShares

func ErrNotEnoughDelegationShares(codespace sdk.CodespaceType, shares string) sdk.Error

func ErrNotMature

func ErrNotMature(codespace sdk.CodespaceType, operation, descriptor string, got, min time.Time) sdk.Error

func ErrSelfDelegationBelowMinimum

func ErrSelfDelegationBelowMinimum(codespace sdk.CodespaceType) sdk.Error

func ErrSelfRedelegation

func ErrSelfRedelegation(codespace sdk.CodespaceType) sdk.Error

func ErrTransitiveRedelegation

func ErrTransitiveRedelegation(codespace sdk.CodespaceType) sdk.Error

func ErrValidatorJailed

func ErrValidatorJailed(codespace sdk.CodespaceType) sdk.Error

func ErrValidatorOwnerExists

func ErrValidatorOwnerExists(codespace sdk.CodespaceType) sdk.Error

func ErrValidatorPubKeyExists

func ErrValidatorPubKeyExists(codespace sdk.CodespaceType) sdk.Error

func ErrValidatorPubKeyTypeNotSupported

func ErrValidatorPubKeyTypeNotSupported(codespace sdk.CodespaceType, keyType string, supportedTypes []string) sdk.Error

func ErrVerySmallRedelegation

func ErrVerySmallRedelegation(codespace sdk.CodespaceType) sdk.Error

func MustMarshalDelegation

func MustMarshalDelegation(cdc *codec.Codec, delegation Delegation) []byte

return the delegation

func MustMarshalRED

func MustMarshalRED(cdc *codec.Codec, red Redelegation) []byte

return the redelegation

func MustMarshalUBD

func MustMarshalUBD(cdc *codec.Codec, ubd UnbondingDelegation) []byte

return the unbonding delegation

func MustMarshalValidator

func MustMarshalValidator(cdc *codec.Codec, validator Validator) []byte

return the redelegation

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

Register concrete types on codec codec

Types

type BankKeeper

type BankKeeper interface {
	DelegateCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Tags, sdk.Error)
	UndelegateCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Tags, sdk.Error)
}

expected bank keeper

type CodeType

type CodeType = sdk.CodeType
const (
	DefaultCodespace sdk.CodespaceType = ModuleName

	CodeInvalidValidator  CodeType = 101
	CodeInvalidDelegation CodeType = 102
	CodeInvalidInput      CodeType = 103
	CodeValidatorJailed   CodeType = 104
	CodeInvalidAddress    CodeType = sdk.CodeInvalidAddress
	CodeUnauthorized      CodeType = sdk.CodeUnauthorized
	CodeInternal          CodeType = sdk.CodeInternal
	CodeUnknownRequest    CodeType = sdk.CodeUnknownRequest
)

type Commission

type Commission struct {
	// 表示可以从 委托人身上抽取的佣金比
	Rate sdk.Dec `json:"rate"` // the commission rate charged to delegators, as a fraction

	// 此验证人可以收取的最高佣金率
	MaxRate sdk.Dec `json:"max_rate"` // maximum commission rate which this validator can ever charge, as a fraction

	// 验证人的佣金的每日最大增幅率
	MaxChangeRate sdk.Dec `json:"max_change_rate"` // maximum daily increase of the validator commission, as a fraction

	// 信息更新时间
	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 sdk.Dec) Commission

NewCommission returns an initialized validator commission.

func NewCommissionWithTime

func NewCommissionWithTime(rate, maxRate, maxChangeRate sdk.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) Validate

func (c Commission) Validate() sdk.Error

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

func (Commission) ValidateNewRate

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

ValidateNewRate performs basic sanity validation checks of a new commission rate. If validation fails, an SDK error is returned. * 校验 新设置的佣金比合法性 ValidateNewRate执行新佣金率的基本健全性验证检查。 如果验证失败,则返回错误。

type CommissionMsg

type CommissionMsg struct {

	// 向委托人收取的佣金率
	Rate sdk.Dec `json:"rate"` // the commission rate charged to delegators, as a fraction

	// 验证人可以收取的最高佣金率
	MaxRate sdk.Dec `json:"max_rate"` // maximum commission rate which validator can ever charge, as a fraction

	// 验证人佣金的每日最大增幅
	MaxChangeRate sdk.Dec `json:"max_change_rate"` // maximum daily increase of the validator commission, as a fraction
}

CommissionMsg defines a commission message to be used for creating a validator. CommissionMsg定义用于创建验证人的佣金消息。

func NewCommissionMsg

func NewCommissionMsg(rate, maxRate, maxChangeRate sdk.Dec) CommissionMsg

NewCommissionMsg returns an initialized validator commission message.

type DVPair

type DVPair struct {
	DelegatorAddress sdk.AccAddress
	ValidatorAddress sdk.ValAddress
}

DVPair is struct that just has a delegator-validator pair with no other data. It is intended to be used as a marshalable pointer. For example, a DVPair can be used to construct the key to getting an UnbondingDelegation from state. * DVPair是一个只有一个【委托者 - 验证者】kv对,而没有其他数据的结构。 它旨在用作可编组指针。 例如,DVPair可用于构建从状态获取UnbondingDelegation的密钥。

type DVVTriplet

type DVVTriplet struct {
	DelegatorAddress    sdk.AccAddress
	ValidatorSrcAddress sdk.ValAddress
	ValidatorDstAddress sdk.ValAddress
}

DVVTriplet is struct that just has a delegator-validator-validator triplet with no other data. It is intended to be used as a marshalable pointer. For example, a DVVTriplet can be used to construct the key to getting a Redelegation from state.

type Delegation

type Delegation struct {
	// 委托人地址
	DelegatorAddress sdk.AccAddress `json:"delegator_address"`
	// 被委托的验证人地址
	ValidatorAddress sdk.ValAddress `json:"validator_address"`
	// 委托的金额
	Shares sdk.Dec `json:"shares"`
}

Delegation represents the bond with tokens held by an account. It is owned by one delegator, and is associated with the voting power of one validator. * 委托实例

func MustUnmarshalDelegation

func MustUnmarshalDelegation(cdc *codec.Codec, value []byte) Delegation

return the delegation

func NewDelegation

func NewDelegation(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress,
	shares sdk.Dec) Delegation

NewDelegation creates a new delegation object

func UnmarshalDelegation

func UnmarshalDelegation(cdc *codec.Codec, value []byte) (delegation Delegation, err error)

return the delegation

func (Delegation) Equal

func (d Delegation) Equal(d2 Delegation) bool

nolint

func (Delegation) GetDelegatorAddr

func (d Delegation) GetDelegatorAddr() sdk.AccAddress

nolint - for sdk.Delegation

func (Delegation) GetShares

func (d Delegation) GetShares() sdk.Dec

func (Delegation) GetValidatorAddr

func (d Delegation) GetValidatorAddr() sdk.ValAddress

func (Delegation) String

func (d Delegation) String() string

String returns a human readable string representation of a Delegation.

type Delegations

type Delegations []Delegation

Delegations is a collection of delegations

func (Delegations) String

func (d Delegations) String() (out string)

type Description

type Description struct {
	// 验证人的名称
	Moniker string `json:"moniker"` // name
	// 可选的身份签名(例如UPort或Keybase)
	Identity string `json:"identity"` // optional identity signature (ex. UPort or Keybase)
	// 可选的网站链接(验证人的主页?)
	Website string `json:"website"` // optional website link
	// 一些描述信息
	Details string `json:"details"` // optional details
}

Description - description fields for a validator * 验证人的描述信息 验证人的字段

func NewDescription

func NewDescription(moniker, identity, website, details string) Description

NewDescription returns a new Description with the provided values.

func (Description) EnsureLength

func (d Description) EnsureLength() (Description, sdk.Error)

EnsureLength ensures the length of a validator's description. * 校验 验证人的描述信息中各个字段的长度

func (Description) UpdateDescription

func (d Description) UpdateDescription(d2 Description) (Description, sdk.Error)

UpdateDescription updates the fields of a given description. An error is returned if the resulting description contains an invalid length.

type DistributionKeeper

type DistributionKeeper interface {
	GetFeePoolCommunityCoins(ctx sdk.Context) sdk.DecCoins
	GetValidatorOutstandingRewardsCoins(ctx sdk.Context, val sdk.ValAddress) sdk.DecCoins
}

expected coin keeper

type FeeCollectionKeeper

type FeeCollectionKeeper interface {
	GetCollectedFees(ctx sdk.Context) sdk.Coins
}

expected fee collection keeper

type GenesisState

type GenesisState struct {
	Pool                 Pool                  `json:"pool"`
	Params               Params                `json:"params"`
	LastTotalPower       sdk.Int               `json:"last_total_power"`
	LastValidatorPowers  []LastValidatorPower  `json:"last_validator_powers"`
	Validators           Validators            `json:"validators"`
	Delegations          Delegations           `json:"delegations"`
	UnbondingDelegations []UnbondingDelegation `json:"unbonding_delegations"`
	Redelegations        []Redelegation        `json:"redelegations"`
	Exported             bool                  `json:"exported"`
}

GenesisState - all staking state that must be provided at genesis

func DefaultGenesisState

func DefaultGenesisState() GenesisState

get raw genesis raw message for testing

func NewGenesisState

func NewGenesisState(pool Pool, params Params, validators []Validator, delegations []Delegation) GenesisState

type LastValidatorPower

type LastValidatorPower struct {
	Address sdk.ValAddress
	Power   int64
}

Last validator power, needed for validator set update logic

type MsgBeginRedelegate

type MsgBeginRedelegate struct {
	DelegatorAddress sdk.AccAddress `json:"delegator_address"`
	// 旧有的委托 验证人
	ValidatorSrcAddress sdk.ValAddress `json:"validator_src_address"`
	// 新的委托 验证人
	ValidatorDstAddress sdk.ValAddress `json:"validator_dst_address"`
	SharesAmount        sdk.Dec        `json:"shares_amount"`
}

MsgDelegate - struct for bonding transactions

func NewMsgBeginRedelegate

func NewMsgBeginRedelegate(delAddr sdk.AccAddress, valSrcAddr,
	valDstAddr sdk.ValAddress, sharesAmount sdk.Dec) MsgBeginRedelegate

func (MsgBeginRedelegate) GetSignBytes

func (msg MsgBeginRedelegate) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgBeginRedelegate) GetSigners

func (msg MsgBeginRedelegate) GetSigners() []sdk.AccAddress

func (MsgBeginRedelegate) Route

func (msg MsgBeginRedelegate) Route() string

nolint

func (MsgBeginRedelegate) Type

func (msg MsgBeginRedelegate) Type() string

func (MsgBeginRedelegate) ValidateBasic

func (msg MsgBeginRedelegate) ValidateBasic() sdk.Error

quick validity check

type MsgCreateValidator

type MsgCreateValidator struct {
	// 验证人的描述信息
	Description Description `json:"description"`
	// 验证人自定义的佣金信息
	Commission CommissionMsg `json:"commission"`

	// 验证人自声明的最小自委托 (自己设定,且不可更改)
	MinSelfDelegation sdk.Int `json:"min_self_delegation"`
	// 委托人的地址
	DelegatorAddress sdk.AccAddress `json:"delegator_address"`

	// 质押的验证人地址
	ValidatorAddress sdk.ValAddress `json:"validator_address"`
	// 质押的验证人公钥
	PubKey crypto.PubKey `json:"pubkey"`
	// 质押的钱
	Value sdk.Coin `json:"value"`
}

MsgCreateValidator - struct for bonding transactions * 客户端的创建验证人入参

func NewMsgCreateValidator

func NewMsgCreateValidator(
	valAddr sdk.ValAddress, pubKey crypto.PubKey, selfDelegation sdk.Coin,
	description Description, commission CommissionMsg, minSelfDelegation sdk.Int,
) MsgCreateValidator

Default way to create validator. Delegator address and validator address are the same

func (MsgCreateValidator) GetSignBytes

func (msg MsgCreateValidator) GetSignBytes() []byte

GetSignBytes returns the message bytes to sign over.

func (MsgCreateValidator) GetSigners

func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress

Return address(es) that must sign over msg.GetSignBytes()

func (MsgCreateValidator) MarshalJSON

func (msg MsgCreateValidator) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface to provide custom JSON serialization of the MsgCreateValidator type.

func (MsgCreateValidator) Route

func (msg MsgCreateValidator) Route() string

nolint

func (MsgCreateValidator) Type

func (msg MsgCreateValidator) Type() string

func (*MsgCreateValidator) UnmarshalJSON

func (msg *MsgCreateValidator) UnmarshalJSON(bz []byte) error

UnmarshalJSON implements the json.Unmarshaler interface to provide custom JSON deserialization of the MsgCreateValidator type.

func (MsgCreateValidator) ValidateBasic

func (msg MsgCreateValidator) ValidateBasic() sdk.Error

quick validity check

type MsgDelegate

type MsgDelegate struct {
	DelegatorAddress sdk.AccAddress `json:"delegator_address"`
	ValidatorAddress sdk.ValAddress `json:"validator_address"`
	Value            sdk.Coin       `json:"value"`
}

MsgDelegate - struct for bonding transactions * 委托交易的请求入参

func NewMsgDelegate

func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, value sdk.Coin) MsgDelegate

func (MsgDelegate) GetSignBytes

func (msg MsgDelegate) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgDelegate) GetSigners

func (msg MsgDelegate) GetSigners() []sdk.AccAddress

func (MsgDelegate) Route

func (msg MsgDelegate) Route() string

nolint

func (MsgDelegate) Type

func (msg MsgDelegate) Type() string

func (MsgDelegate) ValidateBasic

func (msg MsgDelegate) ValidateBasic() sdk.Error

quick validity check

type MsgEditValidator

type MsgEditValidator struct {

	// 验证人的信息
	Description

	// 验证人地址
	ValidatorAddress sdk.ValAddress `json:"address"`

	// We pass a reference to the new commission rate and min self delegation as it's not mandatory to
	// update. If not updated, the deserialized rate will be zero with no way to
	// distinguish if an update was intended.
	//
	// REF: #2373
	/**
	我们通过了对新佣金率和最低自我授权的引用,因为它不是必须更新的。
	如果未更新,则反序列化的速率将为零,无法区分是否有更新。
	NOTE: 那这就是代码设计层面上的不足了
	*/
	CommissionRate    *sdk.Dec `json:"commission_rate"`
	MinSelfDelegation *sdk.Int `json:"min_self_delegation"`
}

MsgEditValidator - struct for editing a validator MsgEditValidator - 用于更新验证人的结构体

func NewMsgEditValidator

func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRate *sdk.Dec, newMinSelfDelegation *sdk.Int) MsgEditValidator

func (MsgEditValidator) GetSignBytes

func (msg MsgEditValidator) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgEditValidator) GetSigners

func (msg MsgEditValidator) GetSigners() []sdk.AccAddress

func (MsgEditValidator) Route

func (msg MsgEditValidator) Route() string

nolint

func (MsgEditValidator) Type

func (msg MsgEditValidator) Type() string

func (MsgEditValidator) ValidateBasic

func (msg MsgEditValidator) ValidateBasic() sdk.Error

quick validity check

type MsgUndelegate

type MsgUndelegate struct {
	DelegatorAddress sdk.AccAddress `json:"delegator_address"`
	ValidatorAddress sdk.ValAddress `json:"validator_address"`
	SharesAmount     sdk.Dec        `json:"shares_amount"`
}

MsgUndelegate - struct for unbonding transactions

func NewMsgUndelegate

func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount sdk.Dec) MsgUndelegate

func (MsgUndelegate) GetSignBytes

func (msg MsgUndelegate) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgUndelegate) GetSigners

func (msg MsgUndelegate) GetSigners() []sdk.AccAddress

func (MsgUndelegate) Route

func (msg MsgUndelegate) Route() string

nolint

func (MsgUndelegate) Type

func (msg MsgUndelegate) Type() string

func (MsgUndelegate) ValidateBasic

func (msg MsgUndelegate) ValidateBasic() sdk.Error

quick validity check

type Params

type Params struct {

	// 解锁时长
	UnbondingTime time.Duration `json:"unbonding_time"` // time duration of unbonding

	// 最大验证人数量(max uint16 = 65535)
	MaxValidators uint16 `json:"max_validators"` // maximum number of validators (max uint16 = 65535)

	// 无绑定委托或重新委托的最大条目(单个 一对/三重奏)
	MaxEntries uint16 `json:"max_entries"` // max entries for either unbonding delegation or redelegation (per pair/trio)

	// 质押的币面额
	BondDenom string `json:"bond_denom"` // bondable coin denomination
}

Params defines the high level settings for staking Params定义了经济模型的高阶配置

func DefaultParams

func DefaultParams() Params

DefaultParams returns a default set of parameters.

func MustUnmarshalParams

func MustUnmarshalParams(cdc *codec.Codec, value []byte) Params

unmarshal the current staking params value from store key or panic

func NewParams

func NewParams(unbondingTime time.Duration, maxValidators, maxEntries uint16,
	bondDenom string) Params

func UnmarshalParams

func UnmarshalParams(cdc *codec.Codec, value []byte) (params Params, err error)

unmarshal the current staking params value from store key

func (Params) Equal

func (p Params) Equal(p2 Params) bool

Equal returns a boolean determining if two Param types are identical. TODO: This is slower than comparing struct fields directly

func (*Params) ParamSetPairs

func (p *Params) ParamSetPairs() params.ParamSetPairs

Implements params.ParamSet

func (Params) String

func (p Params) String() string

String returns a human readable string representation of the parameters.

func (Params) Validate

func (p Params) Validate() error

validate a set of params

type Pool

type Pool struct {
	// 记录着目前流通的未与验证人绑定的令牌(未绑定或未绑定) (就是那些,减持质押或者减持委托的token)
	NotBondedTokens sdk.Int `json:"not_bonded_tokens"` // tokens which are not bonded to a validator (unbonded or unbonding)
	// 目前与验证人绑定的令牌
	BondedTokens sdk.Int `json:"bonded_tokens"` // tokens which are currently bonded to a validator
}

Pool - tracking bonded and not-bonded token supply of the bond denomination Pool: 用于跟踪锁定及非锁定代币供应

func InitialPool

func InitialPool() Pool

initial pool for testing

func MustUnmarshalPool

func MustUnmarshalPool(cdc *codec.Codec, value []byte) Pool

unmarshal the current pool value from store key or panics

func UnmarshalPool

func UnmarshalPool(cdc *codec.Codec, value []byte) (pool Pool, err error)

unmarshal the current pool value from store key

func (Pool) BondedRatio

func (p Pool) BondedRatio() sdk.Dec

Get the fraction of the staking token which is currently bonded

func (Pool) Equal

func (p Pool) Equal(p2 Pool) bool

nolint TODO: This is slower than comparing struct fields directly

func (Pool) String

func (p Pool) String() string

String returns a human readable string representation of a pool.

func (Pool) TokenSupply

func (p Pool) TokenSupply() sdk.Int

Sum total of all staking tokens in the pool

type Redelegation

type Redelegation struct {
	DelegatorAddress    sdk.AccAddress      `json:"delegator_address"`     // delegator
	ValidatorSrcAddress sdk.ValAddress      `json:"validator_src_address"` // validator redelegation source operator addr
	ValidatorDstAddress sdk.ValAddress      `json:"validator_dst_address"` // validator redelegation destination operator addr
	Entries             []RedelegationEntry `json:"entries"`               // redelegation entries
}

Redelegation contains the list of a particular delegator's redelegating bonds from a particular source validator to a particular destination validator

某个验证人身上的某个委托的重置信息

func MustUnmarshalRED

func MustUnmarshalRED(cdc *codec.Codec, value []byte) Redelegation

unmarshal a redelegation from a store value

func NewRedelegation

func NewRedelegation(delegatorAddr sdk.AccAddress, validatorSrcAddr,
	validatorDstAddr sdk.ValAddress, creationHeight int64,
	minTime time.Time, balance sdk.Int,
	sharesDst sdk.Dec) Redelegation

NewRedelegation - create a new redelegation object

func UnmarshalRED

func UnmarshalRED(cdc *codec.Codec, value []byte) (red Redelegation, err error)

unmarshal a redelegation from a store value

func (*Redelegation) AddEntry

func (d *Redelegation) AddEntry(creationHeight int64,
	minTime time.Time, balance sdk.Int,
	sharesDst sdk.Dec)

AddEntry - append entry to the unbonding delegation

func (Redelegation) Equal

func (d Redelegation) Equal(d2 Redelegation) bool

nolint inefficient but only used in tests

func (*Redelegation) RemoveEntry

func (d *Redelegation) RemoveEntry(i int64)

RemoveEntry - remove entry at index i to the unbonding delegation

func (Redelegation) String

func (d Redelegation) String() string

String returns a human readable string representation of a Redelegation.

type RedelegationEntry

type RedelegationEntry struct {
	CreationHeight int64     `json:"creation_height"` // height at which the redelegation took place
	CompletionTime time.Time `json:"completion_time"` // time at which the redelegation will complete
	InitialBalance sdk.Int   `json:"initial_balance"` // initial balance when redelegation started
	SharesDst      sdk.Dec   `json:"shares_dst"`      // amount of destination-validator shares created by redelegation
}

RedelegationEntry - entry to a Redelegation

重置委托 条目单元

func NewRedelegationEntry

func NewRedelegationEntry(creationHeight int64,
	completionTime time.Time, balance sdk.Int,
	sharesDst sdk.Dec) RedelegationEntry

NewRedelegation - create a new redelegation object

func (RedelegationEntry) IsMature

func (e RedelegationEntry) IsMature(currentTime time.Time) bool

IsMature - is the current entry mature

type Redelegations

type Redelegations []Redelegation

Redelegations are a collection of Redelegation

func (Redelegations) String

func (d Redelegations) String() (out string)

type UnbondingDelegation

type UnbondingDelegation struct {
	// 委托人地址
	DelegatorAddress sdk.AccAddress `json:"delegator_address"` // delegator
	// 该委托人所解除委托的 验证人地址
	ValidatorAddress sdk.ValAddress `json:"validator_address"` // validator unbonding from operator addr
	// 所有【减持】委托的条目信息
	Entries []UnbondingDelegationEntry `json:"entries"` // unbonding delegation entries
}

UnbondingDelegation stores all of a single delegator's unbonding bonds for a single validator in an time-ordered list * UnbondingDelegation存储所有单个委托人的无约束债券 某个验证人身上的某个委托人的N次减持信息

func MustUnmarshalUBD

func MustUnmarshalUBD(cdc *codec.Codec, value []byte) UnbondingDelegation

unmarshal a unbonding delegation from a store value

func NewUnbondingDelegation

func NewUnbondingDelegation(delegatorAddr sdk.AccAddress,
	validatorAddr sdk.ValAddress, creationHeight int64, minTime time.Time,
	balance sdk.Int) UnbondingDelegation

NewUnbondingDelegation - create a new unbonding delegation object

新建 减持条目的结构体,且追加第一个 减持条目单元

func UnmarshalUBD

func UnmarshalUBD(cdc *codec.Codec, value []byte) (ubd UnbondingDelegation, err error)

unmarshal a unbonding delegation from a store value

func (*UnbondingDelegation) AddEntry

func (d *UnbondingDelegation) AddEntry(creationHeight int64,
	minTime time.Time, balance sdk.Int)

AddEntry - append entry to the unbonding delegation

向该委托的减持条目的结构体中 追加 减持条目单元

func (UnbondingDelegation) Equal

nolint inefficient but only used in testing

func (*UnbondingDelegation) RemoveEntry

func (d *UnbondingDelegation) RemoveEntry(i int64)

RemoveEntry - remove entry at index i to the unbonding delegation

func (UnbondingDelegation) String

func (d UnbondingDelegation) String() string

String returns a human readable string representation of an UnbondingDelegation.

type UnbondingDelegationEntry

type UnbondingDelegationEntry struct {
	// 解除(减持)委托时的块高
	CreationHeight int64 `json:"creation_height"` // height which the unbonding took place
	// 解除(减持)委托时的区块时间戳
	CompletionTime time.Time `json:"completion_time"` // time at which the unbonding delegation will complete

	/*
		这个是 发起减持时的钱
	*/
	InitialBalance sdk.Int `json:"initial_balance"` // atoms initially sch eduled to receive at completion
	/*
		这个是如果有 惩罚而被削减的话,就是 减持时的钱 - 被惩罚的钱
	*/
	Balance sdk.Int `json:"balance"` // atoms to receive at completion
}

UnbondingDelegationEntry - entry to an UnbondingDelegation

解除委托的条目信息 (减持的条目)

func NewUnbondingDelegationEntry

func NewUnbondingDelegationEntry(creationHeight int64, completionTime time.Time,
	balance sdk.Int) UnbondingDelegationEntry

NewUnbondingDelegation - create a new unbonding delegation object

创建一个 减持条目单元

func (UnbondingDelegationEntry) IsMature

func (e UnbondingDelegationEntry) IsMature(currentTime time.Time) bool

IsMature - is the current entry mature

判断 目标时间 是否不在当前时间之后 TODO 等于 或者 在当前时间之前

type UnbondingDelegations

type UnbondingDelegations []UnbondingDelegation

UnbondingDelegations is a collection of UnbondingDelegation

func (UnbondingDelegations) String

func (ubds UnbondingDelegations) String() (out string)

type Validator

type Validator struct {
	// 验证人的地址; 以JSON编码的bech
	/**
	Bech32是一种地址格式。 它由BIP173作为SegWit地址引入。
	Bech32由42个符号组成,以bc1开头。
	例如:bc1qa5ndt07z2lu7r2kl6zrffw362chj74vse76lq5
	Bech32地址本身就与SegWit兼容。该地址格式也称为“bc1地址”。

	虽然此地址格式已包含在某些实施中,但截至2017年12月,在更多软件支持该格式之前,建议不要使用地址格式
	*/
	OperatorAddress sdk.ValAddress `json:"operator_address"` // address of the validator's operator; bech encoded in JSON

	// 验证者的共识公钥; 以JSON编码的bech
	// 用于做共识时用的公钥
	ConsPubKey crypto.PubKey `json:"consensus_pubkey"` // the consensus public key of the validator; bech encoded in JSON

	// 表示 当前验证人是否属于锁定状态
	// 这个貌似和 slash (惩罚机制) 相关的 (入狱?)
	Jailed bool `json:"jailed"` // has the validator been jailed from bonded status?

	// 验证器状态(已锁定/解除锁定中/未锁定) TODO [这个主要是 解质押的时候 锁定 三周 用]
	// TODO  cosmos 也类似有结算锁定期和犹豫期 ??
	Status sdk.BondStatus `json:"status"` // validator status (bonded/unbonding/unbonded)

	// 委托代币(包括自我授权)
	Tokens sdk.Int `json:"tokens"` // delegated tokens (incl. self-delegation)

	// 发给验证人的委托人发出的总委托的 占比?
	DelegatorShares sdk.Dec `json:"delegator_shares"` // total shares issued to a validator's delegators

	// 当前 验证人的一些描述信息
	Description Description `json:"description"` // description terms for the validator

	// 如果解开锁定,则此高度为该验证人解开锁定时的高度。
	UnbondingHeight int64 `json:"unbonding_height"` // if unbonding, height at which this validator has begun unbonding

	// 如果解开锁定,验证器完成解开锁定动作的最短时间
	UnbondingCompletionTime time.Time `json:"unbonding_time"` // if unbonding, min time for the validator to complete unbonding

	// 佣金参数 (佣金比例?)
	Commission Commission `json:"commission"` // commission parameters

	// 验证人自声明的最小自委托门槛
	MinSelfDelegation sdk.Int `json:"min_self_delegation"` // validator's self declared minimum self delegation
}

Validator defines the total amount of bond shares and their exchange rate to coins. Slashing results in a decrease in the exchange rate, allowing correct calculation of future undelegations without iterating over delegators. When coins are delegated to this validator, the validator is credited with a delegation whose number of bond shares is based on the amount of coins delegated divided by the current exchange rate. Voting power can be calculated as total bonded shares multiplied by exchange rate. * Validator: 定义债券份额的总额及其对硬币的汇率。 削减导致汇率下降,允许正确 计算未来的未取消保护而不迭代委托人。 当硬币被委托给该验证器时,验证器被记入一个代表团, 该代表团的债券份额数基于所委托的硬币数量除以当前汇率。 投票权可以计算为总保税份额乘以汇率。

这个就是经济模型的 验证人结构

func MustUnmarshalValidator

func MustUnmarshalValidator(cdc *codec.Codec, value []byte) Validator

unmarshal a redelegation from a store value

func NewValidator

func NewValidator(operator sdk.ValAddress, pubKey crypto.PubKey, description Description) Validator

NewValidator - initialize a new validator 创建一个 验证人

func UnmarshalValidator

func UnmarshalValidator(cdc *codec.Codec, value []byte) (validator Validator, err error)

unmarshal a redelegation from a store value

func (Validator) ABCIValidatorUpdate

func (v Validator) ABCIValidatorUpdate() abci.ValidatorUpdate

ABCIValidatorUpdate returns an abci.ValidatorUpdate from a staking validator type with the full validator power * ABCIValidatorUpdate: 从 staking的完整 validator类型返回abci.ValidatorUpdate

func (Validator) ABCIValidatorUpdateZero

func (v Validator) ABCIValidatorUpdateZero() abci.ValidatorUpdate

ABCIValidatorUpdateZero returns an abci.ValidatorUpdate from a staking validator type with zero power used for validator updates.

func (Validator) AddTokensFromDel

func (v Validator) AddTokensFromDel(pool Pool, amount sdk.Int) (Validator, Pool, sdk.Dec)

AddTokensFromDel adds tokens to a validator CONTRACT: Tokens are assumed to have come from not-bonded pool. * AddTokensFromDel将币添加到验证人 合约:假设代币来自非绑定池。

钱被追加到token字段 钱的占比被追加到DelegatorShares字段

func (Validator) BondedTokens

func (v Validator) BondedTokens() sdk.Int

get the bonded tokens which the validator holds

func (Validator) ConsAddress

func (v Validator) ConsAddress() sdk.ConsAddress

return the TM validator address

func (Validator) GetBondedTokens

func (v Validator) GetBondedTokens() sdk.Int

func (Validator) GetCommission

func (v Validator) GetCommission() sdk.Dec

func (Validator) GetConsAddr

func (v Validator) GetConsAddr() sdk.ConsAddress

func (Validator) GetConsPubKey

func (v Validator) GetConsPubKey() crypto.PubKey

func (Validator) GetDelegatorShares

func (v Validator) GetDelegatorShares() sdk.Dec

func (Validator) GetJailed

func (v Validator) GetJailed() bool

nolint - for sdk.Validator

func (Validator) GetMinSelfDelegation

func (v Validator) GetMinSelfDelegation() sdk.Int

func (Validator) GetMoniker

func (v Validator) GetMoniker() string

func (Validator) GetOperator

func (v Validator) GetOperator() sdk.ValAddress

func (Validator) GetStatus

func (v Validator) GetStatus() sdk.BondStatus

func (Validator) GetTendermintPower

func (v Validator) GetTendermintPower() int64

func (Validator) GetTokens

func (v Validator) GetTokens() sdk.Int

func (Validator) InvalidExRate

func (v Validator) InvalidExRate() bool

In some situations, the exchange rate becomes invalid, e.g. if Validator loses all tokens due to slashing. In this case, make all future delegations invalid. * 在某些情况下,更改被委托的钱以及占比是无效的, 如果 因为Validator由于削减而丢失所有令牌。 这种情况下,所有的委托将失效

func (Validator) MarshalJSON

func (v Validator) MarshalJSON() ([]byte, error)

MarshalJSON marshals the validator to JSON using Bech32

func (Validator) PotentialTendermintPower

func (v Validator) PotentialTendermintPower() int64

potential Tendermint power 根据验证人身上的token数量计算 该验证人的Tendermint 权重值

func (Validator) RemoveDelShares

func (v Validator) RemoveDelShares(pool Pool, delShares sdk.Dec) (Validator, Pool, sdk.Int)

RemoveDelShares removes delegator shares from a validator. NOTE: because token fractions are left in the valiadator,

the exchange rate of future shares of this validator can increase.

CONTRACT: Tokens are assumed to move to the not-bonded pool.

func (Validator) RemoveTokens

func (v Validator) RemoveTokens(pool Pool, tokens sdk.Int) (Validator, Pool)

removes tokens from a validator

func (Validator) SetInitialCommission

func (v Validator) SetInitialCommission(commission Commission) (Validator, sdk.Error)

SetInitialCommission attempts to set a validator's initial commission. An error is returned if the commission is invalid.

func (Validator) ShareTokens

func (v Validator) ShareTokens(shares sdk.Dec) sdk.Dec

calculate the token worth of provided shares 计算入参的数额的代币价值

func (Validator) ShareTokensTruncated

func (v Validator) ShareTokensTruncated(shares sdk.Dec) sdk.Dec

calculate the token worth of provided shares, truncated

func (Validator) String

func (v Validator) String() string

String returns a human readable string representation of a validator. 返回 验证人字符串形式

func (Validator) TendermintPower

func (v Validator) TendermintPower() int64

get the Tendermint Power a reduction of 10^6 from validator tokens is applied

func (Validator) TestEquivalent

func (v Validator) TestEquivalent(v2 Validator) bool

only the vitals

func (*Validator) UnmarshalJSON

func (v *Validator) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the validator from JSON using Bech32

func (Validator) UpdateStatus

func (v Validator) UpdateStatus(pool Pool, NewStatus sdk.BondStatus) (Validator, Pool)

UpdateStatus updates the location of the shares within a validator to reflect the new status

type Validators

type Validators []Validator

Validators is a collection of Validator * 验证人列表

func (Validators) String

func (v Validators) String() (out string)

func (Validators) ToSDKValidators

func (v Validators) ToSDKValidators() (validators []sdk.Validator)

ToSDKValidators - convenience function convert []Validators to []sdk.Validators ToSDKValidators - 方便函数将[] Validators转换为[] sdk.Validators 哎,不就是 struct 转成 interface{} 么

Jump to

Keyboard shortcuts

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