posTypes

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

nolint

Index

Constants

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

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

Variables

View Source
var MaxPartialToken types.Dec = types.NewDec(2) //100/2

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 ErrBadPercentStake

func ErrBadPercentStake(codespace sdk.CodespaceType) sdk.Error

validator

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 ErrDescriptionLength

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

func ErrExistingUnbondingDelegation

func ErrExistingUnbondingDelegation(codespace sdk.CodespaceType) sdk.Error

func ErrInSufficientMasterNodeToken

func ErrInSufficientMasterNodeToken(codespace sdk.CodespaceType) sdk.Error

func ErrInsufficientShares

func ErrInsufficientShares(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

func ErrNoDelegation

func ErrNoDelegation(codespace sdk.CodespaceType) sdk.Error

func ErrNoDelegationFound

func ErrNoDelegationFound(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 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 MustMarshalDelegation

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

aggregates of all delegations, unbondings and redelegations

type DelegationSummary struct {
	Delegations          []Delegation          `json:"delegations"`
	UnbondingDelegations []UnbondingDelegation `json:"unbonding_delegations"`
	Redelegations        []Redelegation        `json:"redelegations"`
}

return the delegation without fields contained within the key for the store

func MustMarshalRED

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

return the redelegation without fields contained within the key for the store

func MustMarshalUBD

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

return the unbonding delegation without fields contained within the key for the store

func MustMarshalValidator

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

return the redelegation without fields contained within the key for the store

func MustMarshalValidatorDist

func MustMarshalValidatorDist(
	cdc *amino.Codec, vdi ValidatorDistInfo,
) []byte

func SortABCIValidators

func SortABCIValidators(av []abci.Validator) []abci.Validator

SortABCIValidators - function to sort abci.Validator in ascending order before returning to Tendermint

Types

type CodeType

type CodeType = sdk.CodeType
const (
	DefaultCodespace sdk.CodespaceType = "POS"

	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 Delegation

type Delegation struct {
	DelegatorAddr    sdk.AccAddress `json:"delegator_addr"`
	ValidatorAddr    sdk.AccAddress `json:"validator_addr"`
	Shares           types.Dec      `json:"shares"`
	Height           int64          `json:"height"`           // Last height bond updated
	RewardAccum      types.Coin     `json:"reward_accum"`     // reward accumulation of this block til withdrawal_height
	WithdrawalHeight int64          `json:"withdrawal_height` // latest withdrawal height
}

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 pubKey.

func MustUnmarshalDelegation

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

return the delegation without fields contained within the key for the store

func UnmarshalDelegation

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

return the delegation without fields contained within the key for the store

func (Delegation) GetBondShares

func (b Delegation) GetBondShares() types.Dec

func (Delegation) GetDelegator

func (b Delegation) GetDelegator() sdk.AccAddress

nolint - for sdk.Delegation

func (Delegation) GetValidator

func (b Delegation) GetValidator() sdk.AccAddress

func (Delegation) HumanReadableString

func (b Delegation) HumanReadableString() (string, error)

Human Friendly pretty printer

func (Delegation) UpdateDelAccum

func (b Delegation) UpdateDelAccum(
	currentHeight int64,
	totalRewardAccum types.Coin,
	totalShares types.Dec,
) Delegation

UpdateDelReward updating reward accumulation

type Description

type Description struct {
	Moniker  string `json:"moniker"`  // name
	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

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 Params

type Params struct {
	GoalBonded types.Dec `json:"goal_bonded"` // Goal of percent bonded atoms

	UnbondingTime time.Duration `json:"unbonding_time"`

	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

func DefaultParams

func DefaultParams() Params

DefaultParams returns a default set of parameters.

type Pool

type Pool struct {
	LooseTokens             types.Dec `json:"loose_tokens"`               // tokens which are not bonded in a validator
	BondedTokens            types.Dec `json:"bonded_tokens"`              // reserve of bonded tokens
	DateLastCommissionReset int64     `json:"date_last_commission_reset"` // unix timestamp for last commission accounting reset (daily)

	// Fee Related
	PrevBondedShares types.Dec `json:"prev_bonded_shares"` // last recorded bonded shares - for fee calculations
}

Pool - dynamic parameters of the current state

func InitialPool

func InitialPool() Pool

initial pool for testing

func MustUnmarshalPool

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

unmarshal the current pool value from store key or panics

func UnmarshalPool

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

unmarshal the current pool value from store key

func (Pool) BondedRatio

func (p Pool) BondedRatio() types.Dec

get the bond ratio of the global state

func (Pool) HumanReadableString

func (p Pool) HumanReadableString() string

HumanReadableString returns a human readable string representation of a pool.

func (Pool) TokenSupply

func (p Pool) TokenSupply() types.Dec

Sum total of all staking tokens in the pool

type Redelegation

type Redelegation struct {
	DelegatorAddr    sdk.AccAddress `json:"delegator_addr"`     // delegator
	ValidatorSrcAddr sdk.AccAddress `json:"validator_src_addr"` // validator redelegation source operator addr
	ValidatorDstAddr sdk.AccAddress `json:"validator_dst_addr"` // validator redelegation destination operator addr
	CreationHeight   int64          `json:"creation_height"`    // height which the redelegation took place
	MinTime          time.Time      `json:"min_time"`           // unix time for redelegation completion
	InitialBalance   types.Coin     `json:"initial_balance"`    // initial balance when redelegation started
	Balance          types.Coin     `json:"balance"`            // current balance
	SharesSrc        types.Dec      `json:"shares_src"`         // amount of source shares redelegating
	SharesDst        types.Dec      `json:"shares_dst"`         // amount of destination shares redelegating
}

Redelegation reflects a delegation's passive re-delegation queue.

func MustUnmarshalRED

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

unmarshal a redelegation from a store key and value

func UnmarshalRED

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

unmarshal a redelegation from a store key and value

type SortValidators

type SortValidators []abci.Validator

func (SortValidators) Len

func (av SortValidators) Len() int

func (SortValidators) Less

func (av SortValidators) Less(i, j int) bool

func (SortValidators) Swap

func (av SortValidators) Swap(i, j int)

type UnbondingDelegation

type UnbondingDelegation struct {
	DelegatorAddr  sdk.AccAddress `json:"delegator_addr"`  // delegator
	ValidatorAddr  sdk.AccAddress `json:"validator_addr"`  // validator unbonding from operator addr
	CreationHeight int64          `json:"creation_height"` // height which the unbonding took place
	MinTime        time.Time      `json:"min_time"`        // unix time for unbonding completion  /*time.Time*/
	InitialBalance types.Coin     `json:"initial_balance"` // atoms initially scheduled to receive at completion
	Balance        types.Coin     `json:"balance"`         // atoms to receive at completion
}

UnbondingDelegation reflects a delegation's passive unbonding queue.

func MustUnmarshalUBD

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

unmarshal a unbonding delegation from a store key and value

func UnmarshalUBD

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

unmarshal a unbonding delegation from a store key and value

type Validator

type Validator struct {
	Owner   sdk.AccAddress   `json:"owner"`   // sender of BondTx - UnbondTx returns here
	PubKey  types.PubKey     `json:"pub_key"` // pubkey of validator
	Revoked bool             `json:"revoked"` // has the validator  been revoked from bonded status?
	Status  types.BondStatus `json:"status"`  // validator status (bonded/unbonding/unbonded)

	Tokens          types.Dec `json:"tokens"`           // delegated tokens (incl. self-delegation)
	DelegatorShares types.Dec `json:"delegator_shares"` // total shares issued to a validator's delegators
	CommissionRate  types.Dec `json:"commission_rate"`  // commision kept by this validator

	Description        Description `json:"description"`           // description terms for the validator
	BondHeight         int64       `json:"bond_height"`           // earliest height as a bonded validator
	BondIntraTxCounter int16       `json:"bond_intra_tx_counter"` // block-local tx index of validator change
	UnbondingHeight    int64       `json:"unbonding_height"`      // if unbonding, height at which this validator has begun unbonding
	UnbondingMinTime   time.Time   `json:"unbonding_time"`        // time.Time  // if unbonding, min time for the validator to complete unbonding

}

Validator 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 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 bonds multiplied by exchange rate.

func MustUnmarshalValidator

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

unmarshal a redelegation from a store key and value

func NewValidator

func NewValidator(owner sdk.AccAddress, pubKey types.PubKey, description Description) Validator

NewValidator - initialize a new validator

func UnmarshalValidator

func UnmarshalValidator(cdc *amino.Codec, owner sdk.AccAddress, value []byte) (validator Validator, err error)

unmarshal a redelegation from a store key and value

func (Validator) ABCIValidator

func (v Validator) ABCIValidator() abci.Validator

func (Validator) ABCIValidatorUpdate added in v0.2.0

func (v Validator) ABCIValidatorUpdate() abci.ValidatorUpdate

validator which fulfills abci validator interface for use in Tendermint ABCIValidator returns an abci.Validator from a staked validator type.

func (Validator) ABCIValidatorZero

func (v Validator) ABCIValidatorZero() abci.ValidatorUpdate

ABCIValidator returns an abci.Validator from a staked validator type.

func (Validator) AddTokensFromDel

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

XXX Audit this function further to make sure it's correct add tokens to a validator

func (Validator) BondedTokens

func (v Validator) BondedTokens() types.Dec

Get the bonded tokens which the validator holds

func (Validator) DelegatorShareExRate

func (v Validator) DelegatorShareExRate() types.Dec

DelegatorShareExRate gets the exchange rate of tokens over delegator shares. UNITS: tokens/delegator-shares

func (Validator) Equal

func (v Validator) Equal(c2 Validator) bool

only the vitals - does not check bond height of IntraTxCounter

func (Validator) GetABCIPubKey

func (v Validator) GetABCIPubKey() secp256k1.PubKeySecp256k1

func (Validator) GetBondHeight

func (v Validator) GetBondHeight() int64

func (Validator) GetDelegatorShares

func (v Validator) GetDelegatorShares() types.Dec

func (Validator) GetMoniker

func (v Validator) GetMoniker() string

nolint - for sdk.Validator

func (Validator) GetOwner

func (v Validator) GetOwner() sdk.AccAddress

func (Validator) GetPower

func (v Validator) GetPower() types.Dec

func (Validator) GetPubKey

func (v Validator) GetPubKey() types.PubKey

func (Validator) GetStatus

func (v Validator) GetStatus() types.BondStatus

func (Validator) HumanReadableString

func (v Validator) HumanReadableString() (string, error)

Human Friendly pretty printer

func (Validator) IsDelegatingTokenValid

func (v Validator) IsDelegatingTokenValid(pool Pool, tokenAMount types.Dec) bool

check if the adding token violate the percent rule or not:

func (Validator) IsUnbonded

func (v Validator) IsUnbonded(ctx sdk.Context) bool

Returns if the validator should be considered unbonded

func (Validator) RemoveDelShares

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

RemoveDelShares removes delegator shares from a validator.

func (Validator) RemoveTokens

func (v Validator) RemoveTokens(pool Pool, tokens types.Dec) (Validator, Pool)

removes tokens from a validator

func (Validator) UpdateStatus

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

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

type ValidatorDistInfo

type ValidatorDistInfo struct {
	ValidatorAddr    sdk.AccAddress `json:"validator_addr"`    // Validator Address
	RewardAccum      types.Coin     `json:"reward_accum"`      // Block Reward accumulation since BlockHeight, excluding commission
	Commission       types.Coin     `json:"commision"`         // total commission
	WithdrawalHeight int64          `json:"withdrawal_height"` // Latest blockheight that performs reward distribution
	ValidatorReward  types.Coin     `json:"validator_reward"`  // Validator reward accumulation not yet witdrawed
}

func MustUnmarshalValidatorDist

func MustUnmarshalValidatorDist(
	cdc *amino.Codec, value []byte,
) ValidatorDistInfo

func NewValidatorDistInfo

func NewValidatorDistInfo(
	validatorAddress sdk.AccAddress,
	currentHeight int64,
) ValidatorDistInfo

NewValidatorDistInfo - return new ValidatorDistInfo

func UnmarshalValidatorDist

func UnmarshalValidatorDist(
	cdc *amino.Codec, value []byte,
) (
	vdi ValidatorDistInfo, err error,
)

func (ValidatorDistInfo) HumanReadableString

func (vdi ValidatorDistInfo) HumanReadableString() string

type Validators

type Validators []Validator

Validators - list of Validators

Jump to

Keyboard shortcuts

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