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

v0 source realm

Package ballot is a Gno port of the classic Solidity "Ballot" voting contract from the Solidity docs. A chairperson s...

Readme View source

Ballot

⚠️ Experimental — generated with no human supervision by the daily MCP pipeline to exercise gno tooling. Not audited. See r/moul/x/daily.


A Gno port of the classic Solidity "Ballot" voting contract: a chairperson seeds a fixed list of proposals and grants specific addresses the right to vote, and each voter either casts a direct vote or delegates their weight down a delegation chain (with a loop guard, just like the original). WinningProposal/WinnerName report the current leader live, so there's no separate close-the-vote step. It's neat because delegation composability - a delegate's weight can itself be re-delegated - is the one part of the original contract that's easy to get subtly wrong, and this port keeps that chain-walking + cycle-detection logic faithful while swapping mappings for an avl.Tree.

Built for gno 0.9.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

Dependency graph:

gno.land/r/moul/x/daily/ballot/v0 dependency graph

🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.

Overview

Package ballot is a Gno port of the classic Solidity "Ballot" voting contract from the Solidity docs. A chairperson seeds a fixed list of proposals and grants specific addresses the right to vote; each voter can either cast a direct vote or delegate their weight to another voter, and delegation follows a chain so a delegate who later delegates further still carries every accumulated weight. The winning proposal is whichever has the most accumulated weight at query time.

Functions 7

func Delegate

crossing Action
1func Delegate(cur realm, toAddr string)
source

Delegate hands the caller's voting weight to toAddr. If toAddr has already voted, the weight is added directly to that proposal's tally; otherwise it accumulates on toAddr's own weight, ready to be cast (or delegated further) later. Mirrors Solidity's delegation-chain-following with a loop guard.

func GiveRightToVote

crossing Action
1func GiveRightToVote(cur realm, voterAddr string)
source

GiveRightToVote grants voterAddr a voting weight of 1. Only the chairperson may call this, and only for voters who haven't voted yet.

func Init

crossing Action
1func Init(cur realm, proposalNamesCSV string)
source

Init configures the ballot exactly once: the caller becomes the chairperson (and is immediately given the right to vote), and proposalNamesCSV — a comma-separated list — seeds the fixed set of proposals. It panics if called twice or with no usable proposal names.

func Vote

crossing Action
1func Vote(cur realm, proposalIndex int)
source

Vote casts the caller's full weight for proposals[proposalIndex].

func WinnerName

Action
1func WinnerName() string
source

WinnerName returns the name of the current winning proposal, or "" if the ballot hasn't been initialized.

func WinningProposal

Action
1func WinningProposal() int
source

WinningProposal returns the index of the proposal with the most accumulated weight, breaking ties in favor of the lowest index.

Imports 4

Source Files 3