Documentation ¶
Index ¶
- Constants
- Variables
- func ApproveResolution(ctx context.Context, db sql.TxMaker, resolutionID types.UUID, expiration int64, ...) error
- func CreateResolution(ctx context.Context, db sql.TxMaker, event *types.VotableEvent, ...) error
- func DeleteResolutions(ctx context.Context, db sql.Executor, ids ...types.UUID) error
- func FilterExistsNoBody(ctx context.Context, db sql.Executor, ids ...types.UUID) ([]types.UUID, error)
- func FilterNotProcessed(ctx context.Context, db sql.Executor, ids ...types.UUID) ([]types.UUID, error)
- func GetExpired(ctx context.Context, db sql.Executor, blockheight int64) ([]*resolutions.Resolution, error)
- func GetResolutionIDsByTypeAndProposer(ctx context.Context, db sql.Executor, resType string, proposer []byte) ([]types.UUID, error)
- func GetResolutionInfo(ctx context.Context, db sql.Executor, id types.UUID) (*resolutions.Resolution, error)
- func GetResolutionsByThresholdAndType(ctx context.Context, db sql.TxMaker, threshold *big.Rat, resType string) ([]*resolutions.Resolution, error)
- func GetResolutionsByType(ctx context.Context, db sql.Executor, resType string) ([]*resolutions.Resolution, error)
- func GetValidatorPower(ctx context.Context, db sql.Executor, identifier []byte) (power int64, err error)
- func GetValidators(ctx context.Context, db sql.Executor) ([]*types.Validator, error)
- func HasVoted(ctx context.Context, tx sql.Executor, resolutionID types.UUID, from []byte) (bool, error)
- func InitializeVoteStore(ctx context.Context, db sql.DB) error
- func IsProcessed(ctx context.Context, tx sql.Executor, resolutionID types.UUID) (bool, error)
- func MarkProcessed(ctx context.Context, db sql.Executor, ids ...types.UUID) error
- func RequiredPower(ctx context.Context, db sql.Executor, threshold *big.Rat) (int64, error)
- func ResolutionContainsBody(ctx context.Context, db sql.Executor, id types.UUID) (bool, error)
- func SetValidatorPower(ctx context.Context, db sql.Executor, recipient []byte, power int64) error
- type UpdatePowerRequest
Constants ¶
const ( ValidatorJoinEventType = "validator_join" ValidatorRemoveEventType = "validator_remove" )
const ( ValidatorVoteBodyBytePrice = 1000 // Per byte cost ValidatorVoteIDPrice = 1000 * 16 // 16 bytes for the UUID )
Variables ¶
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 ¶
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 do exist but do not have a 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 ¶
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
InitializeVoteStore initializes the vote store with the required tables. It will also create any resolution types that have been registered.
func IsProcessed ¶
IsProcessed checks if a vote has been marked as processed.
func MarkProcessed ¶
MarkProcessed marks a set of resolutions as processed.
func RequiredPower ¶
RequiredPower gets the required power to meet the threshold requirements.
func ResolutionContainsBody ¶ added in v0.7.0
ResolutionContainsBody returns true if the resolution has a body.
func SetValidatorPower ¶
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 ¶
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