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.

views.gno

3.92 Kb · 148 lines
  1package core
  2
  3// MemberView is an inert membership record.
  4type MemberView struct {
  5	Address address
  6	Role    Role
  7}
  8
  9// MembershipReader is the read side of a membership set, implemented by the
 10// membership block and by adapters to shared membership realms.
 11type MembershipReader interface {
 12	// RoleOf returns addr's role, RoleNone for non-members.
 13	RoleOf(addr address) Role
 14	// Size returns the number of members.
 15	Size() int
 16	// Snapshot returns every member whose role is at least minRole, in a
 17	// stable order. ok is false (and the slice nil) when more than max
 18	// members qualify, so callers never act on a truncated electorate.
 19	// A negative max or an invalid minRole also yields (nil, false).
 20	Snapshot(minRole Role, max int) (addrs []address, ok bool)
 21}
 22
 23// AuthorizationPolicy decides whether an authenticated actor may perform a
 24// named operation. The actor must come from the realm's authenticated
 25// context, never from a caller-supplied argument.
 26type AuthorizationPolicy interface {
 27	Authorize(op string, actor address) error
 28}
 29
 30// BallotStatus is the lifecycle stage of a ballot.
 31type BallotStatus int
 32
 33const (
 34	BallotDraft BallotStatus = iota
 35	BallotOpen
 36	BallotFinalized
 37)
 38
 39func (s BallotStatus) String() string {
 40	switch s {
 41	case BallotDraft:
 42		return "draft"
 43	case BallotOpen:
 44		return "open"
 45	case BallotFinalized:
 46		return "finalized"
 47	}
 48	return "unknown"
 49}
 50
 51// BallotOutcome is the committed result of a finalized ballot.
 52type BallotOutcome int
 53
 54const (
 55	OutcomePending BallotOutcome = iota
 56	OutcomeWinner
 57	OutcomeTie
 58	OutcomeNoQuorum
 59	OutcomeNoVotes
 60)
 61
 62func (o BallotOutcome) String() string {
 63	switch o {
 64	case OutcomePending:
 65		return "pending"
 66	case OutcomeWinner:
 67		return "winner"
 68	case OutcomeTie:
 69		return "tie"
 70	case OutcomeNoQuorum:
 71		return "no-quorum"
 72	case OutcomeNoVotes:
 73		return "no-votes"
 74	}
 75	return "unknown"
 76}
 77
 78// BallotView is an inert summary of a ballot and its current tally.
 79type BallotView struct {
 80	ID             uint64
 81	Title          string
 82	Options        []string
 83	Status         BallotStatus
 84	Public         bool  // anyone may vote; no electorate snapshot
 85	ElectorateSize int   // 0 for public ballots
 86	QuorumPercent  int   // of the captured electorate
 87	OpenedAt       int64 // unix seconds, 0 while draft
 88	Deadline       int64 // unix seconds, 0 while draft
 89	Counts         []int // per option, same order as Options
 90	Abstentions    int
 91	Turnout        int // ballots cast, including abstentions
 92	Outcome        BallotOutcome
 93	Winner         int // option index when Outcome == OutcomeWinner, else -1
 94}
 95
 96// BallotReader is the read side of a ballot box.
 97type BallotReader interface {
 98	Ballot(id uint64) (BallotView, bool)
 99}
100
101// SubmissionStatus is the review state of a form submission.
102type SubmissionStatus int
103
104const (
105	SubmissionSubmitted SubmissionStatus = iota
106	SubmissionAccepted
107	SubmissionRejected
108)
109
110func (s SubmissionStatus) String() string {
111	switch s {
112	case SubmissionSubmitted:
113		return "submitted"
114	case SubmissionAccepted:
115		return "accepted"
116	case SubmissionRejected:
117		return "rejected"
118	}
119	return "unknown"
120}
121
122// SubmissionView is an inert copy of a submission.
123type SubmissionView struct {
124	ID        uint64
125	Submitter address
126	Answers   []string // in form field order
127	Status    SubmissionStatus
128}
129
130// SubmissionReader is the read side of a form.
131type SubmissionReader interface {
132	Submission(id uint64) (SubmissionView, bool)
133	// Submissions pages through submissions, optionally filtered by status
134	// (pass -1 for all), in submission order.
135	Submissions(status int, offset, limit int) []SubmissionView
136	Count() int
137}
138
139// AppDescriptor identifies how a realm was composed. Generated realms expose
140// one so the Lab can show an app's ingredients from the chain itself.
141type AppDescriptor struct {
142	Recipe            string
143	RecipeVersion     string
144	Components        []string // "<component-id>@<catalog-version>"
145	ConfigDigest      string
146	ViewSchemaVersion int
147	Bindings          []string // "<interface>=<pkgpath>"
148}