stake

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

nolint

Index

Constants

View Source
const (
	GasDeclareCandidacy int64 = 20
	GasEditCandidacy    int64 = 20
	GasDelegate         int64 = 20
	GasUnbond           int64 = 20
)

nolint

View Source
const MsgType = "stake"

name to idetify transaction types

View Source
const StakingToken = "fermion"

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

View Source
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
)

nolint

Functions

func AddrFromKey

func AddrFromKey(key []byte) sdk.Address

reverse operation of GetRecentValidatorKey

func ErrBadBondingAmount

func ErrBadBondingAmount() sdk.Error

func ErrBadBondingDenom

func ErrBadBondingDenom() sdk.Error

func ErrBadCandidateAddr

func ErrBadCandidateAddr() sdk.Error

func ErrBadDelegatorAddr

func ErrBadDelegatorAddr() sdk.Error

func ErrBadRemoveValidator

func ErrBadRemoveValidator() sdk.Error

func ErrBadShares

func ErrBadShares() sdk.Error

func ErrBadValidatorAddr

func ErrBadValidatorAddr() sdk.Error

func ErrBondNotNominated

func ErrBondNotNominated() sdk.Error

func ErrCandidateEmpty

func ErrCandidateEmpty() sdk.Error

func ErrCandidateExistsAddr

func ErrCandidateExistsAddr() sdk.Error

func ErrCandidateRevoked

func ErrCandidateRevoked() sdk.Error

func ErrCommissionHuge

func ErrCommissionHuge() sdk.Error

func ErrCommissionNegative

func ErrCommissionNegative() sdk.Error

func ErrInsufficientFunds

func ErrInsufficientFunds() sdk.Error

func ErrMissingSignature

func ErrMissingSignature() sdk.Error

func ErrNoBondingAcct

func ErrNoBondingAcct() sdk.Error

func ErrNoCandidateForAddress

func ErrNoCandidateForAddress() sdk.Error

func ErrNoDelegatorForAddress

func ErrNoDelegatorForAddress() sdk.Error

func ErrNotEnoughBondShares

func ErrNotEnoughBondShares(shares string) sdk.Error

func GetAccUpdateValidatorKey

func GetAccUpdateValidatorKey(addr sdk.Address) []byte

get the key for the accumulated update validators

func GetCandidateKey

func GetCandidateKey(addr sdk.Address) []byte

get the key for the candidate with address

func GetDelegatorBondKey

func GetDelegatorBondKey(delegatorAddr, candidateAddr sdk.Address, cdc *wire.Codec) []byte

get the key for delegator bond with candidate

func GetDelegatorBondsKey

func GetDelegatorBondsKey(delegatorAddr sdk.Address, cdc *wire.Codec) []byte

get the prefix for a delegator for all candidates

func GetRecentValidatorKey

func GetRecentValidatorKey(addr sdk.Address) []byte

get the key for the accumulated update validators

func GetToKickOutValidatorKey

func GetToKickOutValidatorKey(addr sdk.Address) []byte

get the key for the accumulated update validators

func GetValidatorKey

func GetValidatorKey(addr sdk.Address, power sdk.Rat, cdc *wire.Codec) []byte

get the key for the validator used in the power-store

func NewEndBlocker

func NewEndBlocker(k Keeper) sdk.EndBlocker

NewEndBlocker generates sdk.EndBlocker Performs tick functionality

func NewHandler

func NewHandler(k Keeper, ck bank.CoinKeeper) sdk.Handler

func RegisterWire

func RegisterWire(cdc *wire.Codec)

XXX complete

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
}

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

func NewCandidate(address sdk.Address, pubKey crypto.PubKey, description Description) Candidate

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 Candidates

type Candidates []Candidate

Candidates - list of Candidates

type CodeType

type CodeType = sdk.CodeType
const (
	// Gaia errors reserve 200 ~ 299.
	CodeInvalidValidator CodeType = 201
	CodeInvalidCandidate CodeType = 202
	CodeInvalidBond      CodeType = 203
	CodeInvalidInput     CodeType = 204
	CodeUnauthorized     CodeType = sdk.CodeUnauthorized
	CodeInternal         CodeType = sdk.CodeInternal
	CodeUnknownRequest   CodeType = sdk.CodeUnknownRequest
)

type DelegatorBond

type DelegatorBond struct {
	DelegatorAddr sdk.Address `json:"delegatoraddr"`
	CandidateAddr sdk.Address `json:"candidate_addr"`
	Shares        sdk.Rat     `json:"shares"`
}

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"`
}

GenesisState - all staking state that must be provided at genesis

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

keeper of the staking store

func NewKeeper

func NewKeeper(ctx sdk.Context, cdc *wire.Codec, key sdk.StoreKey, ck bank.CoinKeeper) Keeper

func (Keeper) GetCandidate

func (k Keeper) GetCandidate(ctx sdk.Context, addr sdk.Address) (candidate Candidate, found bool)

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) GetParams

func (k Keeper) GetParams(ctx sdk.Context) (params Params)

load/save the global staking params

func (Keeper) GetPool

func (k Keeper) GetPool(ctx sdk.Context) (gs Pool)

load/save the pool

func (Keeper) GetValidators

func (k Keeper) GetValidators(ctx sdk.Context) (validators []Validator)

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) InitGenesis

func (k Keeper) InitGenesis(ctx sdk.Context, data json.RawMessage) error

InitGenesis - store genesis parameters

func (Keeper) IsRecentValidator

func (k Keeper) IsRecentValidator(ctx sdk.Context, address sdk.Address) bool

Is the address provided a part of the most recently saved validator group?

func (Keeper) Tick

func (k Keeper) Tick(ctx sdk.Context) (change []abci.Validator)

Tick - called at the end of every block

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) Get

func (msg MsgDeclareCandidacy) Get(key interface{}) (value interface{})

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) String

func (msg MsgDeclareCandidacy) String() string

func (MsgDeclareCandidacy) Type

func (msg MsgDeclareCandidacy) Type() string

nolint

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) Get

func (msg MsgDelegate) Get(key interface{}) (value interface{})

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) String

func (msg MsgDelegate) String() string

func (MsgDelegate) Type

func (msg MsgDelegate) Type() string

nolint

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) Get

func (msg MsgEditCandidacy) Get(key interface{}) (value interface{})

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) String

func (msg MsgEditCandidacy) String() string

func (MsgEditCandidacy) Type

func (msg MsgEditCandidacy) Type() string

nolint

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"`
	Shares        string      `json:"shares"`
}

MsgUnbond - struct for unbonding transactions

func NewMsgUnbond

func NewMsgUnbond(delegatorAddr, candidateAddr sdk.Address, shares string) MsgUnbond

func (MsgUnbond) Get

func (msg MsgUnbond) Get(key interface{}) (value interface{})

func (MsgUnbond) GetSignBytes

func (msg MsgUnbond) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgUnbond) GetSigners

func (msg MsgUnbond) GetSigners() []sdk.Address

func (MsgUnbond) String

func (msg MsgUnbond) String() string

func (MsgUnbond) Type

func (msg MsgUnbond) Type() string

nolint

func (MsgUnbond) ValidateBasic

func (msg MsgUnbond) ValidateBasic() sdk.Error

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
	BondedShares      sdk.Rat `json:"bonded_shares"`       // sum of all shares distributed for the Bonded Pool
	UnbondedShares    sdk.Rat `json:"unbonded_shares"`     // sum of all shares distributed for the Unbonded Pool
	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"`
}

Validator is one of the top Candidates

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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