Documentation ¶
Index ¶
- Constants
- Variables
- func IsValidCandidateName(s string) bool
- type BucketIndices
- type Candidate
- func (d *Candidate) AddSelfStake(amount *big.Int) error
- func (d *Candidate) AddVote(amount *big.Int) error
- func (d *Candidate) Clone() *Candidate
- func (d *Candidate) Deserialize(buf []byte) error
- func (d *Candidate) Serialize() ([]byte, error)
- func (d *Candidate) SubSelfStake(amount *big.Int) error
- func (d *Candidate) SubVote(amount *big.Int) error
- type CandidateCenter
- func (m CandidateCenter) All() (CandidateList, error)
- func (m CandidateCenter) ContainsName(name string) bool
- func (m CandidateCenter) ContainsOperator(operator address.Address) bool
- func (m CandidateCenter) ContainsOwner(owner address.Address) bool
- func (m CandidateCenter) ContainsSelfStakingBucket(index uint64) bool
- func (m CandidateCenter) Delete(owner address.Address)
- func (m CandidateCenter) GetByName(name string) *Candidate
- func (m CandidateCenter) GetByOwner(owner address.Address) *Candidate
- func (m CandidateCenter) GetBySelfStakingIndex(index uint64) *Candidate
- func (m CandidateCenter) Size() int
- func (m CandidateCenter) Upsert(d *Candidate) error
- type CandidateList
- type Configuration
- type DepositGas
- type Protocol
- func (p *Protocol) ActiveCandidates(context.Context) (state.CandidateList, error)
- func (p *Protocol) CreateGenesisStates(ctx context.Context, sm protocol.StateManager) error
- func (p *Protocol) ForceRegister(r *protocol.Registry) error
- func (p *Protocol) Handle(ctx context.Context, act action.Action, sm protocol.StateManager) (*action.Receipt, error)
- func (p *Protocol) ReadState(ctx context.Context, sr protocol.StateReader, method []byte, args ...[]byte) ([]byte, error)
- func (p *Protocol) Register(r *protocol.Registry) error
- func (p *Protocol) Start(ctx context.Context) error
- func (p *Protocol) Validate(ctx context.Context, act action.Action) error
- type RegistrationConsts
- type VoteBucket
Constants ¶
const ( // HandleCreateStake is the handler name of createStake HandleCreateStake = "createStake" // HandleUnstake is the handler name of unstake HandleUnstake = "unstake" // HandleWithdrawStake is the handler name of withdrawStake HandleWithdrawStake = "withdrawStake" // HandleChangeCandidate is the handler name of changeCandidate HandleChangeCandidate = "changeCandidate" // HandleTransferStake is the handler name of transferStake HandleTransferStake = "transferStake" // HandleDepositToStake is the handler name of depositToStake HandleDepositToStake = "depositToStake" // HandleRestake is the handler name of restake HandleRestake = "restake" // HandleCandidateRegister is the handler name of candidateRegister HandleCandidateRegister = "candidateRegister" // HandleCandidateUpdate is the handler name of candidateUpdate HandleCandidateUpdate = "candidateUpdate" )
const ( // StakingNameSpace is the bucket name for staking state StakingNameSpace = "Staking" // CandidateNameSpace is the bucket name for candidate state CandidateNameSpace = "Candidate" )
Variables ¶
var ( ErrAlreadyExist = errors.New("candidate already exist") 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") ErrInvalidSelfStkIndex = errors.New("invalid self-staking bucket index") ErrMissingField = errors.New("missing data field") )
Errors
Functions ¶
func IsValidCandidateName ¶
IsValidCandidateName check if a candidate name string is valid.
Types ¶
type BucketIndices ¶
type BucketIndices []uint64
BucketIndices defines the array of bucket index for a
func (*BucketIndices) Deserialize ¶
func (bis *BucketIndices) Deserialize(data []byte) error
Deserialize deserializes bytes into bucket indices
func (*BucketIndices) LoadProto ¶
func (bis *BucketIndices) LoadProto(bucketIndicesPb *stakingpb.BucketIndices) error
LoadProto converts protobuf to bucket indices
func (*BucketIndices) Proto ¶
func (bis *BucketIndices) Proto() *stakingpb.BucketIndices
Proto converts bucket indices to protobuf
func (*BucketIndices) Serialize ¶
func (bis *BucketIndices) Serialize() ([]byte, error)
Serialize serializes bucket indices into bytes
type Candidate ¶
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 ¶
AddSelfStake adds self stake
func (*Candidate) Deserialize ¶
Deserialize deserializes bytes to candidate
func (*Candidate) SubSelfStake ¶
SubSelfStake subtracts self stake
type CandidateCenter ¶
type CandidateCenter struct {
// contains filtered or unexported fields
}
CandidateCenter is a struct to manage the candidates
func NewCandidateCenter ¶
func NewCandidateCenter() *CandidateCenter
NewCandidateCenter creates an instance of CandidateCenter
func (CandidateCenter) All ¶
func (m CandidateCenter) All() (CandidateList, error)
All returns all candidates in candidate center
func (CandidateCenter) ContainsName ¶
func (m CandidateCenter) ContainsName(name string) bool
ContainsName returns true if the map contains the candidate by name
func (CandidateCenter) ContainsOperator ¶
func (m CandidateCenter) ContainsOperator(operator address.Address) bool
ContainsOperator returns true if the map contains the candidate by operator
func (CandidateCenter) ContainsOwner ¶
func (m CandidateCenter) ContainsOwner(owner address.Address) bool
ContainsOwner returns true if the map contains the candidate by owner
func (CandidateCenter) ContainsSelfStakingBucket ¶
func (m CandidateCenter) ContainsSelfStakingBucket(index uint64) bool
ContainsSelfStakingBucket returns true if the map contains the self staking bucket index
func (CandidateCenter) Delete ¶
func (m CandidateCenter) Delete(owner address.Address)
Delete deletes the candidate by name
func (CandidateCenter) GetByName ¶
func (m CandidateCenter) GetByName(name string) *Candidate
GetByName returns the candidate by name
func (CandidateCenter) GetByOwner ¶
func (m CandidateCenter) GetByOwner(owner address.Address) *Candidate
GetByOwner returns the candidate by owner
func (CandidateCenter) GetBySelfStakingIndex ¶
func (m CandidateCenter) GetBySelfStakingIndex(index uint64) *Candidate
GetBySelfStakingIndex returns the candidate by self-staking index
func (CandidateCenter) Upsert ¶
func (m CandidateCenter) Upsert(d *Candidate) error
Upsert adds a candidate into map, overwrites if already exist
type CandidateList ¶
type CandidateList []*Candidate
CandidateList is a list of candidates which is sortable
func (*CandidateList) Deserialize ¶
func (l *CandidateList) Deserialize(buf []byte) error
Deserialize deserializes bytes to list of candidates
func (CandidateList) Len ¶
func (l CandidateList) Len() int
func (CandidateList) Less ¶
func (l CandidateList) Less(i, j int) bool
func (CandidateList) Swap ¶
func (l CandidateList) Swap(i, j int)
type Configuration ¶
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 ¶
DepositGas deposits gas to some pool
type Protocol ¶
type Protocol struct {
// contains filtered or unexported fields
}
Protocol defines the protocol of handling staking
func NewProtocol ¶
func NewProtocol(depositGas DepositGas, sr protocol.StateReader, cfg genesis.Staking) (*Protocol, error)
NewProtocol instantiates the protocol of staking
func (*Protocol) ActiveCandidates ¶
ActiveCandidates returns all active candidates in candidate center
func (*Protocol) CreateGenesisStates ¶
CreateGenesisStates is used to setup BootstrapCandidates from genesis config.
func (*Protocol) ForceRegister ¶
ForceRegister registers the protocol with a unique ID and force replacing the previous protocol if it exists
func (*Protocol) Handle ¶
func (p *Protocol) Handle(ctx context.Context, act action.Action, sm protocol.StateManager) (*action.Receipt, error)
Handle handles a staking message
func (*Protocol) ReadState ¶
func (p *Protocol) ReadState(ctx context.Context, sr protocol.StateReader, method []byte, args ...[]byte) ([]byte, error)
ReadState read the state on blockchain via protocol
type RegistrationConsts ¶
RegistrationConsts are the registration fee and min self stake
type VoteBucket ¶
type VoteBucket struct { 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 ¶
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 ¶
func (vb *VoteBucket) Deserialize(buf []byte) error
Deserialize deserializes bytes into bucket
func (*VoteBucket) Serialize ¶
func (vb *VoteBucket) Serialize() ([]byte, error)
Serialize serializes bucket into bytes