staking

package
v1.2.0-fork6 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: LGPL-3.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ONE_DAY_LOCK      = uint32(0)
	ONE_DAY_LOCK_RATE = uint8(0)
	ONE_DAY_LOCK_TIME = uint64(60 * 60 * 24)

	ONE_WEEK_LOCK      = uint32(1)
	ONE_WEEK_LOCK_RATE = uint8(5) // 5 percent
	ONE_WEEK_LOCK_TIME = uint64(60 * 60 * 24 * 7)

	TWO_WEEK_LOCK      = uint32(2)
	TWO_WEEK_LOCK_RATE = uint8(6) // %6
	TWO_WEEK_LOCK_TIME = uint64(60 * 60 * 24 * 14)

	THREE_WEEK_LOCK      = uint32(3)
	THREE_WEEK_LOCK_RATE = uint8(7)
	THREE_WEEK_LOCK_TIME = uint64(60 * 60 * 24 * 21)

	FOUR_WEEK_LOCK      = uint32(4)
	FOUR_WEEK_LOCK_RATE = uint8(8)
	FOUR_WEEK_LOCK_TIME = uint64(60 * 60 * 24 * 28)

	// for candidate bucket ONLY
	FOREVER_LOCK_RATE = ONE_WEEK_LOCK_RATE
	FOREVER_LOCK_TIME = uint64(0)

	BUCKET_ADD_OPT = 0
	BUCKET_SUB_OPT = 1
)

staking options

View Source
const (
	MIN_CANDIDATE_UPDATE_INTV = uint64(3600 * 24) // 1 day
	TESLA1_0_SELF_VOTE_RATIO  = 10                // max candidate total votes / self votes ratio < 10x in Tesla 1.0
	TESLA1_1_SELF_VOTE_RATIO  = 100               // max candidate total votes / self votes ratio < 100x in Tesla 1.1

	STAKING_TIMESPAN = uint64(720)
)
View Source
const (
	OP_BOUND          = uint32(1)
	OP_UNBOUND        = uint32(2)
	OP_CANDIDATE      = uint32(3)
	OP_UNCANDIDATE    = uint32(4)
	OP_DELEGATE       = uint32(5)
	OP_UNDELEGATE     = uint32(6)
	OP_CANDIDATE_UPDT = uint32(7)
	OP_BUCKET_UPDT    = uint32(8)

	OP_DELEGATE_STATISTICS  = uint32(101)
	OP_DELEGATE_EXITJAIL    = uint32(102)
	OP_FLUSH_ALL_STATISTICS = uint32(103)

	OP_GOVERNING = uint32(10001)
)

Variables

View Source
var (
	// bound minimium requirement 100 mtrgov
	MIN_BOUND_BALANCE *big.Int = new(big.Int).Mul(big.NewInt(100), big.NewInt(1e18))
	MIN_SUB_BALANCE   *big.Int = new(big.Int).Mul(big.NewInt(100), big.NewInt(1e18))

	// delegate minimum requirement 2000 MTRG
	MIN_REQUIRED_BY_DELEGATE *big.Int = new(big.Int).Mul(big.NewInt(int64(2000)), big.NewInt(int64(1e18)))

	// amount to exit from jail 10 MTRGov
	BAIL_FOR_EXIT_JAIL *big.Int = new(big.Int).Mul(big.NewInt(int64(10)), big.NewInt(int64(1e18)))
)

Functions

func CalcBonus

func CalcBonus(fromTS uint64, toTS uint64, rate uint8, value *big.Int) *big.Int

func CheckCandEnoughSelfVotes added in v1.2.0

func CheckCandEnoughSelfVotes(newVotes *big.Int, c *meter.Candidate, bl *meter.BucketList, selfVoteRatio int64) bool

func CheckEnoughSelfVotes

func CheckEnoughSelfVotes(subVotes *big.Int, c *meter.Candidate, bl *meter.BucketList, selfVoteRatio int64) bool

func GetBoundLockOption

func GetBoundLockOption(chose uint32) (opt uint32, rate uint8, locktime uint64)

func GetBoundLocktime

func GetBoundLocktime(opt uint32) (lock uint64)

func GetCandidateBucket added in v1.2.0

func GetCandidateBucket(c *meter.Candidate, bl *meter.BucketList) (*meter.Bucket, error)

get the bucket that candidate initialized

func GetCandidateSelfBuckets added in v1.2.0

func GetCandidateSelfBuckets(c *meter.Candidate, bl *meter.BucketList) ([]*meter.Bucket, error)

get the buckets which owner is candidate

func GetCommissionRate

func GetCommissionRate(opt uint32) uint64

func GetOpName

func GetOpName(op uint32) string

func InTimeSpan

func InTimeSpan(ts, now, span uint64) bool

func TouchBucketBonus added in v1.2.0

func TouchBucketBonus(ts uint64, bucket *meter.Bucket) *big.Int

deprecated warning: BonusVotes will always be 0 after Tesla Fork 5

Types

type Staking

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

Candidate indicates the structure of a candidate

func NewStaking

func NewStaking(ch *chain.Chain, sc *state.Creator) *Staking

func (*Staking) BoundHandler

func (s *Staking) BoundHandler(env *setypes.ScriptEnv, sb *StakingBody, gas uint64) (leftOverGas uint64, err error)

func (*Staking) BucketUpdateHandler

func (s *Staking) BucketUpdateHandler(env *setypes.ScriptEnv, sb *StakingBody, gas uint64) (leftOverGas uint64, err error)

update the bucket value. we can only increase the balance

func (*Staking) CandidateHandler

func (s *Staking) CandidateHandler(env *setypes.ScriptEnv, sb *StakingBody, gas uint64) (leftOverGas uint64, err error)

func (*Staking) CandidateUpdateHandler

func (s *Staking) CandidateUpdateHandler(env *setypes.ScriptEnv, sb *StakingBody, gas uint64) (leftOverGas uint64, err error)

This method only update the attached infomation of candidate. Stricted to: name, public key, IP/port, commission

func (*Staking) Chain

func (s *Staking) Chain() *chain.Chain

func (*Staking) DelegateExitJailHandler

func (s *Staking) DelegateExitJailHandler(env *setypes.ScriptEnv, sb *StakingBody, gas uint64) (leftOverGas uint64, err error)

func (*Staking) DelegateHandler

func (s *Staking) DelegateHandler(env *setypes.ScriptEnv, sb *StakingBody, gas uint64) (leftOverGas uint64, err error)

func (*Staking) DelegateStatFlushHandler

func (s *Staking) DelegateStatFlushHandler(env *setypes.ScriptEnv, sb *StakingBody, gas uint64) (leftOverGas uint64, err error)

this is debug API, only executor has the right to call

func (*Staking) DelegateStatHandler

func (s *Staking) DelegateStatHandler(env *setypes.ScriptEnv, sb *StakingBody, gas uint64) (leftOverGas uint64, err error)

func (*Staking) DoTeslaFork1_Correction

func (s *Staking) DoTeslaFork1_Correction(bid meter.Bytes32, owner meter.Address, amount *big.Int, state *state.State, ts uint64)

func (*Staking) DoTeslaFork5_BonusCorrection

func (s *Staking) DoTeslaFork5_BonusCorrection(state *state.State)

func (*Staking) DoTeslaFork6_StakingCorrection

func (s *Staking) DoTeslaFork6_StakingCorrection(state *state.State)

func (*Staking) GoverningHandler

func (s *Staking) GoverningHandler(env *setypes.ScriptEnv, sb *StakingBody, gas uint64) (leftOverGas uint64, err error)

func (*Staking) Handle

func (s *Staking) Handle(senv *setypes.ScriptEnv, payload []byte, to *meter.Address, gas uint64) (seOutput *setypes.ScriptEngineOutput, leftOverGas uint64, err error)

func (*Staking) UnBoundHandler

func (s *Staking) UnBoundHandler(env *setypes.ScriptEnv, sb *StakingBody, gas uint64) (leftOverGas uint64, err error)

func (*Staking) UnCandidateHandler

func (s *Staking) UnCandidateHandler(env *setypes.ScriptEnv, sb *StakingBody, gas uint64) (leftOverGas uint64, err error)

func (*Staking) UnDelegateHandler

func (s *Staking) UnDelegateHandler(env *setypes.ScriptEnv, sb *StakingBody, gas uint64) (leftOverGas uint64, err error)

type StakingBody

type StakingBody struct {
	Opcode          uint32
	Version         uint32
	Option          uint32
	HolderAddr      meter.Address
	CandAddr        meter.Address
	CandName        []byte
	CandDescription []byte
	CandPubKey      []byte //ecdsa.PublicKey
	CandIP          []byte
	CandPort        uint16
	StakingID       meter.Bytes32 // only for unbond
	Amount          *big.Int
	Token           byte   // meter or meter gov
	Autobid         uint8  // autobid percentile
	Timestamp       uint64 // staking timestamp
	Nonce           uint64 //staking nonce
	ExtraData       []byte
}

Candidate indicates the structure of a candidate

func DecodeFromBytes

func DecodeFromBytes(bytes []byte) (*StakingBody, error)

func (*StakingBody) String added in v1.2.0

func (sb *StakingBody) String() string

func (*StakingBody) ToString

func (sb *StakingBody) ToString() string

func (*StakingBody) UniteHash added in v1.2.0

func (sb *StakingBody) UniteHash() (hash meter.Bytes32)

func (*StakingBody) UniteHashWithoutExtraData added in v1.2.0

func (sb *StakingBody) UniteHashWithoutExtraData() (hash meter.Bytes32)

Jump to

Keyboard shortcuts

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