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