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

ballot/v0 package

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

Delegate

func Delegate(cur realm, toAddr string)

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.

Param

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/daily/ballot/v0" -func "Delegate" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/daily/ballot/v0" -func "Delegate" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx
  

GiveRightToVote

func GiveRightToVote(cur realm, voterAddr string)

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

Param

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/daily/ballot/v0" -func "GiveRightToVote" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/daily/ballot/v0" -func "GiveRightToVote" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx
  

Init

func Init(cur realm, proposalNamesCSV string)

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.

Param

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/daily/ballot/v0" -func "Init" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/daily/ballot/v0" -func "Init" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx
  

Render

func Render(path string) string

Param

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/daily/ballot/v0.Render()"

Result

Vote

func Vote(cur realm, proposalIndex int)

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

Param

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/daily/ballot/v0" -func "Vote" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/daily/ballot/v0" -func "Vote" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx
  

WinnerName

func WinnerName() string

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

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/daily/ballot/v0.WinnerName()"

Result

WinningProposal

func WinningProposal() int

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

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/daily/ballot/v0.WinningProposal()"

Result