Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v1 source pure

Package ballots is the Remix Lab public-ballot block: single-choice polls with fixed options, an electorate captured ...

Overview

Package ballots is the Remix Lab public-ballot block: single-choice polls with fixed options, an electorate captured at opening, one vote per eligible address, integer quorum and deterministic tie handling.

Lifecycle: Create (draft) -> Open (options, rules and electorate freeze; the deadline starts) -> Finalize (any caller, once the deadline passed). A draft can be cancelled, which removes it. Early closure of an open ballot is not supported. Deadlines are only evaluated when a transaction or read happens; nothing closes a ballot automatically.

MaxBallots bounds ballots that are not finalized (drafts and open ballots), so finalized history never blocks new ballots. Public ballots bound neither voters nor votes; each voter pays for their own vote's storage and nothing iterates over votes.

Like every Remix Lab block, a *Box must stay in an unexported host-realm variable. The host authenticates callers and passes their address; the Box never trusts an address it did not receive from the host.

Constants 2

const Abstain

1const Abstain = -1
source

Abstain is the choice value for an abstention.

Functions 2

func NewBox

1func NewBox(cfg Config) *Box
source

NewBox creates an empty box. It panics on invalid configuration.

func DefaultConfig

1func DefaultConfig() Config
source

DefaultConfig returns the starting limits proposed for the MVP.

Types 2

type Box

struct
1type Box struct {
2	cfg     Config
3	ballots *avl.Tree // zero-padded id -> *ballot
4	nextID  uint64
5	active  int // drafts plus open ballots
6}
source

Box holds a bounded set of ballots.

Methods on Box

func Active

method on Box
1func (b *Box) Active() int
source

Active returns the number of drafts and open ballots.

func Ballot

method on Box
1func (b *Box) Ballot(id uint64) (core.BallotView, bool)
source

Ballot implements core.BallotReader.

func CancelDraft

method on Box
1func (b *Box) CancelDraft(id uint64) error
source

CancelDraft removes a ballot that was never opened. The host must have authorized the actor.

func Config

method on Box
1func (b *Box) Config() Config
source

Config returns the box configuration.

func Count

method on Box
1func (b *Box) Count() int
source

Count returns the number of ballots, finalized ones included.

func Create

method on Box
1func (b *Box) Create(creator address, title string, options []string, duration int64) (uint64, error)
source

Create adds a draft ballot. Options are copied. creator must be the authenticated caller.

func Creator

method on Box
1func (b *Box) Creator(id uint64) (address, bool)
source

Creator returns the address that created ballot id.

func Eligible

method on Box
1func (b *Box) Eligible(id uint64, voter address) bool
source

Eligible reports whether voter belongs to an open ballot's electorate. It ignores the deadline and whether voter has already voted.

func Finalize

method on Box
1func (b *Box) Finalize(id uint64, now int64) (core.BallotView, error)
source

Finalize commits the result once the deadline has passed. Any caller may finalize; the outcome depends only on rules fixed at opening.

func HasVoted

method on Box
1func (b *Box) HasVoted(id uint64, voter address) bool
source

HasVoted reports whether voter has cast a ballot (including abstention).

func InElectorate

method on Box
1func (b *Box) InElectorate(id uint64, voter address) bool
source

InElectorate reports whether voter belongs to the ballot's frozen electorate (always true for public ballots once open).

func List

method on Box
1func (b *Box) List(offset, limit int) []core.BallotView
source

List returns up to limit ballots, newest first.

func OpenPublic

method on Box
1func (b *Box) OpenPublic(id uint64, now int64) error
source

OpenPublic opens a draft ballot to any address. Percentage quorum needs a known electorate, so public ballots require QuorumPercent == 0.

func OpenWithElectorate

method on Box
1func (b *Box) OpenWithElectorate(id uint64, now int64, voters []address) error
source

OpenWithElectorate opens a draft ballot restricted to voters. The list is copied; later membership changes do not affect this ballot.

func Vote

method on Box
1func (b *Box) Vote(id uint64, voter address, choice int, now int64) error
source

Vote records voter's choice. voter must be the authenticated caller. Votes are final.

type Config

struct
 1type Config struct {
 2	MaxBallots     int // drafts plus open ballots at any one time
 3	MaxOptions     int
 4	MaxElectorate  int
 5	QuorumPercent  int   // 0..100, of the captured electorate
 6	AllowAbstain   bool  // voters may cast an explicit abstention
 7	MinDuration    int64 // seconds
 8	MaxDuration    int64 // seconds
 9	MaxTitleBytes  int
10	MaxOptionBytes int
11}
source

Config is fixed at construction. Each ballot copies the rules it depends on when it is created, so they never change underneath an open ballot.

Methods on Config

func Validate

method on Config
1func (c Config) Validate() error
source

Validate checks configuration bounds.

Dependencies

Source Files 2