Skip to content

Commit

Permalink
Add execution failed ProposalStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicmilos committed Jul 14, 2024
1 parent 322bc8c commit 794a353
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
14 changes: 9 additions & 5 deletions examples/gno.land/p/demo/simpledao/dao.gno
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ func (s *SimpleDAO) VoteOnProposal(id uint64, option dao.VoteOption) error {
prop := propRaw.(*proposal)

// Check the proposal status
if prop.GetStatus() == dao.Executed {
if prop.GetStatus() == dao.ExecutionSuccessful ||
prop.GetStatus() == dao.ExecutionFailed {
// Proposal was already executed, nothing to vote on anymore.
//
// In fact, the proposal should stop accepting
Expand Down Expand Up @@ -159,7 +160,8 @@ func (s *SimpleDAO) ExecuteProposal(id uint64) error {
}

// Check if the proposal is executed
if prop.GetStatus() == dao.Executed {
if prop.GetStatus() == dao.ExecutionSuccessful ||
prop.GetStatus() == dao.ExecutionFailed {
// Proposal is already executed
return errProposalExecuted
}
Expand All @@ -169,14 +171,16 @@ func (s *SimpleDAO) ExecuteProposal(id uint64) error {
return errProposalExpired
}

// Update the proposal status
prop.status = dao.Executed

// Attempt to execute the proposal
if err = prop.executor.Execute(); err != nil {
prop.status = dao.ExecutionFailed

return ufmt.Errorf("error during proposal %d execution, %s", id, err)
}

// Update the proposal status
prop.status = dao.ExecutionSuccessful

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions examples/gno.land/p/demo/simpledao/propstore.gno
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type proposal struct {
description string // description of the proposal

executor pproposal.Executor // executor for the proposal
status dao.Status // status of the proposal
status dao.ProposalStatus // status of the proposal

votes *votes // voting mechanism
}
Expand All @@ -38,7 +38,7 @@ func (p *proposal) GetDescription() string {
return p.description
}

func (p *proposal) GetStatus() dao.Status {
func (p *proposal) GetStatus() dao.ProposalStatus {
return p.status
}

Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/p/demo/simpledao/propstore_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestProposal_Data(t *testing.T) {
t.Parallel()

p := &proposal{
status: dao.Executed,
status: dao.ExecutionSuccessful,
}

uassert.Equal(t, p.status.String(), p.GetStatus().String())
Expand Down
17 changes: 9 additions & 8 deletions examples/gno.land/p/gov/dao/proposal.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package dao

import "std"

type Status string
type ProposalStatus string

// ACTIVE -> ACCEPTED -> EXECUTED
// ACTIVE -> ACCEPTED -> EXECUTION(SUCCEEDED/FAILED)
// ACTIVE -> NOT ACCEPTED
var (
Active Status = "active" // proposal is still active
Accepted Status = "accepted" // proposal gathered quorum
NotAccepted Status = "not accepted" // proposal failed to gather quorum
Executed Status = "executed" // proposal is executed
Active ProposalStatus = "active" // proposal is still active
Accepted ProposalStatus = "accepted" // proposal gathered quorum
NotAccepted ProposalStatus = "not accepted" // proposal failed to gather quorum
ExecutionSuccessful ProposalStatus = "execution successful" // proposal is executed successfully
ExecutionFailed ProposalStatus = "execution failed" // proposal is failed during execution
)

func (s Status) String() string {
func (s ProposalStatus) String() string {
return string(s)
}

Expand All @@ -40,7 +41,7 @@ type Proposal interface {
GetDescription() string

// GetStatus returns the status of the proposal
GetStatus() Status
GetStatus() ProposalStatus

// GetVotes returns the votes of the proposal
GetVotes() []Vote
Expand Down

0 comments on commit 794a353

Please sign in to comment.