/
msgs.go
114 lines (93 loc) · 3.68 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package types
import (
"errors"
"time"
lockuptypes "github.com/merlinslair/merlin/x/lockup/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
TypeMsgCreateGauge = "create_gauge"
TypeMsgAddToGauge = "add_to_gauge"
)
var _ sdk.Msg = &MsgCreateGauge{}
// NewMsgCreateGauge creates a message to create a gauge with the provided parameters.
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,
}
}
// Route takes a create gauge message, then returns the RouterKey used for slashing.
func (m MsgCreateGauge) Route() string { return RouterKey }
// Type takes a create gauge message, then returns a create gauge message type.
func (m MsgCreateGauge) Type() string { return TypeMsgCreateGauge }
// ValidateBasic checks that the create gauge message is valid.
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
}
// GetSignBytes takes a create gauge message and turns it into a byte array.
func (m MsgCreateGauge) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
// GetSigners takes a create gauge message and returns the owner in a byte array.
func (m MsgCreateGauge) GetSigners() []sdk.AccAddress {
owner, _ := sdk.AccAddressFromBech32(m.Owner)
return []sdk.AccAddress{owner}
}
var _ sdk.Msg = &MsgAddToGauge{}
// NewMsgAddToGauge creates a message to add rewards to a specific gauge.
func NewMsgAddToGauge(owner sdk.AccAddress, gaugeId uint64, rewards sdk.Coins) *MsgAddToGauge {
return &MsgAddToGauge{
Owner: owner.String(),
GaugeId: gaugeId,
Rewards: rewards,
}
}
// Route takes an add to gauge message, then returns the RouterKey used for slashing.
func (m MsgAddToGauge) Route() string { return RouterKey }
// Type takes an add to gauge message, then returns an add to gauge message type.
func (m MsgAddToGauge) Type() string { return TypeMsgAddToGauge }
// ValidateBasic checks that the add to gauge message is valid.
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
}
// GetSignBytes takes an add to gauge message and turns it into a byte array.
func (m MsgAddToGauge) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
// GetSigners takes an add to gauge message and returns the owner in a byte array.
func (m MsgAddToGauge) GetSigners() []sdk.AccAddress {
owner, _ := sdk.AccAddressFromBech32(m.Owner)
return []sdk.AccAddress{owner}
}