staking

package
v0.0.0-...-f705c6e Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package staking provides staking functionalities for validators and delegators. [More Details](https://www.junjie-bianjie.org/docs/features/stake.html)

As a quick start:

 baseTx := sdk.BaseTx{
		From: "test1",
		Gas:  20000,
		Memo: "test",
		Mode: sdk.Commit,
	}

	//test QueryValidators
	validators, _ := sts.Staking().QueryValidators(1, 10)
	validator := validators[0].OperatorAddress
	amt, _ := sdk.NewIntFromString("20000000000000000000")
	amount := sdk.NewCoin("iris-atto", amt)

	//test Delegate
	rs, err := sts.Staking().Delegate(validator, amount, baseTx)
	require.NoError(sts.T(), err)
	require.NotEmpty(sts.T(), rs.Hash)

	//test QueryDelegation
	delegator := sts.Sender().String()
	d, err := sts.Staking().QueryDelegation(delegator, validator)
	require.NoError(sts.T(), err)
	require.Equal(sts.T(), validator, d.ValidatorAddr)
	require.Equal(sts.T(), delegator, d.DelegatorAddr)

	//test QueryDelegations
	ds, err := sts.Staking().QueryDelegations(delegator)
	require.NoError(sts.T(), err)
	require.NotEmpty(sts.T(), ds)

	//test QueryDelegationsTo
	ds, err = sts.Staking().QueryDelegationsTo(validator)
	require.NoError(sts.T(), err)
	require.NotEmpty(sts.T(), ds)

	//test Undelegate
	amt, _ = sdk.NewIntFromString("10000000000000000000")
	amount = sdk.NewCoin("iris-atto", amt)
	rs, err = sts.Staking().Undelegate(validator, amount, baseTx)
	require.NoError(sts.T(), err)
	require.NotEmpty(sts.T(), rs.Hash)

	//test QueryUnbondingDelegation
	ubd, err := sts.Staking().QueryUnbondingDelegation(delegator, validator)
	require.NoError(sts.T(), err)
	require.Equal(sts.T(), validator, ubd.ValidatorAddr)
	require.Equal(sts.T(), delegator, ubd.DelegatorAddr)

	//test QueryUnbondingDelegations
	ubds, err := sts.Staking().QueryUnbondingDelegations(delegator)
	require.NoError(sts.T(), err)
	require.NotEmpty(sts.T(), ubds)

	//test QueryUnbondingDelegationsFrom
	uds, err := sts.Staking().QueryUnbondingDelegationsFrom(validator)
	require.NoError(sts.T(), err)
	require.NotEmpty(sts.T(), uds)

Index

Constants

View Source
const (
	Unbonded  bondStatus = 1
	Unbonding bondStatus = 2
	Bonded    bondStatus = 3

	BondStatusUnbonded  = "Unbonded"
	BondStatusUnbonding = "Unbonding"
	BondStatusBonded    = "Bonded"
)

nolint

View Source
const (
	ModuleName = "stake"
)

Variables

This section is empty.

Functions

func Create

func Create(ac sdk.BaseClient) rpc.Staking

Types

type Commission

type Commission struct {
	CommissionRates `json:"commission_rates"`
}

Commission defines a commission parameters for a given validator.

type CommissionMsg

type CommissionMsg struct {
	Rate          sdk.Dec `json:"rate"`            // the commission rate charged to delegators
	MaxRate       sdk.Dec `json:"max_rate"`        // maximum commission rate which validator can ever charge
	MaxChangeRate sdk.Dec `json:"max_change_rate"` // maximum daily increase of the validator commission
}

CommissionMsg defines a commission message to be used for creating a validator.

type CommissionRates

type CommissionRates struct {
	Rate          sdk.Dec   `json:"rate"`            // the commission rate charged to delegators
	MaxRate       sdk.Dec   `json:"max_rate"`        // maximum commission rate which validator can ever charge
	MaxChangeRate sdk.Dec   `json:"max_change_rate"` // maximum daily increase of the validator commission
	UpdateTime    time.Time `json:"update_time"`     // the last time the commission rate was changed
}

CommissionRates defines the initial commission rates to be used for creating a validator.

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
	SecurityContact string `json:"security_contact"` // optional securityContact
	Details         string `json:"details"`          // optional details
}

Description - description fields for a validator

type MsgBeginRedelegate

type MsgBeginRedelegate struct {
	DelegatorAddr    sdk.AccAddress `json:"delegator_addr"`
	ValidatorSrcAddr sdk.ValAddress `json:"validator_src_addr"`
	ValidatorDstAddr sdk.ValAddress `json:"validator_dst_addr"`
	SharesAmount     sdk.Dec        `json:"shares_amount"`
}

______________________________________________________________________ MsgBeginRedelegate - struct for bonding transactions

func NewMsgBeginRedelegate

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

func (MsgBeginRedelegate) GetSignBytes

func (msg MsgBeginRedelegate) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgBeginRedelegate) GetSigners

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

func (MsgBeginRedelegate) Route

func (msg MsgBeginRedelegate) Route() string

nolint

func (MsgBeginRedelegate) Type

func (msg MsgBeginRedelegate) Type() string

func (MsgBeginRedelegate) ValidateBasic

func (msg MsgBeginRedelegate) ValidateBasic() error

quick validity check

type MsgCreateValidator

type MsgCreateValidator struct {
	Description
	Commission    CommissionMsg
	DelegatorAddr sdk.AccAddress `json:"delegator_address"`
	ValidatorAddr sdk.ValAddress `json:"validator_address"`
	PubKey        crypto.PubKey  `json:"pubkey"`
	Delegation    sdk.Coin       `json:"delegation"`
}

MsgCreateValidator - struct for bonding transactions

func (MsgCreateValidator) GetSignBytes

func (msg MsgCreateValidator) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgCreateValidator) GetSigners

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

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

func (MsgCreateValidator) Route

func (msg MsgCreateValidator) Route() string

nolint

func (MsgCreateValidator) Type

func (msg MsgCreateValidator) Type() string

func (MsgCreateValidator) ValidateBasic

func (msg MsgCreateValidator) ValidateBasic() error

quick validity check

type MsgDelegate

type MsgDelegate struct {
	DelegatorAddr sdk.AccAddress `json:"delegator_addr"`
	ValidatorAddr sdk.ValAddress `json:"validator_addr"`
	Delegation    sdk.Coin       `json:"delegation"`
}

MsgDelegate - struct for bonding transactions

func (MsgDelegate) GetSignBytes

func (msg MsgDelegate) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgDelegate) GetSigners

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

func (MsgDelegate) Route

func (msg MsgDelegate) Route() string

func (MsgDelegate) Type

func (msg MsgDelegate) Type() string

nolint

func (MsgDelegate) ValidateBasic

func (msg MsgDelegate) ValidateBasic() error

quick validity check

type MsgEditValidator

type MsgEditValidator struct {
	Description
	ValidatorAddr sdk.ValAddress `json:"address"`

	// We pass a reference to the new commission rate as it's not mandatory to
	// update. If not updated, the deserialized rate will be zero with no way to
	// distinguish if an update was intended.
	//
	// REF: #2373
	CommissionRate *sdk.Dec `json:"commission_rate"`
}

MsgEditValidator - struct for editing a validator

func (MsgEditValidator) GetSignBytes

func (msg MsgEditValidator) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgEditValidator) GetSigners

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

func (MsgEditValidator) Route

func (msg MsgEditValidator) Route() string

nolint

func (MsgEditValidator) Type

func (msg MsgEditValidator) Type() string

func (MsgEditValidator) ValidateBasic

func (msg MsgEditValidator) ValidateBasic() error

quick validity check

type MsgUndelegate

type MsgUndelegate struct {
	DelegatorAddr sdk.AccAddress `json:"delegator_addr"`
	ValidatorAddr sdk.ValAddress `json:"validator_addr"`
	SharesAmount  sdk.Dec        `json:"shares_amount"`
}

MsgUndelegate - struct for unbonding transactions

func (MsgUndelegate) GetSignBytes

func (msg MsgUndelegate) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgUndelegate) GetSigners

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

func (MsgUndelegate) Route

func (msg MsgUndelegate) Route() string

nolint

func (MsgUndelegate) Type

func (msg MsgUndelegate) Type() string

func (MsgUndelegate) ValidateBasic

func (msg MsgUndelegate) ValidateBasic() error

quick validity check

type Pool

type Pool struct {
	NotBondedTokens sdk.Int `json:"not_bonded_tokens"` // tokens which are not bonded in a validator
	BondedTokens    sdk.Int `json:"bonded_tokens"`     // reserve of bonded tokens
}

func (Pool) Convert

func (p Pool) Convert() interface{}

Jump to

Keyboard shortcuts

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