Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

proposal_action_status.gno

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