contribution.gno
1.47 Kb ยท 69 lines
1package evaluation
2
3import (
4 "time"
5)
6
7var contributionStatus = map[string]string{}
8
9type Contribution struct {
10 id int
11 contributor address
12 status string // approved, proposed, negotiation, discussion, evaluation, etc.
13 votes []Vote
14 tallyResult TallyResult
15 submitTime time.Time
16 lastEvaluateTime time.Time
17 approveTime time.Time
18}
19
20func init() {
21 contributionStatus = make(map[string]string)
22 contributionStatus["Proposed"] = "Proposed"
23 contributionStatus["Approved"] = "Approved"
24 contributionStatus["Evaluated"] = "Evaluated"
25 contributionStatus["Negotiated"] = "Negotiated"
26}
27
28func NewContribution(id int, contributor address) *Contribution {
29 c := &Contribution{
30 id: id,
31 contributor: contributor,
32 status: contributionStatus["Proposed"],
33 votes: []Vote{},
34 tallyResult: TallyResult{},
35 }
36 return c
37}
38
39func (c Contribution) Id() int {
40 return c.id
41}
42
43func (c Contribution) Status() string {
44 return c.status
45}
46
47func (c *Contribution) UpdateStatus(status string) bool {
48 if c.status == contributionStatus["Approved"] {
49 return false
50 }
51 c.status = status
52 return true
53}
54
55func (c *Contribution) Approve() {
56 // TODO error handling
57 c.status = "Approved"
58}
59
60func (c *Contribution) Tally() {
61 // TODO error handling
62 for _, v := range c.votes {
63 if c.tallyResult.results.Has(v.option) {
64 value, _ := c.tallyResult.results.Get(v.option)
65 count := value.(int)
66 c.tallyResult.results.Set(v.option, count+1)
67 }
68 }
69}