types

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: GPL-3.0 Imports: 15 Imported by: 5 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidProto = errors.New("Invalid election proto")

ErrInvalidProto indicates a format error of an election proto

Functions

func CalcWeightedVotes added in v0.1.11

func CalcWeightedVotes(v *Bucket, now time.Time) *big.Int

CalcWeightedVotes calculates the weighted votes based on time

Types

type Bucket added in v0.2.0

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

Bucket defines a bucket stored in staking contract

func NewBucket added in v0.2.0

func NewBucket(
	startTime time.Time,
	duration time.Duration,
	amount *big.Int,
	voter []byte,
	candidate []byte,
	decay bool,
) (*Bucket, error)

NewBucket creates a new bucket

func (*Bucket) Amount added in v0.2.0

func (bucket *Bucket) Amount() *big.Int

Amount returns the amount of bucket

func (*Bucket) Candidate added in v0.2.0

func (bucket *Bucket) Candidate() []byte

Candidate returns the candidate

func (*Bucket) Clone added in v0.2.0

func (bucket *Bucket) Clone() *Bucket

Clone clones the bucket

func (*Bucket) Decay added in v0.2.0

func (bucket *Bucket) Decay() bool

Decay returns whether this is a decay bucket

func (*Bucket) Deserialize added in v0.2.0

func (bucket *Bucket) Deserialize(data []byte) error

Deserialize deserializes a byte array to bucket

func (*Bucket) Duration added in v0.2.0

func (bucket *Bucket) Duration() time.Duration

Duration returns the duration of this bucket

func (*Bucket) Equal added in v0.2.0

func (bucket *Bucket) Equal(b *Bucket) bool

Equal returns true if two buckets are of the same values

func (*Bucket) FromProtoMsg added in v0.2.0

func (bucket *Bucket) FromProtoMsg(vPb *pb.Bucket) (err error)

FromProtoMsg extracts bucket details from protobuf message (voteCore)

func (*Bucket) Hash added in v0.2.0

func (bucket *Bucket) Hash() (hash.Hash256, error)

Hash returns the hash

func (*Bucket) RemainingTime added in v0.2.0

func (bucket *Bucket) RemainingTime(now time.Time) time.Duration

RemainingTime returns the remaining time to given time

func (*Bucket) Serialize added in v0.2.0

func (bucket *Bucket) Serialize() ([]byte, error)

Serialize serializes the bucket to bytes

func (*Bucket) StartTime added in v0.2.0

func (bucket *Bucket) StartTime() time.Time

StartTime returns the start time

func (*Bucket) ToProtoMsg added in v0.2.0

func (bucket *Bucket) ToProtoMsg() (*pb.Bucket, error)

ToProtoMsg converts the bucket to protobuf

func (*Bucket) Voter added in v0.2.0

func (bucket *Bucket) Voter() []byte

Voter returns the voter address in bytes

type BucketFilterFunc added in v0.2.0

type BucketFilterFunc func(*Bucket) bool

BucketFilterFunc defines the function to filter vote

type Candidate

type Candidate struct {
	Registration
	// contains filtered or unexported fields
}

Candidate defines a delegate candidate

func NewCandidate

func NewCandidate(
	reg *Registration,
	score *big.Int,
	selfStakingTokens *big.Int,
) *Candidate

NewCandidate creates a new candidate with scores as 0s

func (*Candidate) Clone

func (c *Candidate) Clone() *Candidate

Clone clones the candidate

func (*Candidate) Equal added in v0.2.0

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

Equal returns true if two candidates are identical

func (*Candidate) FromProtoMsg

func (c *Candidate) FromProtoMsg(msg *pb.Candidate) error

FromProtoMsg fills the instance with a protobuf message

func (*Candidate) Score

func (c *Candidate) Score() *big.Int

Score returns the total votes (weighted) of this candidate

func (*Candidate) SelfStakingTokens

func (c *Candidate) SelfStakingTokens() *big.Int

SelfStakingTokens returns the total self votes (weighted)

func (*Candidate) SetScore added in v0.1.5

func (c *Candidate) SetScore(score *big.Int)

SetScore set score value in Candidate

func (*Candidate) SetSelfStakingTokens added in v0.1.5

func (c *Candidate) SetSelfStakingTokens(selfStakingTokens *big.Int)

SetSelfStakingTokens set selfStakingTokens value in Candidate

func (*Candidate) ToProtoMsg

func (c *Candidate) ToProtoMsg() (*pb.Candidate, error)

ToProtoMsg converts the instance to a protobuf message

type CandidateFilterFunc

type CandidateFilterFunc func(*Candidate) bool

CandidateFilterFunc defines the function to filter candidate

type ElectionResult

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

ElectionResult defines the collection of voting result on a height

func NewElectionResultForTest

func NewElectionResultForTest(
	mintTime time.Time,
) *ElectionResult

NewElectionResultForTest creates an election result for test purpose only

func (*ElectionResult) DelegateByName added in v0.1.8

func (r *ElectionResult) DelegateByName(name []byte) *Candidate

DelegateByName returns the candidate details

func (*ElectionResult) Delegates

func (r *ElectionResult) Delegates() []*Candidate

Delegates returns a list of sorted delegates

func (*ElectionResult) Deserialize

func (r *ElectionResult) Deserialize(data []byte) error

Deserialize converts a byte array to election result

func (*ElectionResult) Equal added in v0.2.0

func (r *ElectionResult) Equal(result *ElectionResult) bool

Equal compares two results and returns true if they are identical

func (*ElectionResult) FromProtoMsg

func (r *ElectionResult) FromProtoMsg(rPb *pb.ElectionResult) (err error)

FromProtoMsg extracts result details from protobuf message

func (*ElectionResult) MintTime

func (r *ElectionResult) MintTime() time.Time

MintTime returns the mint time of the corresponding gravity chain block

func (*ElectionResult) Serialize

func (r *ElectionResult) Serialize() ([]byte, error)

Serialize converts result to byte array

func (*ElectionResult) String added in v0.1.4

func (r *ElectionResult) String() string

func (*ElectionResult) ToProtoMsg

func (r *ElectionResult) ToProtoMsg() (*pb.ElectionResult, error)

ToProtoMsg converts the vote to protobuf

func (*ElectionResult) TotalVotedStakes

func (r *ElectionResult) TotalVotedStakes() *big.Int

TotalVotedStakes returns the total amount of stakings which has been voted

func (*ElectionResult) TotalVotes

func (r *ElectionResult) TotalVotes() *big.Int

TotalVotes returns the total votes in the result

func (*ElectionResult) Votes added in v0.1.18

func (r *ElectionResult) Votes() []*Vote

Votes returns all votes

func (*ElectionResult) VotesByDelegate

func (r *ElectionResult) VotesByDelegate(name []byte) []*Vote

VotesByDelegate returns a list of votes for a given delegate

type Poll added in v0.2.0

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

Poll defines the struct stores election result in db

func NewPoll added in v0.2.0

func NewPoll(
	buckets [][]byte,
	regs [][]byte,
) *Poll

NewPoll creates a new electionresultMeta

func (*Poll) Buckets added in v0.2.0

func (m *Poll) Buckets() [][]byte

Buckets returns all buckets

func (*Poll) Deserialize added in v0.2.0

func (m *Poll) Deserialize(data []byte) error

Deserialize converts a byte array to election result

func (*Poll) FromProtoMsg added in v0.2.0

func (m *Poll) FromProtoMsg(rPb *pb.Poll) (err error)

FromProtoMsg extracts result details from protobuf message

func (*Poll) Registrations added in v0.2.0

func (m *Poll) Registrations() [][]byte

Registrations returns a list of Registrations

func (*Poll) Serialize added in v0.2.0

func (m *Poll) Serialize() ([]byte, error)

Serialize converts result to byte array

func (*Poll) ToProtoMsg added in v0.2.0

func (m *Poll) ToProtoMsg() (*pb.Poll, error)

ToProtoMsg converts the electionresultMeta to protobuf

type Registration added in v0.2.0

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

Registration defines a registration in contract

func NewRegistration added in v0.2.0

func NewRegistration(
	name []byte,
	address []byte,
	operatorAddress []byte,
	rewardPubKey []byte,
	selfStakingWeight uint64,
) *Registration

NewRegistration creates a new registration

func (*Registration) Address added in v0.2.0

func (reg *Registration) Address() []byte

Address returns the address of this candidate on gravity chain

func (*Registration) Clone added in v0.2.0

func (reg *Registration) Clone() *Registration

Clone clones the registration

func (*Registration) Deserialize added in v0.2.0

func (reg *Registration) Deserialize(data []byte) error

Deserialize deserializes a byte array to candidate

func (*Registration) Equal added in v0.2.0

func (reg *Registration) Equal(r *Registration) bool

Equal returns true if two candidates are identical

func (*Registration) FromProtoMsg added in v0.2.0

func (reg *Registration) FromProtoMsg(msg *pb.Registration) error

FromProtoMsg fills the instance with a protobuf message (CandidateCore)

func (*Registration) Hash added in v0.2.0

func (reg *Registration) Hash() (hash.Hash256, error)

Hash returns the hash of serialized data

func (*Registration) Name added in v0.2.0

func (reg *Registration) Name() []byte

Name returns the name of this candidate

func (*Registration) OperatorAddress added in v0.2.0

func (reg *Registration) OperatorAddress() []byte

OperatorAddress returns the address of the assigned operator on chain

func (*Registration) RewardAddress added in v0.2.0

func (reg *Registration) RewardAddress() []byte

RewardAddress returns the address of the assigned benefiter on chain

func (*Registration) SelfStakingWeight added in v0.2.0

func (reg *Registration) SelfStakingWeight() uint64

SelfStakingWeight returns the extra weight for self staking

func (*Registration) Serialize added in v0.2.0

func (reg *Registration) Serialize() ([]byte, error)

Serialize serializes the candidate to bytes

func (*Registration) ToProtoMsg added in v0.2.0

func (reg *Registration) ToProtoMsg() (*pb.Registration, error)

ToProtoMsg converts the instance to a protobuf message (CandidateCore)

type ResultCalculator

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

ResultCalculator defines a calculator for a set of votes

func NewResultCalculator

func NewResultCalculator(
	mintTime time.Time,
	skipManified bool,
	bucketFilter BucketFilterFunc,
	calcScore func(*Bucket, time.Time) *big.Int,
	candidateFilter CandidateFilterFunc,
) *ResultCalculator

NewResultCalculator creates a result calculator

func (*ResultCalculator) AddBuckets added in v0.2.0

func (calculator *ResultCalculator) AddBuckets(buckets []*Bucket) error

AddBuckets adds bucket to result

func (*ResultCalculator) AddRegistrations added in v0.2.0

func (calculator *ResultCalculator) AddRegistrations(candidates []*Registration) error

AddRegistrations adds candidates to result

func (*ResultCalculator) Calculate

func (calculator *ResultCalculator) Calculate() (*ElectionResult, error)

Calculate summaries the result with candidates and votes added

type Vote

type Vote struct {
	Bucket
	// contains filtered or unexported fields
}

Vote defines the structure of a vote

func NewVote

func NewVote(
	bucket *Bucket,
	weighted *big.Int,
) (*Vote, error)

NewVote creates a new vote

func (*Vote) Clone

func (v *Vote) Clone() *Vote

Clone clones the vote

func (*Vote) Deserialize

func (v *Vote) Deserialize(data []byte) error

Deserialize deserializes a byte array to vote

func (*Vote) Equal added in v0.2.0

func (v *Vote) Equal(vote *Vote) bool

Equal returns true if two candidates are identical

func (*Vote) FromProtoMsg

func (v *Vote) FromProtoMsg(vPb *pb.Vote) (err error)

FromProtoMsg extracts vote details from protobuf message

func (*Vote) Serialize

func (v *Vote) Serialize() ([]byte, error)

Serialize serializes the vote to bytes

func (*Vote) SetWeightedAmount

func (v *Vote) SetWeightedAmount(w *big.Int) error

SetWeightedAmount sets the weighted amount for the vote

func (*Vote) ToProtoMsg

func (v *Vote) ToProtoMsg() (*pb.Vote, error)

ToProtoMsg converts the vote to protobuf

func (*Vote) WeightedAmount

func (v *Vote) WeightedAmount() *big.Int

WeightedAmount returns the weighted amount of vote

Jump to

Keyboard shortcuts

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