types

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTypeCompleteUnbonding = "complete_unbonding"
	EventTypeCreateValidator   = "create_validator"
	EventTypeEditValidator     = "edit_validator"
	EventTypeDelegate          = "delegate"
	EventTypeUnbond            = "unbond"

	AttributeKeyValidator      = "validator"
	AttributeKeyDelegator      = "delegator"
	AttributeKeyCompletionTime = "completion_time"
	AttributeValueCategory     = ModuleName
)

staking module event types

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

	// 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.Hour * 24 * 7 //devnet: time.Second * 60 * 5

	// Default maximum number of bonded validators
	DefaultMaxValidators uint16 = 30 //devnet: 5

	// Default maximum entries in a UBD/RED pair
	DefaultMaxEntries uint16 = 7

	// DefaultHistorical entries is 0 since it must only be non-zero for
	// IBC connected chains
	DefaultHistoricalEntries uint16 = 0
)

Staking params default values

View Source
const (
	NotBondedPoolName = "not_bonded_tokens_pool"
	BondedPoolName    = "bonded_tokens_pool"
)

names used as root for pool module accounts:

- NotBondedPool -> "not_bonded_tokens_pool"

- BondedPool -> "bonded_tokens_pool"

View Source
const (
	QueryValidators                    = "validators"
	QueryValidator                     = "validator"
	QueryDelegatorDelegations          = "delegatorDelegations"
	QueryDelegatorUnbondingDelegations = "delegatorUnbondingDelegations"
	QueryValidatorDelegations          = "validatorDelegations"
	QueryValidatorUnbondingDelegations = "validatorUnbondingDelegations"
	QueryDelegation                    = "delegation"
	QueryUnbondingDelegation           = "unbondingDelegation"
	QueryDelegatorValidators           = "delegatorValidators"
	QueryDelegatorValidator            = "delegatorValidator"
	QueryPool                          = "pool"
	QueryParameters                    = "parameters"
	QueryHistoricalInfo                = "historicalInfo"
)

query endpoints supported by the staking Querier

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
	MaxSecurityContactLength = 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 (
	ErrEmptyValidatorAddr              = sdkerrors.Register(ModuleName, 1, "empty validator address")
	ErrBadValidatorAddr                = sdkerrors.Register(ModuleName, 2, "validator address is invalid")
	ErrNoValidatorFound                = sdkerrors.Register(ModuleName, 3, "validator does not exist")
	ErrValidatorOwnerExists            = sdkerrors.Register(ModuleName, 4, "validator already exist for this operator address; must use new validator operator address")
	ErrValidatorPubKeyExists           = sdkerrors.Register(ModuleName, 5, "validator already exist for this pubkey; must use new validator pubkey")
	ErrValidatorPubKeyTypeNotSupported = sdkerrors.Register(ModuleName, 6, "validator pubkey type is not supported")
	ErrValidatorJailed                 = sdkerrors.Register(ModuleName, 7, "validator for this address is currently jailed")
	ErrBadRemoveValidator              = sdkerrors.Register(ModuleName, 8, "failed to remove validator")
	ErrSelfDelegationBelowMinimum      = sdkerrors.Register(ModuleName, 16, "validator's self delegation must be greater than their minimum self delegation")
	ErrMinSelfDelegationInvalid        = sdkerrors.Register(ModuleName, 17, "minimum self delegation must be a positive integer")
	ErrMinSelfDelegationDecreased      = sdkerrors.Register(ModuleName, 18, "minimum self delegation cannot be decrease")
	ErrEmptyDelegatorAddr              = sdkerrors.Register(ModuleName, 19, "empty delegator address")
	ErrBadDenom                        = sdkerrors.Register(ModuleName, 20, "invalid coin denomination")
	ErrBadDelegationAddr               = sdkerrors.Register(ModuleName, 21, "invalid address for (address, validator) tuple")
	ErrBadDelegationAmount             = sdkerrors.Register(ModuleName, 22, "invalid delegation amount")
	ErrNoDelegation                    = sdkerrors.Register(ModuleName, 23, "no delegation for (address, validator) tuple")
	ErrBadDelegatorAddr                = sdkerrors.Register(ModuleName, 24, "delegator does not exist with address")
	ErrNoDelegatorForAddress           = sdkerrors.Register(ModuleName, 25, "delegator does not contain delegation")
	ErrInsufficientShares              = sdkerrors.Register(ModuleName, 26, "insufficient delegation shares")
	ErrDelegationValidatorEmpty        = sdkerrors.Register(ModuleName, 27, "cannot delegate to an empty validator")
	ErrNotEnoughDelegationShares       = sdkerrors.Register(ModuleName, 28, "not enough delegation shares")
	ErrBadSharesAmount                 = sdkerrors.Register(ModuleName, 29, "invalid shares amount")
	ErrBadSharesPercent                = sdkerrors.Register(ModuleName, 30, "Invalid shares percent")
	ErrNotMature                       = sdkerrors.Register(ModuleName, 31, "entry not mature")
	ErrNoUnbondingDelegation           = sdkerrors.Register(ModuleName, 32, "no unbonding delegation found")
	ErrMaxUnbondingDelegationEntries   = sdkerrors.Register(ModuleName, 33, "too many unbonding delegation entries for (delegator, validator) tuple")
	ErrDelegatorShareExRateInvalid     = sdkerrors.Register(ModuleName, 41, "cannot delegate to validators with invalid (zero) ex-rate")
	ErrBothShareMsgsGiven              = sdkerrors.Register(ModuleName, 42, "both shares amount and shares percent provided")
	ErrNeitherShareMsgsGiven           = sdkerrors.Register(ModuleName, 43, "neither shares amount nor shares percent provided")
	ErrInvalidHistoricalInfo           = sdkerrors.Register(ModuleName, 44, "invalid historical info")
	ErrNoHistoricalInfo                = sdkerrors.Register(ModuleName, 45, "no historical info found")
	ErrInvalidGenesis                  = sdkerrors.Register(ModuleName, 46, "invalid genesis state")
)

x/staking module sentinel errors

TODO: Many of these errors are redundant. They should be removed and replaced by sdkerrors.ErrInvalidRequest.

REF: https://github.com/cosmos/cosmos-sdk/issues/5450

View Source
var (
	// Keys for store prefixes
	// Last* values are constant during a block.
	LastValidatorPowerKey = []byte{0x11} // prefix for each key to a validator index, for bonded validators
	LastTotalPowerKey     = []byte{0x12} // prefix for the total power

	ValidatorsKey             = []byte{0x21} // prefix for each key to a validator
	ValidatorsByConsAddrKey   = []byte{0x22} // prefix for each key to a validator index, by pubkey
	ValidatorsByPowerIndexKey = []byte{0x23} // prefix for each key to a validator index, sorted by power
	ValidatorsByTicketKey     = []byte{0x24}

	DelegationKey                    = []byte{0x31} // key for a delegation
	UnbondingDelegationKey           = []byte{0x32} // key for an unbonding-delegation
	UnbondingDelegationByValIndexKey = []byte{0x33} // prefix for each key for an unbonding-delegation, by validator operator

	UnbondingQueueKey = []byte{0x41} // prefix for the timestamps in unbonding queue
	ValidatorQueueKey = []byte{0x43} // prefix for the timestamps in validator queue

	HistoricalInfoKey = []byte{0x50} // prefix for the historical info

	TicketKey = []byte{0x60}
)

nolint

View Source
var (
	KeyUnbondingTime     = []byte("UnbondingTime")
	KeyMaxValidators     = []byte("MaxValidators")
	KeyMaxEntries        = []byte("KeyMaxEntries")
	KeyBondDenom         = []byte("BondDenom")
	KeyHistoricalEntries = []byte("HistoricalEntries")

	DefaultStake, _ = sdk.NewIntFromString("50000000000000") // This line is the default staking requirement for a validator  10,000,000,000,000 pin = 100k Anatha
)

nolint - Keys for parameter access

View Source
var ModuleCdc *codec.Codec

generic sealed codec to be used throughout this module

Functions

func AddressFromLastValidatorPowerKey

func AddressFromLastValidatorPowerKey(key []byte) []byte

Get the validator operator address from LastValidatorPowerKey

func GetDelegationKey

func GetDelegationKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte

gets the key for delegator bond with validator VALUE: staking/Delegation

func GetDelegationsKey

func GetDelegationsKey(delAddr sdk.AccAddress) []byte

gets the prefix for a delegator for all validators

func GetHistoricalInfoKey

func GetHistoricalInfoKey(height int64) []byte

GetHistoricalInfoKey gets the key for the historical info

func GetLastValidatorPowerKey

func GetLastValidatorPowerKey(operator sdk.ValAddress) []byte

get the bonded validator index key for an operator address

func GetTicketBytes

func GetTicketBytes(ticket uint64) (ticketBz []byte)

func GetTicketFromBytes

func GetTicketFromBytes(bz []byte) (ticket uint64)

func GetUBDByValIndexKey

func GetUBDByValIndexKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte

gets the index-key for an unbonding delegation, stored by validator-index VALUE: none (key rearrangement used)

func GetUBDKey

func GetUBDKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte

gets the key for an unbonding delegation by delegator and validator addr VALUE: staking/UnbondingDelegation

func GetUBDKeyFromValIndexKey

func GetUBDKeyFromValIndexKey(indexKey []byte) []byte

rearranges the ValIndexKey to get the UBDKey

func GetUBDsByValIndexKey

func GetUBDsByValIndexKey(valAddr sdk.ValAddress) []byte

gets the prefix keyspace for the indexes of unbonding delegations for a validator

func GetUBDsKey

func GetUBDsKey(delAddr sdk.AccAddress) []byte

gets the prefix for all unbonding delegations from a delegator

func GetUnbondingDelegationTimeKey

func GetUnbondingDelegationTimeKey(timestamp time.Time) []byte

gets the prefix for all unbonding delegations from a delegator

func GetValidatorByConsAddrKey

func GetValidatorByConsAddrKey(addr sdk.ConsAddress) []byte

gets the key for the validator with pubkey VALUE: validator operator address ([]byte)

func GetValidatorKey

func GetValidatorKey(operatorAddr sdk.ValAddress) []byte

gets the key for the validator with address VALUE: staking/Validator

func GetValidatorQueueTimeKey

func GetValidatorQueueTimeKey(timestamp time.Time) []byte

gets the prefix for all unbonding delegations from a delegator

func GetValidatorsByPowerIndexKey

func GetValidatorsByPowerIndexKey(validator Validator) []byte

get the validator by power index. Power index is the key used in the power-store, and represents the relative power ranking of the validator. VALUE: validator operator address ([]byte)

func GetValidatorsByTicketKey

func GetValidatorsByTicketKey(validator Validator) []byte

func MustMarshalDelegation

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

MustMarshalDelegation returns the delegation bytes. Panics if fails

func MustMarshalHistoricalInfo

func MustMarshalHistoricalInfo(cdc *codec.Codec, hi HistoricalInfo) []byte

MustMarshalHistoricalInfo wll marshal historical info and panic on error

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 validator

func ParseValidatorPowerRankKey

func ParseValidatorPowerRankKey(key []byte) (operAddr []byte)

parse the validators operator address from power rank key

func ParseValidatorTicketKey

func ParseValidatorTicketKey(key []byte) (ticket uint64, operAddr []byte)

parse the validators operator address from ticket rank key

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

Register concrete types on codec codec

func ValidateBasic

func ValidateBasic(hi HistoricalInfo) error

ValidateBasic will ensure HistoricalInfo is not nil and sorted

Types

type AccountKeeper

type AccountKeeper interface {
	IterateAccounts(ctx sdk.Context, process func(authexported.Account) (stop bool))
	GetAccount(ctx sdk.Context, addr sdk.AccAddress) authexported.Account // only used for simulation
}

AccountKeeper defines the expected account keeper (noalias)

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.

type Delegation

type Delegation struct {
	DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
	ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
	Shares           sdk.Dec        `json:"shares" yaml:"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

MustUnmarshalDelegation return the unmarshaled delegation from bytes. Panics if fails.

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 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 DelegationResponse

type DelegationResponse struct {
	Delegation
	Balance sdk.Coin `json:"balance" yaml:"balance"`
}

DelegationResponse is equivalent to Delegation except that it contains a balance in addition to shares which is more suitable for client responses.

func NewDelegationResp

func NewDelegationResp(
	delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress, shares sdk.Dec, balance sdk.Coin,
) DelegationResponse

NewDelegationResp creates a new DelegationResponse instance

func (DelegationResponse) MarshalJSON

func (d DelegationResponse) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. This is so we can achieve a flattened structure while embedding other types.

func (DelegationResponse) String

func (d DelegationResponse) String() string

String implements the Stringer interface for DelegationResponse.

func (*DelegationResponse) UnmarshalJSON

func (d *DelegationResponse) UnmarshalJSON(bz []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. This is so we can achieve a flattened structure while embedding other types.

type DelegationResponses

type DelegationResponses []DelegationResponse

DelegationResponses is a collection of DelegationResp

func (DelegationResponses) String

func (d DelegationResponses) String() (out string)

String implements the Stringer interface for DelegationResponses.

type DelegationSet

type DelegationSet interface {
	GetValidatorSet() ValidatorSet // validator set for which delegation set is based upon

	// iterate through all delegations from one delegator by validator-AccAddress,
	//   execute func for each validator
	IterateDelegations(ctx sdk.Context, delegator sdk.AccAddress,
		fn func(index int64, delegation stakingexported.DelegationI) (stop bool))
}

DelegationSet expected properties for the set of all delegations for a particular (noalias)

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" yaml:"moniker"`                   // name
	Identity        string `json:"identity" yaml:"identity"`                 // optional identity signature (ex. UPort or Keybase)
	Website         string `json:"website" yaml:"website"`                   // optional website link
	SecurityContact string `json:"security_contact" yaml:"security_contact"` // optional security contact info
	Details         string `json:"details" yaml:"details"`                   // optional details
}

Description - description fields for a validator

func NewDescription

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

NewDescription returns a new Description with the provided values.

func (Description) EnsureLength

func (d Description) EnsureLength() (Description, error)

EnsureLength ensures the length of a validator's description.

func (Description) UpdateDescription

func (d Description) UpdateDescription(d2 Description) (Description, 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
}

DistributionKeeper expected distribution keeper (noalias)

type GenesisState

type GenesisState struct {
	Params               Params                `json:"params" yaml:"params"`
	LastTotalPower       sdk.Int               `json:"last_total_power" yaml:"last_total_power"`
	LastValidatorPowers  []LastValidatorPower  `json:"last_validator_powers" yaml:"last_validator_powers"`
	Validators           Validators            `json:"validators" yaml:"validators"`
	Delegations          Delegations           `json:"delegations" yaml:"delegations"`
	UnbondingDelegations []UnbondingDelegation `json:"unbonding_delegations" yaml:"unbonding_delegations"`
	Exported             bool                  `json:"exported" yaml:"exported"`
	StartingTicket       uint64                `json:"starting_ticket" yaml:"starting_ticket"`
}

GenesisState - all staking state that must be provided at genesis

func DefaultGenesisState

func DefaultGenesisState() GenesisState

DefaultGenesisState gets the raw genesis raw message for testing

func NewGenesisState

func NewGenesisState(params Params, validators []Validator, delegations []Delegation, startingTicket uint64) GenesisState

NewGenesisState creates a new GenesisState instanc e

type HistoricalInfo

type HistoricalInfo struct {
	Header abci.Header `json:"header" yaml:"header"`
	ValSet []Validator `json:"valset" yaml:"valset"`
}

HistoricalInfo contains the historical information that gets stored at each height

func MustUnmarshalHistoricalInfo

func MustUnmarshalHistoricalInfo(cdc *codec.Codec, value []byte) HistoricalInfo

MustUnmarshalHistoricalInfo wll unmarshal historical info and panic on error

func NewHistoricalInfo

func NewHistoricalInfo(header abci.Header, valSet []Validator) HistoricalInfo

NewHistoricalInfo will create a historical information struct from header and valset it will first sort valset before inclusion into historical info

func UnmarshalHistoricalInfo

func UnmarshalHistoricalInfo(cdc *codec.Codec, value []byte) (hi HistoricalInfo, err error)

UnmarshalHistoricalInfo will unmarshal historical info and return any error

type LastValidatorPower

type LastValidatorPower struct {
	Address sdk.ValAddress
	Power   int64
}

LastValidatorPower required for validator set update logic

type MsgCreateValidator

type MsgCreateValidator struct {
	Description      Description    `json:"description" yaml:"description"`
	DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
	ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
	PubKey           crypto.PubKey  `json:"pubkey" yaml:"pubkey"`
	Value            sdk.Coin       `json:"value" yaml:"value"`
}

MsgCreateValidator - struct for bonding transactions

func NewMsgCreateValidator

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

NewMsgCreateValidator creates a new MsgCreateValidator instance. 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

GetSigners implements the sdk.Msg interface. It returns the address(es) that must sign over msg.GetSignBytes(). If the validator address is not same as delegator's, then the validator must sign the msg as well.

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

func (msg MsgCreateValidator) MarshalYAML() (interface{}, error)

MarshalYAML implements a custom marshal yaml function due to consensus pubkey.

func (MsgCreateValidator) Route

func (msg MsgCreateValidator) Route() string

Route implements the sdk.Msg interface.

func (MsgCreateValidator) Type

func (msg MsgCreateValidator) Type() string

Type implements the sdk.Msg interface.

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() error

ValidateBasic implements the sdk.Msg interface.

type MsgDelegate

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

MsgDelegate - struct for bonding transactions

func NewMsgDelegate

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

NewMsgDelegate creates a new MsgDelegate instance.

func (MsgDelegate) GetSignBytes

func (msg MsgDelegate) GetSignBytes() []byte

GetSignBytes implements the sdk.Msg interface.

func (MsgDelegate) GetSigners

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

GetSigners implements the sdk.Msg interface.

func (MsgDelegate) Route

func (msg MsgDelegate) Route() string

Route implements the sdk.Msg interface.

func (MsgDelegate) Type

func (msg MsgDelegate) Type() string

Type implements the sdk.Msg interface.

func (MsgDelegate) ValidateBasic

func (msg MsgDelegate) ValidateBasic() error

ValidateBasic implements the sdk.Msg interface.

type MsgEditValidator

type MsgEditValidator struct {
	Description      Description    `json:"description" yaml:"description"`
	ValidatorAddress sdk.ValAddress `json:"address" yaml:"address"`
}

MsgEditValidator - struct for editing a validator

func NewMsgEditValidator

func NewMsgEditValidator(valAddr sdk.ValAddress, description Description) MsgEditValidator

NewMsgEditValidator creates a new MsgEditValidator instance

func (MsgEditValidator) GetSignBytes

func (msg MsgEditValidator) GetSignBytes() []byte

GetSignBytes implements the sdk.Msg interface.

func (MsgEditValidator) GetSigners

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

GetSigners implements the sdk.Msg interface.

func (MsgEditValidator) Route

func (msg MsgEditValidator) Route() string

Route implements the sdk.Msg interface.

func (MsgEditValidator) Type

func (msg MsgEditValidator) Type() string

Type implements the sdk.Msg interface.

func (MsgEditValidator) ValidateBasic

func (msg MsgEditValidator) ValidateBasic() error

ValidateBasic implements the sdk.Msg interface.

type MsgUndelegate

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

MsgUndelegate - struct for unbonding transactions

func NewMsgUndelegate

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

NewMsgUndelegate creates a new MsgUndelegate instance.

func (MsgUndelegate) GetSignBytes

func (msg MsgUndelegate) GetSignBytes() []byte

GetSignBytes implements the sdk.Msg interface.

func (MsgUndelegate) GetSigners

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

GetSigners implements the sdk.Msg interface.

func (MsgUndelegate) Route

func (msg MsgUndelegate) Route() string

Route implements the sdk.Msg interface.

func (MsgUndelegate) Type

func (msg MsgUndelegate) Type() string

Type implements the sdk.Msg interface.

func (MsgUndelegate) ValidateBasic

func (msg MsgUndelegate) ValidateBasic() error

ValidateBasic implements the sdk.Msg interface.

type MultiStakingHooks

type MultiStakingHooks []StakingHooks

combine multiple staking hooks, all hook functions are run in array sequence

func NewMultiStakingHooks

func NewMultiStakingHooks(hooks ...StakingHooks) MultiStakingHooks

func (MultiStakingHooks) AfterDelegationModified

func (h MultiStakingHooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress)

func (MultiStakingHooks) AfterValidatorBeginUnbonding

func (h MultiStakingHooks) AfterValidatorBeginUnbonding(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)

func (MultiStakingHooks) AfterValidatorBonded

func (h MultiStakingHooks) AfterValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)

func (MultiStakingHooks) AfterValidatorCreated

func (h MultiStakingHooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress)

nolint

func (MultiStakingHooks) AfterValidatorRemoved

func (h MultiStakingHooks) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)

func (MultiStakingHooks) BeforeDelegationCreated

func (h MultiStakingHooks) BeforeDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress)

func (MultiStakingHooks) BeforeDelegationRemoved

func (h MultiStakingHooks) BeforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress)

func (MultiStakingHooks) BeforeDelegationSharesModified

func (h MultiStakingHooks) BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress)

func (MultiStakingHooks) BeforeValidatorModified

func (h MultiStakingHooks) BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress)

func (MultiStakingHooks) BeforeValidatorSlashed

func (h MultiStakingHooks) BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, fraction sdk.Dec)

type Params

type Params struct {
	UnbondingTime     time.Duration `json:"unbonding_time" yaml:"unbonding_time"`         // time duration of unbonding
	MaxValidators     uint16        `json:"max_validators" yaml:"max_validators"`         // maximum number of validators (max uint16 = 65535)
	MaxEntries        uint16        `json:"max_entries" yaml:"max_entries"`               // max entries for either unbonding delegation or redelegation (per pair/trio)
	HistoricalEntries uint16        `json:"historical_entries" yaml:"historical_entries"` // number of historical entries to persist
	BondDenom         string        `json:"bond_denom" yaml:"bond_denom"`                 // bondable coin denomination
}

Params defines the high level settings for staking

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, historicalEntries uint16,
	bondDenom string) Params

NewParams creates a new Params instance

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 {
	NotBondedTokens sdk.Int `json:"not_bonded_tokens" yaml:"not_bonded_tokens"` // tokens which are not bonded to a validator (unbonded or unbonding)
	BondedTokens    sdk.Int `json:"bonded_tokens" yaml:"bonded_tokens"`         // tokens which are currently bonded to a validator
}

Pool - tracking bonded and not-bonded token supply of the bond denomination

func NewPool

func NewPool(notBonded, bonded sdk.Int) Pool

NewPool creates a new Pool instance used for queries

func (Pool) String

func (p Pool) String() string

String returns a human readable string representation of a pool.

type QueryBondsParams

type QueryBondsParams struct {
	DelegatorAddr sdk.AccAddress
	ValidatorAddr sdk.ValAddress
}

defines the params for the following queries: - 'custom/staking/delegation' - 'custom/staking/unbondingDelegation' - 'custom/staking/delegatorValidator'

func NewQueryBondsParams

func NewQueryBondsParams(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) QueryBondsParams

type QueryDelegatorParams

type QueryDelegatorParams struct {
	DelegatorAddr sdk.AccAddress
}

defines the params for the following queries: - 'custom/staking/delegatorDelegations' - 'custom/staking/delegatorUnbondingDelegations' - 'custom/staking/delegatorValidators'

func NewQueryDelegatorParams

func NewQueryDelegatorParams(delegatorAddr sdk.AccAddress) QueryDelegatorParams

type QueryHistoricalInfoParams

type QueryHistoricalInfoParams struct {
	Height int64
}

QueryHistoricalInfoParams defines the params for the following queries: - 'custom/staking/historicalInfo'

func NewQueryHistoricalInfoParams

func NewQueryHistoricalInfoParams(height int64) QueryHistoricalInfoParams

NewQueryHistoricalInfoParams creates a new QueryHistoricalInfoParams instance

type QueryValidatorParams

type QueryValidatorParams struct {
	ValidatorAddr sdk.ValAddress
}

defines the params for the following queries: - 'custom/staking/validator' - 'custom/staking/validatorDelegations' - 'custom/staking/validatorUnbondingDelegations'

func NewQueryValidatorParams

func NewQueryValidatorParams(validatorAddr sdk.ValAddress) QueryValidatorParams

type QueryValidatorsParams

type QueryValidatorsParams struct {
	Page, Limit int
	Status      string
}

QueryValidatorsParams defines the params for the following queries: - 'custom/staking/validators'

func NewQueryValidatorsParams

func NewQueryValidatorsParams(page, limit int, status string) QueryValidatorsParams

type StakingHooks

type StakingHooks interface {
	AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress)                           // Must be called when a validator is created
	BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress)                         // Must be called when a validator's state changes
	AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) // Must be called when a validator is deleted

	AfterValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)         // Must be called when a validator is bonded
	AfterValidatorBeginUnbonding(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) // Must be called when a validator begins unbonding

	BeforeDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress)        // Must be called when a delegation is created
	BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) // Must be called when a delegation's shares are modified
	BeforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress)        // Must be called when a delegation is removed
	AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress)
	BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, fraction sdk.Dec)
}

StakingHooks event hooks for staking validator object (noalias)

type SupplyKeeper

type SupplyKeeper interface {
	GetSupply(ctx sdk.Context) supplyexported.SupplyI

	GetModuleAddress(name string) sdk.AccAddress
	GetModuleAccount(ctx sdk.Context, moduleName string) supplyexported.ModuleAccountI

	// TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862
	SetModuleAccount(sdk.Context, supplyexported.ModuleAccountI)

	SendCoinsFromModuleToModule(ctx sdk.Context, senderPool, recipientPool string, amt sdk.Coins) error
	UndelegateCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
	DelegateCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error

	BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error
}

SupplyKeeper defines the expected supply Keeper (noalias)

type UnbondingDelegation

type UnbondingDelegation struct {
	DelegatorAddress sdk.AccAddress             `json:"delegator_address" yaml:"delegator_address"` // delegator
	ValidatorAddress sdk.ValAddress             `json:"validator_address" yaml:"validator_address"` // validator unbonding from operator addr
	Entries          []UnbondingDelegationEntry `json:"entries" yaml:"entries"`                     // unbonding delegation entries
}

UnbondingDelegation stores all of a single delegator's unbonding bonds for a single validator in an time-ordered list

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" yaml:"creation_height"` // height which the unbonding took place
	CompletionTime time.Time `json:"completion_time" yaml:"completion_time"` // time at which the unbonding delegation will complete
	InitialBalance sdk.Int   `json:"initial_balance" yaml:"initial_balance"` // atoms initially scheduled to receive at completion
	Balance        sdk.Int   `json:"balance" yaml:"balance"`                 // atoms to receive at completion
}

UnbondingDelegationEntry - entry to an UnbondingDelegation

func NewUnbondingDelegationEntry

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

NewUnbondingDelegationEntry - create a new unbonding delegation object

func (UnbondingDelegationEntry) IsMature

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

IsMature - is the current entry mature

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 {
	OperatorAddress         sdk.ValAddress `json:"operator_address" yaml:"operator_address"`       // address of the validator's operator; bech encoded in JSON
	ConsPubKey              crypto.PubKey  `json:"consensus_pubkey" yaml:"consensus_pubkey"`       // the consensus public key of the validator; bech encoded in JSON
	Jailed                  bool           `json:"jailed" yaml:"jailed"`                           // has the validator been jailed from bonded status?
	Status                  sdk.BondStatus `json:"status" yaml:"status"`                           // validator status (bonded/unbonding/unbonded)
	Tokens                  sdk.Int        `json:"tokens" yaml:"tokens"`                           // delegated tokens (incl. self-delegation)
	DelegatorShares         sdk.Dec        `json:"delegator_shares" yaml:"delegator_shares"`       // total shares issued to a validator's delegators
	Description             Description    `json:"description" yaml:"description"`                 // description terms for the validator
	UnbondingHeight         int64          `json:"unbonding_height" yaml:"unbonding_height"`       // if unbonding, height at which this validator has begun unbonding
	UnbondingCompletionTime time.Time      `json:"unbonding_time" yaml:"unbonding_time"`           // if unbonding, min time for the validator to complete unbonding
	MinSelfDelegation       sdk.Int        `json:"min_self_delegation" yaml:"min_self_delegation"` // validator's self declared minimum self delegation
	Ticket                  uint64         `json:"ticket" yaml:"ticket"`
}

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.

func MustUnmarshalValidator

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

unmarshal a validator 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 validator 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

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(amount sdk.Int) (Validator, sdk.Dec)

AddTokensFromDel adds tokens to a validator

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

func (v Validator) ConsensusPower() int64

get the consensus-engine power a reduction of 10^6 from validator tokens is applied

func (Validator) GetBondedTokens

func (v Validator) GetBondedTokens() sdk.Int

func (Validator) GetConsAddr

func (v Validator) GetConsAddr() sdk.ConsAddress

func (Validator) GetConsPubKey

func (v Validator) GetConsPubKey() crypto.PubKey

func (Validator) GetConsensusPower

func (v Validator) GetConsensusPower() int64

func (Validator) GetDelegatorShares

func (v Validator) GetDelegatorShares() sdk.Dec

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

func (v Validator) GetTicket() uint64

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.

func (Validator) IsBonded

func (v Validator) IsBonded() bool

IsBonded checks if the validator status equals Bonded

func (Validator) IsJailed

func (v Validator) IsJailed() bool

nolint - for ValidatorI

func (Validator) IsUnbonded

func (v Validator) IsUnbonded() bool

IsUnbonded checks if the validator status equals Unbonded

func (Validator) IsUnbonding

func (v Validator) IsUnbonding() bool

IsUnbonding checks if the validator status equals Unbonding

func (Validator) MarshalJSON

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

MarshalJSON marshals the validator to JSON using Bech32

func (Validator) MarshalYAML

func (v Validator) MarshalYAML() (interface{}, error)

custom marshal yaml function due to consensus pubkey

func (Validator) PotentialConsensusPower

func (v Validator) PotentialConsensusPower() int64

potential consensus-engine power

func (Validator) RemoveDelShares

func (v Validator) RemoveDelShares(delShares sdk.Dec) (Validator, 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.

func (Validator) RemoveTokens

func (v Validator) RemoveTokens(tokens sdk.Int) Validator

RemoveTokens removes tokens from a validator

func (Validator) SharesFromTokens

func (v Validator) SharesFromTokens(amt sdk.Int) (sdk.Dec, error)

SharesFromTokens returns the shares of a delegation given a bond amount. It returns an error if the validator has no tokens.

func (Validator) SharesFromTokensTruncated

func (v Validator) SharesFromTokensTruncated(amt sdk.Int) (sdk.Dec, error)

SharesFromTokensTruncated returns the truncated shares of a delegation given a bond amount. It returns an error if the validator has no tokens.

func (Validator) String

func (v Validator) String() string

String returns a human readable string representation of a validator.

func (Validator) TestEquivalent

func (v Validator) TestEquivalent(v2 Validator) bool

only the vitals

func (Validator) TokensFromShares

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

calculate the token worth of provided shares

func (Validator) TokensFromSharesRoundUp

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

TokensFromSharesRoundUp returns the token worth of provided shares, rounded up.

func (Validator) TokensFromSharesTruncated

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

calculate the token worth of provided shares, truncated

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(newStatus sdk.BondStatus) Validator

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

type ValidatorSet

type ValidatorSet interface {
	// iterate through validators by operator address, execute func for each validator
	IterateValidators(sdk.Context,
		func(index int64, validator stakingexported.ValidatorI) (stop bool))

	// iterate through bonded validators by operator address, execute func for each validator
	IterateBondedValidatorsByPower(sdk.Context,
		func(index int64, validator stakingexported.ValidatorI) (stop bool))

	// iterate through the consensus validator set of the last block by operator address, execute func for each validator
	IterateLastValidators(sdk.Context,
		func(index int64, validator stakingexported.ValidatorI) (stop bool))

	Validator(sdk.Context, sdk.ValAddress) stakingexported.ValidatorI            // get a particular validator by operator address
	ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingexported.ValidatorI // get a particular validator by consensus address
	TotalBondedTokens(sdk.Context) sdk.Int                                       // total bonded tokens within the validator set
	StakingTokenSupply(sdk.Context) sdk.Int                                      // total staking token supply

	// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
	Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec)
	Jail(sdk.Context, sdk.ConsAddress)   // jail a validator
	Unjail(sdk.Context, sdk.ConsAddress) // unjail a validator

	// Delegation allows for getting a particular delegation for a given validator
	// and delegator outside the scope of the staking module.
	Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingexported.DelegationI

	// MaxValidators returns the maximum amount of bonded validators
	MaxValidators(sdk.Context) uint16
}

ValidatorSet expected properties for the set of all validators (noalias)

type Validators

type Validators []Validator

Validators is a collection of Validator

func (Validators) Len

func (v Validators) Len() int

Implements sort interface

func (Validators) Less

func (v Validators) Less(i, j int) bool

Implements sort interface

func (Validators) Sort

func (v Validators) Sort()

Sort Validators sorts validator array in ascending operator address order

func (Validators) String

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

func (Validators) Swap

func (v Validators) Swap(i, j int)

Implements sort interface

func (Validators) ToSDKValidators

func (v Validators) ToSDKValidators() (validators []exported.ValidatorI)

ToSDKValidators - convenience function convert []Validators to []sdk.Validators

Jump to

Keyboard shortcuts

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