Documentation ¶
Overview ¶
nolint
Index ¶
- Constants
- Variables
- func AddrFromKey(key []byte) sdk.Address
- func ErrBadBondingAmount(codespace sdk.CodespaceType) sdk.Error
- func ErrBadBondingDenom(codespace sdk.CodespaceType) sdk.Error
- func ErrBadCandidateAddr(codespace sdk.CodespaceType) sdk.Error
- func ErrBadDelegatorAddr(codespace sdk.CodespaceType) sdk.Error
- func ErrBadRemoveValidator(codespace sdk.CodespaceType) sdk.Error
- func ErrBadShares(codespace sdk.CodespaceType) sdk.Error
- func ErrBadValidatorAddr(codespace sdk.CodespaceType) sdk.Error
- func ErrBondNotNominated(codespace sdk.CodespaceType) sdk.Error
- func ErrCandidateEmpty(codespace sdk.CodespaceType) sdk.Error
- func ErrCandidateExistsAddr(codespace sdk.CodespaceType) sdk.Error
- func ErrCandidateRevoked(codespace sdk.CodespaceType) sdk.Error
- func ErrCommissionHuge(codespace sdk.CodespaceType) sdk.Error
- func ErrCommissionNegative(codespace sdk.CodespaceType) sdk.Error
- func ErrInsufficientFunds(codespace sdk.CodespaceType) sdk.Error
- func ErrMissingSignature(codespace sdk.CodespaceType) sdk.Error
- func ErrNoBondingAcct(codespace sdk.CodespaceType) sdk.Error
- func ErrNoCandidateForAddress(codespace sdk.CodespaceType) sdk.Error
- func ErrNoDelegatorForAddress(codespace sdk.CodespaceType) sdk.Error
- func ErrNotEnoughBondShares(codespace sdk.CodespaceType, shares string) sdk.Error
- func FeeHandler(ctx sdk.Context, tx sdk.Tx, fee sdk.Coins)
- func GetAccUpdateValidatorKey(addr sdk.Address) []byte
- func GetCandidateKey(addr sdk.Address) []byte
- func GetDelegatorBondKey(delegatorAddr, candidateAddr sdk.Address, cdc *wire.Codec) []byte
- func GetDelegatorBondsKey(delegatorAddr sdk.Address, cdc *wire.Codec) []byte
- func GetRecentValidatorKey(addr sdk.Address) []byte
- func GetToKickOutValidatorKey(addr sdk.Address) []byte
- func GetValidatorKey(addr sdk.Address, power sdk.Rat, height int64, counter int16, cdc *wire.Codec) []byte
- func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState)
- func NewEndBlocker(k Keeper) sdk.EndBlocker
- func NewHandler(k Keeper) sdk.Handler
- func RegisterWire(cdc *wire.Codec)
- type Candidate
- type CandidateStatus
- type Candidates
- type CodeType
- type DelegatorBond
- type Description
- type GenesisState
- type Keeper
- func (k Keeper) GetCandidate(ctx sdk.Context, addr sdk.Address) (candidate Candidate, found bool)
- func (k Keeper) GetCandidates(ctx sdk.Context, maxRetrieve int16) (candidates Candidates)
- func (k Keeper) GetDelegatorBond(ctx sdk.Context, delegatorAddr, candidateAddr sdk.Address) (bond DelegatorBond, found bool)
- func (k Keeper) GetDelegatorBonds(ctx sdk.Context, delegator sdk.Address, maxRetrieve int16) (bonds []DelegatorBond)
- func (k Keeper) GetParams(ctx sdk.Context) (params Params)
- func (k Keeper) GetPool(ctx sdk.Context) (pool Pool)
- func (k Keeper) GetValidators(ctx sdk.Context) (validators []Validator)
- func (k Keeper) IsRecentValidator(ctx sdk.Context, address sdk.Address) bool
- func (k Keeper) Tick(ctx sdk.Context) (change []abci.Validator)
- type MsgDeclareCandidacy
- type MsgDelegate
- type MsgEditCandidacy
- type MsgUnbond
- type Params
- type Pool
- type Validator
- type ViewSlashKeeper
Constants ¶
const ( GasDeclareCandidacy int64 = 20 GasEditCandidacy int64 = 20 GasDelegate int64 = 20 GasUnbond int64 = 20 )
nolint
const MsgType = "stake"
name to idetify transaction types
const StakingToken = "steak"
XXX remove: think it makes more sense belonging with the Params so we can initialize at genesis - to allow for the same tests we should should make the ValidateBasic() function a return from an initializable function ValidateBasic(bondDenom string) function
Variables ¶
var ( // Keys for store prefixes ParamKey = []byte{0x00} // key for global parameters relating to staking PoolKey = []byte{0x01} // key for global parameters relating to staking CandidatesKey = []byte{0x02} // prefix for each key to a candidate ValidatorsKey = []byte{0x03} // prefix for each key to a validator AccUpdateValidatorsKey = []byte{0x04} // prefix for each key to a validator which is being updated RecentValidatorsKey = []byte{0x05} // prefix for each key to the last updated validator group ToKickOutValidatorsKey = []byte{0x06} // prefix for each key to the last updated validator group DelegatorBondKeyPrefix = []byte{0x07} // prefix for each key to a delegator's bond CounterKey = []byte{0x08} // key for block-local tx index )
nolint
Functions ¶
func AddrFromKey ¶
reverse operation of GetRecentValidatorKey
func ErrBadBondingAmount ¶
func ErrBadBondingAmount(codespace sdk.CodespaceType) sdk.Error
func ErrBadBondingDenom ¶
func ErrBadBondingDenom(codespace sdk.CodespaceType) sdk.Error
func ErrBadCandidateAddr ¶
func ErrBadCandidateAddr(codespace sdk.CodespaceType) sdk.Error
func ErrBadDelegatorAddr ¶
func ErrBadDelegatorAddr(codespace sdk.CodespaceType) sdk.Error
func ErrBadRemoveValidator ¶
func ErrBadRemoveValidator(codespace sdk.CodespaceType) sdk.Error
func ErrBadShares ¶
func ErrBadShares(codespace sdk.CodespaceType) sdk.Error
func ErrBadValidatorAddr ¶
func ErrBadValidatorAddr(codespace sdk.CodespaceType) sdk.Error
func ErrBondNotNominated ¶
func ErrBondNotNominated(codespace sdk.CodespaceType) sdk.Error
func ErrCandidateEmpty ¶
func ErrCandidateEmpty(codespace sdk.CodespaceType) sdk.Error
func ErrCandidateExistsAddr ¶
func ErrCandidateExistsAddr(codespace sdk.CodespaceType) sdk.Error
func ErrCandidateRevoked ¶
func ErrCandidateRevoked(codespace sdk.CodespaceType) sdk.Error
func ErrCommissionHuge ¶
func ErrCommissionHuge(codespace sdk.CodespaceType) sdk.Error
func ErrCommissionNegative ¶
func ErrCommissionNegative(codespace sdk.CodespaceType) sdk.Error
func ErrInsufficientFunds ¶
func ErrInsufficientFunds(codespace sdk.CodespaceType) sdk.Error
func ErrMissingSignature ¶
func ErrMissingSignature(codespace sdk.CodespaceType) sdk.Error
func ErrNoBondingAcct ¶
func ErrNoBondingAcct(codespace sdk.CodespaceType) sdk.Error
func ErrNoCandidateForAddress ¶
func ErrNoCandidateForAddress(codespace sdk.CodespaceType) sdk.Error
func ErrNoDelegatorForAddress ¶
func ErrNoDelegatorForAddress(codespace sdk.CodespaceType) sdk.Error
func ErrNotEnoughBondShares ¶
func ErrNotEnoughBondShares(codespace sdk.CodespaceType, shares string) sdk.Error
func FeeHandler ¶ added in v0.16.0
Handle fee distribution to the validators and delegators
func GetAccUpdateValidatorKey ¶
get the key for the accumulated update validators
func GetCandidateKey ¶
get the key for the candidate with address
func GetDelegatorBondKey ¶
get the key for delegator bond with candidate
func GetDelegatorBondsKey ¶
get the prefix for a delegator for all candidates
func GetRecentValidatorKey ¶
get the key for the accumulated update validators
func GetToKickOutValidatorKey ¶
get the key for the accumulated update validators
func GetValidatorKey ¶
func GetValidatorKey(addr sdk.Address, power sdk.Rat, height int64, counter int16, cdc *wire.Codec) []byte
get the key for the validator used in the power-store
func InitGenesis ¶ added in v0.16.0
func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState)
InitGenesis - store genesis parameters
func NewEndBlocker ¶
func NewEndBlocker(k Keeper) sdk.EndBlocker
NewEndBlocker generates sdk.EndBlocker Performs tick functionality
func NewHandler ¶
Types ¶
type Candidate ¶
type Candidate struct { Status CandidateStatus `json:"status"` // Bonded status Address sdk.Address `json:"owner"` // Sender of BondTx - UnbondTx returns here PubKey crypto.PubKey `json:"pub_key"` // Pubkey of candidate Assets sdk.Rat `json:"assets"` // total shares of a global hold pools Liabilities sdk.Rat `json:"liabilities"` // total shares issued to a candidate's delegators Description Description `json:"description"` // Description terms for the candidate ValidatorBondHeight int64 `json:"validator_bond_height"` // Earliest height as a bonded validator ValidatorBondCounter int16 `json:"validator_bond_counter"` // Block-local tx index of validator change }
Candidate defines the total amount of bond shares and their exchange rate to coins. Accumulation of interest is modelled as an in increase in the exchange rate, and slashing as a decrease. When coins are delegated to this candidate, the candidate is credited with a DelegatorBond 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 bonds multiplied by exchange rate.
func NewCandidate ¶
NewCandidate - initialize a new candidate
type CandidateStatus ¶
type CandidateStatus byte
CandidateStatus - status of a validator-candidate
const ( // nolint Bonded CandidateStatus = 0x00 Unbonded CandidateStatus = 0x01 Revoked CandidateStatus = 0x02 )
type CodeType ¶
const ( DefaultCodespace sdk.CodespaceType = 4 // Gaia errors reserve 200 ~ 299. CodeInvalidValidator CodeType = 201 CodeInvalidCandidate CodeType = 202 CodeInvalidBond CodeType = 203 CodeInvalidInput CodeType = 204 CodeInternal CodeType = sdk.CodeInternal CodeUnknownRequest CodeType = sdk.CodeUnknownRequest )
type DelegatorBond ¶
type DelegatorBond struct { DelegatorAddr sdk.Address `json:"delegator_addr"` CandidateAddr sdk.Address `json:"candidate_addr"` Height int64 `json:"height"` // Last height bond updated }
DelegatorBond represents the bond with tokens held by an account. It is owned by one delegator, and is associated with the voting power of one pubKey. TODO better way of managing space
type Description ¶
type Description struct { Moniker string `json:"moniker"` Identity string `json:"identity"` Website string `json:"website"` Details string `json:"details"` }
Description - description fields for a candidate
func NewDescription ¶
func NewDescription(moniker, identity, website, details string) Description
type GenesisState ¶
type GenesisState struct { Pool Pool `json:"pool"` Params Params `json:"params"` Candidates []Candidate `json:"candidates"` Bonds []DelegatorBond `json:"bonds"` }
GenesisState - all staking state that must be provided at genesis
func GetDefaultGenesisState ¶ added in v0.16.0
func GetDefaultGenesisState() GenesisState
get raw genesis raw message for testing
func WriteGenesis ¶ added in v0.16.0
func WriteGenesis(ctx sdk.Context, k Keeper) GenesisState
WriteGenesis - output genesis parameters
type Keeper ¶
type Keeper struct {
// contains filtered or unexported fields
}
keeper of the staking store
func (Keeper) GetCandidate ¶
get a single candidate
func (Keeper) GetCandidates ¶
func (k Keeper) GetCandidates(ctx sdk.Context, maxRetrieve int16) (candidates Candidates)
Get the set of all candidates, retrieve a maxRetrieve number of records
func (Keeper) GetDelegatorBond ¶ added in v0.16.0
func (k Keeper) GetDelegatorBond(ctx sdk.Context, delegatorAddr, candidateAddr sdk.Address) (bond DelegatorBond, found bool)
load a delegator bond
func (Keeper) GetDelegatorBonds ¶ added in v0.16.0
func (k Keeper) GetDelegatorBonds(ctx sdk.Context, delegator sdk.Address, maxRetrieve int16) (bonds []DelegatorBond)
load all bonds of a delegator
func (Keeper) GetValidators ¶
Get the validator set from the candidates. The correct subset is retrieved by iterating through an index of the candidates sorted by power, stored using the ValidatorsKey. Simultaniously the most recent the validator records are updated in store with the RecentValidatorsKey. This store is used to determine if a candidate is a validator without needing to iterate over the subspace as we do in GetValidators
func (Keeper) IsRecentValidator ¶
Is the address provided a part of the most recently saved validator group?
type MsgDeclareCandidacy ¶
type MsgDeclareCandidacy struct { Description CandidateAddr sdk.Address `json:"address"` PubKey crypto.PubKey `json:"pubkey"` Bond sdk.Coin `json:"bond"` }
MsgDeclareCandidacy - struct for unbonding transactions
func NewMsgDeclareCandidacy ¶
func NewMsgDeclareCandidacy(candidateAddr sdk.Address, pubkey crypto.PubKey, bond sdk.Coin, description Description) MsgDeclareCandidacy
func (MsgDeclareCandidacy) GetSignBytes ¶
func (msg MsgDeclareCandidacy) GetSignBytes() []byte
get the bytes for the message signer to sign on
func (MsgDeclareCandidacy) GetSigners ¶
func (msg MsgDeclareCandidacy) GetSigners() []sdk.Address
func (MsgDeclareCandidacy) ValidateBasic ¶
func (msg MsgDeclareCandidacy) ValidateBasic() sdk.Error
quick validity check
type MsgDelegate ¶
type MsgDelegate struct { DelegatorAddr sdk.Address `json:"address"` CandidateAddr sdk.Address `json:"address"` Bond sdk.Coin `json:"bond"` }
MsgDelegate - struct for bonding transactions
func NewMsgDelegate ¶
func NewMsgDelegate(delegatorAddr, candidateAddr sdk.Address, bond 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.Address
func (MsgDelegate) ValidateBasic ¶
func (msg MsgDelegate) ValidateBasic() sdk.Error
quick validity check
type MsgEditCandidacy ¶
type MsgEditCandidacy struct { Description CandidateAddr sdk.Address `json:"address"` }
MsgEditCandidacy - struct for editing a candidate
func NewMsgEditCandidacy ¶
func NewMsgEditCandidacy(candidateAddr sdk.Address, description Description) MsgEditCandidacy
func (MsgEditCandidacy) GetSignBytes ¶
func (msg MsgEditCandidacy) GetSignBytes() []byte
get the bytes for the message signer to sign on
func (MsgEditCandidacy) GetSigners ¶
func (msg MsgEditCandidacy) GetSigners() []sdk.Address
func (MsgEditCandidacy) ValidateBasic ¶
func (msg MsgEditCandidacy) ValidateBasic() sdk.Error
quick validity check
type MsgUnbond ¶
type MsgUnbond struct { DelegatorAddr sdk.Address `json:"address"` CandidateAddr sdk.Address `json:"address"` }
MsgUnbond - struct for unbonding transactions
func NewMsgUnbond ¶
func (MsgUnbond) GetSignBytes ¶
get the bytes for the message signer to sign on
func (MsgUnbond) GetSigners ¶
func (MsgUnbond) ValidateBasic ¶
quick validity check
type Params ¶
type Params struct { InflationRateChange sdk.Rat `json:"inflation_rate_change"` // maximum annual change in inflation rate InflationMax sdk.Rat `json:"inflation_max"` // maximum inflation rate InflationMin sdk.Rat `json:"inflation_min"` // minimum inflation rate GoalBonded sdk.Rat `json:"goal_bonded"` // Goal of percent bonded atoms MaxValidators uint16 `json:"max_validators"` // maximum number of validators BondDenom string `json:"bond_denom"` // bondable coin denomination }
Params defines the high level settings for staking
type Pool ¶
type Pool struct { TotalSupply int64 `json:"total_supply"` // total supply of all tokens BondedPool int64 `json:"bonded_pool"` // reserve of bonded tokens UnbondedPool int64 `json:"unbonded_pool"` // reserve of unbonded tokens held with candidates InflationLastTime int64 `json:"inflation_last_time"` // block which the last inflation was processed // TODO make time Inflation sdk.Rat `json:"inflation"` // current annual inflation rate }
Pool - dynamic parameters of the current state
type Validator ¶
type Validator struct { Address sdk.Address `json:"address"` PubKey crypto.PubKey `json:"pub_key"` Power sdk.Rat `json:"voting_power"` Height int64 `json:"height"` // Earliest height as a validator Counter int16 `json:"counter"` // Block-local tx index for resolving equal voting power & height }
Validator is one of the top Candidates
type ViewSlashKeeper ¶ added in v0.16.0
type ViewSlashKeeper struct {
// contains filtered or unexported fields
}
keeper to view information & slash validators will be used by governance module
func NewViewSlashKeeper ¶ added in v0.16.0
func NewViewSlashKeeper(k Keeper) ViewSlashKeeper
NewViewSlashKeeper creates a keeper restricted to viewing information & slashing validators
func (ViewSlashKeeper) GetDelegatorBond ¶ added in v0.16.0
func (v ViewSlashKeeper) GetDelegatorBond(ctx sdk.Context, delegatorAddr, candidateAddr sdk.Address) (bond DelegatorBond, found bool)
load a delegator bond
func (ViewSlashKeeper) GetDelegatorBonds ¶ added in v0.16.0
func (v ViewSlashKeeper) GetDelegatorBonds(ctx sdk.Context, delegator sdk.Address, maxRetrieve int16) (bonds []DelegatorBond)
load n delegator bonds