forked from terra-money/alliance
/
gov.go
157 lines (130 loc) · 6.19 KB
/
gov.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package types
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
const (
ProposalTypeCreateAlliance = "msg_create_alliance_proposal"
ProposalTypeUpdateAlliance = "msg_update_alliance_proposal"
ProposalTypeDeleteAlliance = "msg_delete_alliance_proposal"
)
var (
_ govtypes.Content = &MsgCreateAllianceProposal{}
_ govtypes.Content = &MsgUpdateAllianceProposal{}
_ govtypes.Content = &MsgDeleteAllianceProposal{}
)
func init() {
govtypes.RegisterProposalType(ProposalTypeCreateAlliance)
govtypes.RegisterProposalType(ProposalTypeUpdateAlliance)
govtypes.RegisterProposalType(ProposalTypeDeleteAlliance)
}
func NewMsgCreateAllianceProposal(title, description, denom string, rewardWeight sdk.Dec, rewardWeightRange RewardWeightRange, consensusWeight sdk.Dec, consensusCap sdk.Dec, takeRate sdk.Dec, rewardChangeRate sdk.Dec, rewardChangeInterval time.Duration) govtypes.Content {
return &MsgCreateAllianceProposal{
Title: title,
Description: description,
Denom: denom,
RewardWeight: rewardWeight,
RewardWeightRange: rewardWeightRange,
ConsensusWeight: consensusWeight,
ConsensusCap: consensusCap,
TakeRate: takeRate,
RewardChangeRate: rewardChangeRate,
RewardChangeInterval: rewardChangeInterval,
}
}
func (m *MsgCreateAllianceProposal) GetTitle() string { return m.Title }
func (m *MsgCreateAllianceProposal) GetDescription() string { return m.Description }
func (m *MsgCreateAllianceProposal) ProposalRoute() string { return RouterKey }
func (m *MsgCreateAllianceProposal) ProposalType() string { return ProposalTypeCreateAlliance }
func (m *MsgCreateAllianceProposal) ValidateBasic() error {
if m.Denom == "" {
return status.Errorf(codes.InvalidArgument, "Alliance denom must have a value")
}
if err := sdk.ValidateDenom(m.Denom); err != nil {
return err
}
if m.RewardWeight.IsNil() || m.RewardWeight.LT(sdk.ZeroDec()) {
return status.Errorf(codes.InvalidArgument, "Alliance rewardWeight must be zero or a positive number")
}
if m.ConsensusWeight.IsNil() || m.ConsensusWeight.LT(sdk.ZeroDec()) {
return status.Errorf(codes.InvalidArgument, "Alliance consensusWeight must be zero or a positive number")
}
if m.ConsensusCap.IsNil() || m.ConsensusCap.LT(sdk.ZeroDec()) {
return status.Errorf(codes.InvalidArgument, "Alliance consensusCap must be zero or a positive number")
}
if m.RewardWeightRange.Min.IsNil() || m.RewardWeightRange.Min.LT(sdk.ZeroDec()) ||
m.RewardWeightRange.Max.IsNil() || m.RewardWeightRange.Max.LT(sdk.ZeroDec()) {
return status.Errorf(codes.InvalidArgument, "Alliance rewardWeight min and max must be zero or a positive number")
}
if m.RewardWeightRange.Min.GT(m.RewardWeightRange.Max) {
return status.Errorf(codes.InvalidArgument, "Alliance rewardWeight min must be less or equal to rewardWeight max")
}
if m.RewardWeight.LT(m.RewardWeightRange.Min) || m.RewardWeight.GT(m.RewardWeightRange.Max) {
return status.Errorf(codes.InvalidArgument, "Alliance rewardWeight must be bounded in RewardWeightRange")
}
if m.TakeRate.IsNil() || m.TakeRate.IsNegative() || m.TakeRate.GTE(sdk.OneDec()) {
return status.Errorf(codes.InvalidArgument, "Alliance takeRate must be more or equals to 0 but strictly less than 1")
}
if m.RewardChangeRate.IsZero() || m.RewardChangeRate.IsNegative() {
return status.Errorf(codes.InvalidArgument, "Alliance rewardChangeRate must be strictly a positive number")
}
if m.RewardChangeInterval < 0 {
return status.Errorf(codes.InvalidArgument, "Alliance rewardChangeInterval must be strictly a positive number")
}
return nil
}
func NewMsgUpdateAllianceProposal(title, description, denom string, rewardWeight, consensusWeight, consensusCap, takeRate sdk.Dec, rewardChangeRate sdk.Dec, rewardChangeInterval time.Duration) govtypes.Content {
return &MsgUpdateAllianceProposal{
Title: title,
Description: description,
Denom: denom,
RewardWeight: rewardWeight,
ConsensusWeight: consensusWeight,
ConsensusCap: consensusCap,
TakeRate: takeRate,
RewardChangeRate: rewardChangeRate,
RewardChangeInterval: rewardChangeInterval,
}
}
func (m *MsgUpdateAllianceProposal) GetTitle() string { return m.Title }
func (m *MsgUpdateAllianceProposal) GetDescription() string { return m.Description }
func (m *MsgUpdateAllianceProposal) ProposalRoute() string { return RouterKey }
func (m *MsgUpdateAllianceProposal) ProposalType() string { return ProposalTypeUpdateAlliance }
func (m *MsgUpdateAllianceProposal) ValidateBasic() error {
if m.Denom == "" {
return status.Errorf(codes.InvalidArgument, "Alliance denom must have a value")
}
if m.RewardWeight.IsNil() || m.RewardWeight.LT(sdk.ZeroDec()) {
return status.Errorf(codes.InvalidArgument, "Alliance rewardWeight must be zero or a positive number")
}
if m.TakeRate.IsNil() || m.TakeRate.IsNegative() || m.TakeRate.GTE(sdk.OneDec()) {
return status.Errorf(codes.InvalidArgument, "Alliance takeRate must be more or equals to 0 but strictly less than 1")
}
if m.RewardChangeRate.IsZero() || m.RewardChangeRate.IsNegative() {
return status.Errorf(codes.InvalidArgument, "Alliance rewardChangeRate must be strictly a positive number")
}
if m.RewardChangeInterval < 0 {
return status.Errorf(codes.InvalidArgument, "Alliance rewardChangeInterval must be strictly a positive number")
}
return nil
}
func NewMsgDeleteAllianceProposal(title, description, denom string) govtypes.Content {
return &MsgDeleteAllianceProposal{
Title: title,
Description: description,
Denom: denom,
}
}
func (m *MsgDeleteAllianceProposal) GetTitle() string { return m.Title }
func (m *MsgDeleteAllianceProposal) GetDescription() string { return m.Description }
func (m *MsgDeleteAllianceProposal) ProposalRoute() string { return RouterKey }
func (m *MsgDeleteAllianceProposal) ProposalType() string { return ProposalTypeDeleteAlliance }
func (m *MsgDeleteAllianceProposal) ValidateBasic() error {
if m.Denom == "" {
return status.Errorf(codes.InvalidArgument, "Alliance denom must have a value")
}
return nil
}