staking

package
v0.0.0-...-91d38f8 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2020 License: GPL-3.0 Imports: 17 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyValidatorSet returns when valset from smart-contract is empty
	ErrEmptyValidatorSet = errors.New("empty validator set")
	// ErrLengthOfCandidatesAndStakesMisMatch returns when lengths stakes and candidates are not match
	ErrLengthOfCandidatesAndStakesMisMatch = errors.New("length of stakes is not equal to length of candidates")
	// ErrLengthOfVotesAndStakesMisMatch returns when lengths voters and stakes are not match
	ErrLengthOfVotesAndStakesMisMatch = errors.New("length of voters is not equal to length of stakes")
)
View Source
var DefaultConfig = &IndexConfigs{
	WithdrawsStateLayout:    NewLayOut(1, 0),
	CandidateVotersLayout:   NewLayOut(2, 0),
	CandidateDataLayout:     NewLayOut(3, 0),
	CandidatesLayout:        NewLayOut(4, 0),
	StartBlockLayout:        NewLayOut(5, 0),
	EpochPeriodLayout:       NewLayOut(6, 0),
	MaxValidatorSizeLayout:  NewLayOut(7, 0),
	MinValidatorStakeLayout: NewLayOut(8, 0),
	MinVoterCapLayout:       NewLayOut(9, 0),
	AdminLayout:             NewLayOut(10, 0),
	CandidateDataStruct: CandidateDataStructIndex{
		TotalStake:   NewLayOut(1, 0),
		Owner:        NewLayOut(2, 0),
		VotersStakes: NewLayOut(3, 0),
	},
}

DefaultConfig represents he default configuration.

Functions

func NewChainContextWrapper

func NewChainContextWrapper(engine consensus.Engine, getHeaderFn func(common.Hash, uint64) *types.Header) core.ChainContext

Types

type CandidateData

type CandidateData struct {
	Owner       common.Address
	VoterStakes map[common.Address]*big.Int
	TotalStake  *big.Int
}

type CandidateDataStructIndex

type CandidateDataStructIndex struct {
	Owner        LayOut
	TotalStake   LayOut
	VotersStakes LayOut
}

layout inside candidateData struct

type IndexConfigs

type IndexConfigs struct {
	WithdrawsStateLayout    LayOut //1
	CandidateVotersLayout   LayOut //2
	CandidateDataLayout     LayOut //3
	CandidatesLayout        LayOut //4
	StartBlockLayout        LayOut //5
	EpochPeriodLayout       LayOut //6
	MaxValidatorSizeLayout  LayOut //7
	MinValidatorStakeLayout LayOut //8
	MinVoterCapLayout       LayOut //9
	AdminLayout             LayOut //10

	CandidateDataStruct CandidateDataStructIndex
}

IndexConfigs represents the configuration index of state variables.

type LayOut

type LayOut struct {
	Offset uint16
	Slot   uint64
}

LayOut represents the Offset and Slot order of a state variable

func NewLayOut

func NewLayOut(slot uint64, offset uint16) LayOut

NewLayOut returns new instance of a LayOut

type StakingCaller

type StakingCaller interface {
	// GetValidators returns list of validators, calculate from current stateDB
	GetValidators(common.Address) ([]common.Address, error)
	// GetValidatorsData return information of validators including owner, totalStake and voterStakes
	GetValidatorsData(common.Address, []common.Address) (map[common.Address]CandidateData, error)
}

func NewEVMStakingCaller deprecated

func NewEVMStakingCaller(stateDB *state.StateDB, chainContext core.ChainContext, header *types.Header,
	chainConfig *params.ChainConfig, vmConfig vm.Config) StakingCaller

Deprecated: Using NewStateDbStakingCaller instead of NewBECaller returns staking caller which reads data from staking smart-contract by execute a call from evm

func NewStateDbStakingCaller

func NewStateDbStakingCaller(state *state.StateDB, cfg *IndexConfigs) StakingCaller

NewStateDbStakingCaller return instance of StakingCaller which reads data directly from state DB

Jump to

Keyboard shortcuts

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