/
msgs.go
88 lines (76 loc) · 2.49 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
package types
import (
"fmt"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// constants
const (
TypeMsgLockTokens = "lock_tokens"
TypeMsgBeginUnlockingAll = "begin_unlocking_all"
TypeMsgBeginUnlocking = "begin_unlocking"
)
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)
}
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}
}