-
Notifications
You must be signed in to change notification settings - Fork 364
/
proposal.go
137 lines (112 loc) · 4.64 KB
/
proposal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package types
import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
const (
ProposalTypeCommitteeChange = "CommitteeChange"
ProposalTypeCommitteeDelete = "CommitteeDelete"
)
// ProposalOutcome indicates the status of a proposal when it's closed and deleted from the store
type ProposalOutcome uint64
const (
// Passed indicates that the proposal passed and was successfully enacted
Passed ProposalOutcome = iota
// Failed indicates that the proposal failed and was not enacted
Failed
// Invalid indicates that proposal passed but an error occurred when attempting to enact it
Invalid
)
var toString = map[ProposalOutcome]string{
Passed: "Passed",
Failed: "Failed",
Invalid: "Invalid",
}
func (p ProposalOutcome) String() string {
return toString[p]
}
// ensure proposal types fulfill the PubProposal interface and the gov Content interface.
var _, _ govtypes.Content = &CommitteeChangeProposal{}, &CommitteeDeleteProposal{}
var _, _ PubProposal = &CommitteeChangeProposal{}, &CommitteeDeleteProposal{}
// ensure CommitteeChangeProposal fulfill the codectypes.UnpackInterfacesMessage interface
var _ codectypes.UnpackInterfacesMessage = &CommitteeChangeProposal{}
func init() {
// Gov proposals need to be registered on gov's ModuleCdc so MsgSubmitProposal can be encoded.
govtypes.RegisterProposalType(ProposalTypeCommitteeChange)
govtypes.RegisterProposalTypeCodec(CommitteeChangeProposal{}, "kava/CommitteeChangeProposal")
govtypes.RegisterProposalType(ProposalTypeCommitteeDelete)
govtypes.RegisterProposalTypeCodec(CommitteeDeleteProposal{}, "kava/CommitteeDeleteProposal")
}
func NewCommitteeChangeProposal(title string, description string, newCommittee Committee) (CommitteeChangeProposal, error) {
committeeAny, err := PackCommittee(newCommittee)
if err != nil {
return CommitteeChangeProposal{}, err
}
return CommitteeChangeProposal{
Title: title,
Description: description,
NewCommittee: committeeAny,
}, nil
}
func MustNewCommitteeChangeProposal(title string, description string, newCommittee Committee) CommitteeChangeProposal {
proposal, err := NewCommitteeChangeProposal(title, description, newCommittee)
if err != nil {
panic(err)
}
return proposal
}
// GetTitle returns the title of the proposal.
func (ccp CommitteeChangeProposal) GetTitle() string { return ccp.Title }
// GetDescription returns the description of the proposal.
func (ccp CommitteeChangeProposal) GetDescription() string { return ccp.Description }
// ProposalRoute returns the routing key of the proposal.
func (ccp CommitteeChangeProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of the proposal.
func (ccp CommitteeChangeProposal) ProposalType() string { return ProposalTypeCommitteeChange }
// GetNewCommittee returns the new committee of the proposal.
func (ccp CommitteeChangeProposal) GetNewCommittee() Committee {
committee, err := UnpackCommittee(ccp.NewCommittee)
if err != nil {
panic(err)
}
return committee
}
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (ccp CommitteeChangeProposal) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
var committee Committee
return unpacker.UnpackAny(ccp.NewCommittee, &committee)
}
// ValidateBasic runs basic stateless validity checks
func (ccp CommitteeChangeProposal) ValidateBasic() error {
if err := govtypes.ValidateAbstract(&ccp); err != nil {
return err
}
committee, err := UnpackCommittee(ccp.NewCommittee)
if err != nil {
return sdkerrors.Wrap(ErrInvalidCommittee, err.Error())
}
if err := committee.Validate(); err != nil {
return sdkerrors.Wrap(ErrInvalidCommittee, err.Error())
}
return nil
}
func NewCommitteeDeleteProposal(title string, description string, committeeID uint64) CommitteeDeleteProposal {
return CommitteeDeleteProposal{
Title: title,
Description: description,
CommitteeID: committeeID,
}
}
// GetTitle returns the title of the proposal.
func (cdp CommitteeDeleteProposal) GetTitle() string { return cdp.Title }
// GetDescription returns the description of the proposal.
func (cdp CommitteeDeleteProposal) GetDescription() string { return cdp.Description }
// ProposalRoute returns the routing key of the proposal.
func (cdp CommitteeDeleteProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of the proposal.
func (cdp CommitteeDeleteProposal) ProposalType() string { return ProposalTypeCommitteeDelete }
// ValidateBasic runs basic stateless validity checks
func (cdp CommitteeDeleteProposal) ValidateBasic() error {
return govtypes.ValidateAbstract(&cdp)
}