proposal_action_status.gno
2.27 Kb · 83 lines
1package governance
2
3import (
4 "errors"
5
6 "gno.land/r/gnoswap/gov/governance"
7)
8
9type ProposalActionStatusResolver struct {
10 *governance.ProposalActionStatus
11}
12
13// NewProposalActionStatusResolver wraps a proposal action status for mutation
14// and execution-state queries.
15//
16// Parameters:
17// - status: proposal action status to resolve and update.
18//
19// Returns:
20// - *ProposalActionStatusResolver: resolver backed by status.
21func NewProposalActionStatusResolver(status *governance.ProposalActionStatus) *ProposalActionStatusResolver {
22 return &ProposalActionStatusResolver{status}
23}
24
25// cancel marks the proposal as canceled and records cancellation details.
26// This method validates that the proposal is eligible for cancellation.
27//
28// Parameters:
29// - canceledAt: timestamp when cancellation occurred
30// - canceledHeight: block height when cancellation occurred
31// - canceledBy: address performing the cancellation
32//
33// Returns:
34// - error: already canceled error if proposal action status is already canceled
35func (p *ProposalActionStatusResolver) cancel(
36 canceledAt, canceledHeight int64,
37 canceledBy address,
38) error {
39 if p.Canceled() {
40 return errors.New(errAlreadyCanceledProposal)
41 }
42
43 // Record cancellation details
44 p.SetCanceled(true)
45 p.SetCanceledAt(canceledAt)
46 p.SetCanceledHeight(canceledHeight)
47 p.SetCanceledBy(canceledBy)
48
49 return nil
50}
51
52// Execute marks the proposal as executed and records execution details.
53// This method validates that the proposal is eligible for execution.
54//
55// Parameters:
56// - executedAt: Unix timestamp when execution occurred.
57// - executedHeight: block height when execution occurred.
58// - executedBy: address performing the execution.
59//
60// Returns:
61// - error: nil on success; an error when the proposal is not executable or
62// has already been canceled.
63func (p *ProposalActionStatusResolver) Execute(
64 executedAt, executedHeight int64,
65 executedBy address,
66) error {
67 // Only executable proposals can be executed (text proposals cannot)
68 if !p.IsExecutable() {
69 return errors.New(errProposalNotExecutable)
70 }
71
72 if p.Canceled() {
73 return errors.New(errAlreadyCanceledProposal)
74 }
75
76 // Record execution details
77 p.SetExecuted(true)
78 p.SetExecutedAt(executedAt)
79 p.SetExecutedHeight(executedHeight)
80 p.SetExecutedBy(executedBy)
81
82 return nil
83}