/
msgs.go
134 lines (110 loc) · 3.61 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package types
import (
"fmt"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// constants.
const (
TypeMsgLockTokens = "lock_tokens"
TypeMsgBeginUnlockingAll = "begin_unlocking_all"
TypeMsgBeginUnlocking = "begin_unlocking"
TypeMsgExtendLockup = "edit_lockup"
)
var _ sdk.Msg = &MsgLockTokens{}
// NewMsgLockTokens creates a message to lock tokens.
func NewMsgLockTokens(owner sdk.AccAddress, duration time.Duration, coins sdk.Coins) *MsgLockTokens {
return &MsgLockTokens{
Owner: owner.String(),
Duration: duration,
Coins: coins,
}
}
func (m MsgLockTokens) Route() string { return RouterKey }
func (m MsgLockTokens) Type() string { return TypeMsgLockTokens }
func (m MsgLockTokens) ValidateBasic() error {
if m.Duration <= 0 {
return fmt.Errorf("duration should be positive: %d < 0", m.Duration)
}
// we only allow locks with one denom for now
if m.Coins.Len() != 1 {
return fmt.Errorf("lockups can only have one denom per lock ID, got %v", m.Coins)
}
return nil
}
func (m MsgLockTokens) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
func (m MsgLockTokens) GetSigners() []sdk.AccAddress {
owner, _ := sdk.AccAddressFromBech32(m.Owner)
return []sdk.AccAddress{owner}
}
var _ sdk.Msg = &MsgBeginUnlockingAll{}
// NewMsgBeginUnlockingAll creates a message to begin unlocking tokens.
func NewMsgBeginUnlockingAll(owner sdk.AccAddress) *MsgBeginUnlockingAll {
return &MsgBeginUnlockingAll{
Owner: owner.String(),
}
}
func (m MsgBeginUnlockingAll) Route() string { return RouterKey }
func (m MsgBeginUnlockingAll) Type() string { return TypeMsgBeginUnlockingAll }
func (m MsgBeginUnlockingAll) ValidateBasic() error {
return nil
}
func (m MsgBeginUnlockingAll) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
func (m MsgBeginUnlockingAll) GetSigners() []sdk.AccAddress {
owner, _ := sdk.AccAddressFromBech32(m.Owner)
return []sdk.AccAddress{owner}
}
var _ sdk.Msg = &MsgBeginUnlocking{}
// NewMsgBeginUnlocking creates a message to begin unlocking the tokens of a specific lock.
func NewMsgBeginUnlocking(owner sdk.AccAddress, id uint64, coins sdk.Coins) *MsgBeginUnlocking {
return &MsgBeginUnlocking{
Owner: owner.String(),
ID: id,
Coins: coins,
}
}
func (m MsgBeginUnlocking) Route() string { return RouterKey }
func (m MsgBeginUnlocking) Type() string { return TypeMsgBeginUnlocking }
func (m MsgBeginUnlocking) ValidateBasic() error {
return nil
}
func (m MsgBeginUnlocking) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
func (m MsgBeginUnlocking) GetSigners() []sdk.AccAddress {
owner, _ := sdk.AccAddressFromBech32(m.Owner)
return []sdk.AccAddress{owner}
}
// NewMsgExtendLockup creates a message to edit the properties of existing locks
func NewMsgExtendLockup(owner sdk.AccAddress, id uint64, duration time.Duration) *MsgExtendLockup {
return &MsgExtendLockup{
Owner: owner.String(),
ID: id,
Duration: duration,
}
}
func (m MsgExtendLockup) Route() string { return RouterKey }
func (m MsgExtendLockup) Type() string { return TypeMsgExtendLockup }
func (m MsgExtendLockup) ValidateBasic() error {
if len(m.Owner) == 0 {
return fmt.Errorf("owner is empty")
}
if m.ID == 0 {
return fmt.Errorf("id is empty")
}
if m.Duration <= 0 {
return fmt.Errorf("duration should be positive: %d < 0", m.Duration)
}
return nil
}
func (m MsgExtendLockup) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON((&m)))
}
func (m MsgExtendLockup) GetSigners() []sdk.AccAddress {
owner, _ := sdk.AccAddressFromBech32(m.Owner)
return []sdk.AccAddress{owner}
}