Search Apps Documentation Source Content File Folder Download Copy Actions Download

voting_context.gno

0.96 Kb · 37 lines
 1package commondao
 2
 3import "errors"
 4
 5// VotingContext contains current voting context, which includes a voting
 6// record for the votes that has been submitted for a proposal and also
 7// the list of DAO members.
 8type VotingContext struct {
 9	VotingRecord ReadonlyVotingRecord
10	Members      ReadonlyMemberStorage
11}
12
13// NewVotingContext creates a new voting context.
14func NewVotingContext(r *VotingRecord, s MemberStorage) (VotingContext, error) {
15	if r == nil {
16		return VotingContext{}, errors.New("voting record is required")
17	}
18
19	if s == nil {
20		return VotingContext{}, errors.New("member storage is required")
21	}
22
23	members := MustNewReadonlyMemberStorage(s)
24	return VotingContext{
25		VotingRecord: r.Readonly(),
26		Members:      *members,
27	}, nil
28}
29
30// MustNewVotingContext creates a new voting context or panics on error.
31func MustNewVotingContext(r *VotingRecord, s MemberStorage) VotingContext {
32	ctx, err := NewVotingContext(r, s)
33	if err != nil {
34		panic(err)
35	}
36	return ctx
37}