governance

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package governance implements the voting, quorum, and role logic for Guardian's constitutional governance system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEligibleVoters

func GetEligibleVoters(constitution *config.Constitution) []string

GetEligibleVoters returns a deduplicated list of email addresses from all roles that are designated as voters in the constitution. The deduplication ensures that a person appearing in multiple voter roles is counted only once.

func GetUserRoles

func GetUserRoles(constitution *config.Constitution, email string) []string

GetUserRoles returns the list of role names that a given email address belongs to. It checks all roles defined in the constitution, not just voter roles.

func IsVoter

func IsVoter(constitution *config.Constitution, email string) bool

IsVoter checks if the given email belongs to any of the voter roles defined in the constitution.

Types

type QuorumResult

type QuorumResult struct {
	Required      int
	YesVotes      int
	NoVotes       int
	TotalEligible int
	Result        string // ACCEPTED|REJECTED|PENDING|EXPIRED
}

QuorumResult holds the result of a quorum calculation.

func CalculateQuorum

func CalculateQuorum(qc config.QuorumConfig, totalEligible int, yesVotes int, noVotes int) *QuorumResult

CalculateQuorum computes the quorum result based on the given configuration, total eligible voters, and the current vote counts.

Quorum types:

  • majority: required = totalEligible/2 + 1
  • two_thirds: required = ceil(totalEligible * 2/3)
  • unanimous: required = totalEligible
  • custom: required = ceil(totalEligible * threshold)

Result determination:

  • ACCEPTED if yesVotes >= required
  • REJECTED if noVotes > (totalEligible - required), meaning there are not enough remaining voters for yes to reach the threshold
  • PENDING otherwise

type TallyResult

type TallyResult struct {
	ProposalID     string
	RuleID         string
	EligibleVoters []string
	Votes          []*config.Vote
	QuorumResult   *QuorumResult
	QuorumConfig   config.QuorumConfig
	IsExpired      bool
}

TallyResult is the full tally of a proposal including voter information, vote counts, quorum calculation, and expiry status.

func ComputeTally

func ComputeTally(
	proposal *config.Proposal,
	votes []*config.Vote,
	constitution *config.Constitution,
) *TallyResult

ComputeTally calculates the full tally for a proposal given its votes and the constitution. It handles:

  • Eligible voter determination (deduplicated by email)
  • Per-rule quorum overrides
  • Vote counting (only from eligible voters)
  • TTL expiry checking
  • Final quorum computation

Jump to

Keyboard shortcuts

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