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