iotex-core: github.com/iotexproject/iotex-core/action/protocol/staking Index | Files | Directories

package staking

import "github.com/iotexproject/iotex-core/action/protocol/staking"

Index

Package Files

bucket_index.go candidate.go candidate_center.go candidate_statemanager.go handlers.go protocol.go read_state.go receipt_log.go validations.go vote_bucket.go

Constants

const (
    HandleCreateStake       = "createStake"
    HandleUnstake           = "unstake"
    HandleWithdrawStake     = "withdrawStake"
    HandleChangeCandidate   = "changeCandidate"
    HandleTransferStake     = "transferStake"
    HandleDepositToStake    = "depositToStake"
    HandleRestake           = "restake"
    HandleCandidateRegister = "candidateRegister"
    HandleCandidateUpdate   = "candidateUpdate"
)

constants

const (

    // StakingNameSpace is the bucket name for staking state
    StakingNameSpace = "Staking"

    // CandidateNameSpace is the bucket name for candidate state
    CandidateNameSpace = "Candidate"
)

Variables

var (
    ErrTypeAssertion   = errors.New("failed type assertion")
    ErrWithdrawnBucket = errors.New("the bucket is already withdrawn")
    TotalBucketKey     = append([]byte{_const}, []byte("totalBucket")...)
)

Errors

var (
    ErrNilAction           = errors.New("action is nil")
    ErrInvalidAmount       = errors.New("invalid staking amount")
    ErrInvalidCanName      = errors.New("invalid candidate name")
    ErrInvalidOwner        = errors.New("invalid owner address")
    ErrInvalidOperator     = errors.New("invalid operator address")
    ErrInvalidReward       = errors.New("invalid reward address")
    ErrInvalidSelfStkIndex = errors.New("invalid self-staking bucket index")
    ErrMissingField        = errors.New("missing data field")
)

Errors

var (
    ErrNilParameters = errors.New("parameter is nil")
)

Errors and vars

func BucketIndexFromReceiptLog Uses

func BucketIndexFromReceiptLog(log *iotextypes.Log) (uint64, bool)

BucketIndexFromReceiptLog extracts bucket index from log

type BucketIndices Uses

type BucketIndices []uint64

BucketIndices defines the array of bucket index for a

func (*BucketIndices) Deserialize Uses

func (bis *BucketIndices) Deserialize(data []byte) error

Deserialize deserializes bytes into bucket indices

func (*BucketIndices) LoadProto Uses

func (bis *BucketIndices) LoadProto(bucketIndicesPb *stakingpb.BucketIndices) error

LoadProto converts protobuf to bucket indices

func (*BucketIndices) Proto Uses

func (bis *BucketIndices) Proto() *stakingpb.BucketIndices

Proto converts bucket indices to protobuf

func (*BucketIndices) Serialize Uses

func (bis *BucketIndices) Serialize() ([]byte, error)

Serialize serializes bucket indices into bytes

type Candidate Uses

type Candidate struct {
    Owner              address.Address
    Operator           address.Address
    Reward             address.Address
    Name               string
    Votes              *big.Int
    SelfStakeBucketIdx uint64
    SelfStake          *big.Int
}

Candidate represents the candidate

func (*Candidate) AddSelfStake Uses

func (d *Candidate) AddSelfStake(amount *big.Int) error

AddSelfStake adds self stake

func (*Candidate) AddVote Uses

func (d *Candidate) AddVote(amount *big.Int) error

AddVote adds vote

func (*Candidate) Clone Uses

func (d *Candidate) Clone() *Candidate

Clone returns a copy

func (*Candidate) Collision Uses

func (d *Candidate) Collision(c *Candidate) error

Collision checks collsion of 2 candidates

func (*Candidate) Deserialize Uses

func (d *Candidate) Deserialize(buf []byte) error

Deserialize deserializes bytes to candidate

func (*Candidate) Equal Uses

func (d *Candidate) Equal(c *Candidate) bool

Equal tests equality of 2 candidates

func (*Candidate) Serialize Uses

func (d *Candidate) Serialize() ([]byte, error)

Serialize serializes candidate to bytes

func (*Candidate) SubSelfStake Uses

func (d *Candidate) SubSelfStake(amount *big.Int) error

SubSelfStake subtracts self stake

func (*Candidate) SubVote Uses

func (d *Candidate) SubVote(amount *big.Int) error

SubVote subtracts vote

func (*Candidate) Validate Uses

func (d *Candidate) Validate() error

Validate does the sanity check

type CandidateCenter Uses

type CandidateCenter interface {
    Size() int
    All() CandidateList
    Base() CandidateCenter
    Delta() CandidateList
    SetDelta(CandidateList) error
    Commit() error
    ContainsName(string) bool
    ContainsOwner(address.Address) bool
    ContainsOperator(address.Address) bool
    ContainsSelfStakingBucket(uint64) bool
    GetByName(string) *Candidate
    GetByOwner(address.Address) *Candidate
    GetBySelfStakingIndex(uint64) *Candidate
    Upsert(*Candidate) error
}

CandidateCenter is the candidate center

func NewCandidateCenter Uses

func NewCandidateCenter(all CandidateList) (CandidateCenter, error)

NewCandidateCenter creates an instance of candCenter

type CandidateList Uses

type CandidateList []*Candidate

CandidateList is a list of candidates which is sortable

func (*CandidateList) Deserialize Uses

func (l *CandidateList) Deserialize(buf []byte) error

Deserialize deserializes bytes to list of candidates

func (CandidateList) Len Uses

func (l CandidateList) Len() int

func (CandidateList) Less Uses

func (l CandidateList) Less(i, j int) bool

func (CandidateList) Serialize Uses

func (l CandidateList) Serialize() ([]byte, error)

Serialize serializes candidate to bytes

func (CandidateList) Swap Uses

func (l CandidateList) Swap(i, j int)

type CandidateStateManager Uses

type CandidateStateManager interface {
    protocol.StateManager
    // candidate-related
    Size() int
    ContainsName(string) bool
    ContainsOwner(address.Address) bool
    ContainsOperator(address.Address) bool
    ContainsSelfStakingBucket(uint64) bool
    GetByName(string) *Candidate
    GetByOwner(address.Address) *Candidate
    GetBySelfStakingIndex(uint64) *Candidate
    Upsert(*Candidate) error
    Commit() error
}

CandidateStateManager is candidate manager on top of StateMangaer

func NewCandidateStateManager Uses

func NewCandidateStateManager(sm protocol.StateManager, c CandidateCenter) (CandidateStateManager, error)

NewCandidateStateManager returns a new CandidateStateManager instance

type Configuration Uses

type Configuration struct {
    VoteWeightCalConsts   genesis.VoteWeightCalConsts
    RegistrationConsts    RegistrationConsts
    WithdrawWaitingPeriod time.Duration
    MinStakeAmount        *big.Int
    BootstrapCandidates   []genesis.BootstrapCandidate
}

Configuration is the staking protocol configuration.

type DepositGas Uses

type DepositGas func(ctx context.Context, sm protocol.StateManager, amount *big.Int) error

DepositGas deposits gas to some pool

type Protocol Uses

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

Protocol defines the protocol of handling staking

func NewProtocol Uses

func NewProtocol(depositGas DepositGas, cfg genesis.Staking) (*Protocol, error)

NewProtocol instantiates the protocol of staking

func (*Protocol) ActiveCandidates Uses

func (p *Protocol) ActiveCandidates(ctx context.Context, sr protocol.StateReader, height uint64) (state.CandidateList, error)

ActiveCandidates returns all active candidates in candidate center

func (*Protocol) Commit Uses

func (p *Protocol) Commit(ctx context.Context, sm protocol.StateManager) error

Commit commits the last change

func (*Protocol) CreateGenesisStates Uses

func (p *Protocol) CreateGenesisStates(
    ctx context.Context,
    sm protocol.StateManager,
) error

CreateGenesisStates is used to setup BootstrapCandidates from genesis config.

func (*Protocol) ForceRegister Uses

func (p *Protocol) ForceRegister(r *protocol.Registry) error

ForceRegister registers the protocol with a unique ID and force replacing the previous protocol if it exists

func (*Protocol) Handle Uses

func (p *Protocol) Handle(ctx context.Context, act action.Action, sm protocol.StateManager) (*action.Receipt, error)

Handle handles a staking message

func (*Protocol) Name Uses

func (p *Protocol) Name() string

Name returns the name of protocol

func (*Protocol) ReadState Uses

func (p *Protocol) ReadState(ctx context.Context, sr protocol.StateReader, method []byte, args ...[]byte) ([]byte, error)

ReadState read the state on blockchain via protocol

func (*Protocol) Register Uses

func (p *Protocol) Register(r *protocol.Registry) error

Register registers the protocol with a unique ID

func (*Protocol) Start Uses

func (p *Protocol) Start(ctx context.Context, sr protocol.StateReader) (interface{}, error)

Start starts the protocol

func (*Protocol) Validate Uses

func (p *Protocol) Validate(ctx context.Context, act action.Action, sr protocol.StateReader) error

Validate validates a staking message

type ReceiptError Uses

type ReceiptError interface {
    Error() string
    ReceiptStatus() uint64
}

ReceiptError indicates a non-critical error with corresponding receipt status

type RegistrationConsts Uses

type RegistrationConsts struct {
    Fee          *big.Int
    MinSelfStake *big.Int
}

RegistrationConsts are the registration fee and min self stake

type VoteBucket Uses

type VoteBucket struct {
    Index            uint64
    Candidate        address.Address
    Owner            address.Address
    StakedAmount     *big.Int
    StakedDuration   time.Duration
    CreateTime       time.Time
    StakeStartTime   time.Time
    UnstakeStartTime time.Time
    AutoStake        bool
}

VoteBucket represents a vote

func NewVoteBucket Uses

func NewVoteBucket(cand, owner address.Address, amount *big.Int, duration uint32, ctime time.Time, autoStake bool) *VoteBucket

NewVoteBucket creates a new vote bucket

func (*VoteBucket) Deserialize Uses

func (vb *VoteBucket) Deserialize(buf []byte) error

Deserialize deserializes bytes into bucket

func (*VoteBucket) Serialize Uses

func (vb *VoteBucket) Serialize() ([]byte, error)

Serialize serializes bucket into bytes

Directories

PathSynopsis
stakingpb

Package staking imports 25 packages (graph) and is imported by 2 packages. Updated 2020-07-07. Refresh now. Tools for package owners.