voting

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ValidatorJoinEventType   = "validator_join"
	ValidatorRemoveEventType = "validator_remove"
)
View Source
const (
	ValidatorVoteBodyBytePrice = 1000      // Per byte cost
	ValidatorVoteIDPrice       = 1000 * 16 // 16 bytes for the UUID
)

Variables

View Source
var (
	ErrAlreadyProcessed         = errors.New("resolution already processed")
	ErrResolutionAlreadyHasBody = errors.New("resolution already has a body")
)

Functions

func ApproveResolution

func ApproveResolution(ctx context.Context, db sql.TxMaker, resolutionID types.UUID, expiration int64, from []byte) error

Approve approves a resolution from a voter. If the resolution does not yet exist, it will be created. If created, it will not be given a body, and can be given a body later. If the resolution already exists, it will simply track that the voter has approved the resolution, and will not change the body or expiration. If the voter does not exist, an error will be returned. If the voter has already approved the resolution, no error will be returned. If the resolution has already been processed, no error will be returned.

func CreateResolution

func CreateResolution(ctx context.Context, db sql.TxMaker, event *types.VotableEvent, expiration int64, voteBodyProposer []byte) error

CreateResolution creates a vote, by submitting a body of a vote, a topic and an expiration. The expiration should be a blockheight. If the resolution already exists, it will not be changed. If the resolution was already processed, nothing will happen.

func DeleteResolutions

func DeleteResolutions(ctx context.Context, db sql.Executor, ids ...types.UUID) error

DeleteResolutions deletes a slice of resolution IDs from the database. It will mark the resolutions as processed in the processed table.

func FilterExistsNoBody added in v0.7.0

func FilterExistsNoBody(ctx context.Context, db sql.Executor, ids ...types.UUID) ([]types.UUID, error)

FilterExistsNoBody takes a set of resolutions and returns the ones that either do not exist or exists but doesn't have the resolution body

func FilterNotProcessed

func FilterNotProcessed(ctx context.Context, db sql.Executor, ids ...types.UUID) ([]types.UUID, error)

FilterNotProcessed takes a set of resolutions and returns the ones that have not been processed. If a resolution does not exist, it WILL be included in the result.

func GetExpired

func GetExpired(ctx context.Context, db sql.Executor, blockheight int64) ([]*resolutions.Resolution, error)

GetExpired returns all resolutions with an expiration less than or equal to the given blockheight.

func GetResolutionIDsByTypeAndProposer

func GetResolutionIDsByTypeAndProposer(ctx context.Context, db sql.Executor, resType string, proposer []byte) ([]types.UUID, error)

GetResolutionIDsByTypeAndProposer gets all resolution ids of a specific type and the body proposer.

func GetResolutionInfo

func GetResolutionInfo(ctx context.Context, db sql.Executor, id types.UUID) (*resolutions.Resolution, error)

GetResolutionInfo gets a resolution, identified by the ID.

func GetResolutionsByThresholdAndType

func GetResolutionsByThresholdAndType(ctx context.Context, db sql.TxMaker, threshold *big.Rat, resType string) ([]*resolutions.Resolution, error)

GetResolutionsByThresholdAndType gets all resolutions that have reached the threshold of votes and are of a specific type.

func GetResolutionsByType

func GetResolutionsByType(ctx context.Context, db sql.Executor, resType string) ([]*resolutions.Resolution, error)

GetResolutionsByType gets all resolutions of a specific type.

func GetValidatorPower

func GetValidatorPower(ctx context.Context, db sql.Executor, identifier []byte) (power int64, err error)

GetValidatorPower gets the power of a voter. If the voter does not exist, it will return 0.

func GetValidators

func GetValidators(ctx context.Context, db sql.Executor) ([]*types.Validator, error)

GetValidators gets all voters in the vote store, along with their power.

func HasVoted added in v0.7.0

func HasVoted(ctx context.Context, tx sql.Executor, resolutionID types.UUID, from []byte) (bool, error)

HasVoted checks if a voter has voted on a resolution.

func InitializeVoteStore added in v0.7.0

func InitializeVoteStore(ctx context.Context, db sql.DB) error

InitializeVoteStore initializes the vote store with the required tables. It will also create any resolution types that have been registered.

func IsProcessed

func IsProcessed(ctx context.Context, tx sql.Executor, resolutionID types.UUID) (bool, error)

IsProcessed checks if a vote has been marked as processed.

func MarkProcessed

func MarkProcessed(ctx context.Context, db sql.Executor, ids ...types.UUID) error

MarkProcessed marks a set of resolutions as processed.

func RequiredPower

func RequiredPower(ctx context.Context, db sql.Executor, threshold *big.Rat) (int64, error)

RequiredPower gets the required power to meet the threshold requirements.

func ResolutionContainsBody added in v0.7.0

func ResolutionContainsBody(ctx context.Context, db sql.Executor, id types.UUID) (bool, error)

ResolutionContainsBody returns true if the resolution has a body.

func SetValidatorPower

func SetValidatorPower(ctx context.Context, db sql.Executor, recipient []byte, power int64) error

SetValidatorPower sets the power of a voter. It will create the voter if it does not exist. It will return an error if a negative power is given. If set to 0, the voter will be deleted.

Types

type UpdatePowerRequest

type UpdatePowerRequest struct {
	PubKey []byte
	Power  int64
}

UpdatePowerRequest is a request to update a validator's power.

func (*UpdatePowerRequest) MarshalBinary

func (j *UpdatePowerRequest) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary representation of the join request It is deterministic

func (*UpdatePowerRequest) UnmarshalBinary

func (j *UpdatePowerRequest) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals the join request from its binary representation

Jump to

Keyboard shortcuts

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