-
Notifications
You must be signed in to change notification settings - Fork 568
/
msgs.go
96 lines (84 loc) · 2.89 KB
/
msgs.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
package types
import (
"errors"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
lockuptypes "github.com/osmosis-labs/osmosis/v7/x/lockup/types"
)
// constants
const (
TypeMsgCreateGauge = "create_gauge"
TypeMsgAddToGauge = "add_to_gauge"
)
var _ sdk.Msg = &MsgCreateGauge{}
// NewMsgCreateGauge creates a message to create a gauge
func NewMsgCreateGauge(isPerpetual bool, owner sdk.AccAddress, distributeTo lockuptypes.QueryCondition, coins sdk.Coins, startTime time.Time, numEpochsPaidOver uint64) *MsgCreateGauge {
return &MsgCreateGauge{
IsPerpetual: isPerpetual,
Owner: owner.String(),
DistributeTo: distributeTo,
Coins: coins,
StartTime: startTime,
NumEpochsPaidOver: numEpochsPaidOver,
}
}
func (m MsgCreateGauge) Route() string { return RouterKey }
func (m MsgCreateGauge) Type() string { return TypeMsgCreateGauge }
func (m MsgCreateGauge) ValidateBasic() error {
if m.Owner == "" {
return errors.New("owner should be set")
}
if sdk.ValidateDenom(m.DistributeTo.Denom) != nil {
return errors.New("denom should be valid for the condition")
}
if lockuptypes.LockQueryType_name[int32(m.DistributeTo.LockQueryType)] == "" {
return errors.New("lock query type is invalid")
}
if m.StartTime.Equal(time.Time{}) {
return errors.New("distribution start time should be set")
}
if m.NumEpochsPaidOver == 0 {
return errors.New("distribution period should be at least 1 epoch")
}
if m.IsPerpetual && m.NumEpochsPaidOver != 1 {
return errors.New("distribution period should be 1 epoch for perpetual gauge")
}
if lockuptypes.LockQueryType_name[int32(m.DistributeTo.LockQueryType)] != "ByDuration" {
return errors.New("only duration query condition is allowed. Start time distr conditions is an obsolete codepath slated for deletion")
}
return nil
}
func (m MsgCreateGauge) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
func (m MsgCreateGauge) GetSigners() []sdk.AccAddress {
owner, _ := sdk.AccAddressFromBech32(m.Owner)
return []sdk.AccAddress{owner}
}
var _ sdk.Msg = &MsgAddToGauge{}
// NewMsgCreateGauge creates a message to create a gauge
func NewMsgAddToGauge(owner sdk.AccAddress, gaugeId uint64, rewards sdk.Coins) *MsgAddToGauge {
return &MsgAddToGauge{
Owner: owner.String(),
GaugeId: gaugeId,
Rewards: rewards,
}
}
func (m MsgAddToGauge) Route() string { return RouterKey }
func (m MsgAddToGauge) Type() string { return TypeMsgAddToGauge }
func (m MsgAddToGauge) ValidateBasic() error {
if m.Owner == "" {
return errors.New("owner should be set")
}
if m.Rewards.Empty() {
return errors.New("additional rewards should not be empty")
}
return nil
}
func (m MsgAddToGauge) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
func (m MsgAddToGauge) GetSigners() []sdk.AccAddress {
owner, _ := sdk.AccAddressFromBech32(m.Owner)
return []sdk.AccAddress{owner}
}