-
Notifications
You must be signed in to change notification settings - Fork 46
/
msgs.go
104 lines (87 loc) · 2.64 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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authlegacy "github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
)
const (
TypeMsgMicrotx = "microtx"
TypeMsgLiquify = "liquify"
)
// nolint: exhaustruct
var (
_ sdk.Msg = &MsgMicrotx{}
_ sdk.Msg = &MsgLiquify{}
_ authlegacy.LegacyMsg = &MsgMicrotx{}
_ authlegacy.LegacyMsg = &MsgLiquify{}
)
// NewMsgMicrotx returns a new MsgMicrotx
func NewMsgMicrotx(sender string, reciever string, amount sdk.Coin) *MsgMicrotx {
return &MsgMicrotx{
sender,
reciever,
amount,
}
}
// Route should return the name of the module
func (msg *MsgMicrotx) Route() string { return RouterKey }
func (msg MsgMicrotx) Type() string { return TypeMsgMicrotx }
// ValidateBasic checks for valid addresses and amounts
func (msg *MsgMicrotx) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrap(err, "invalid sender in microtx msg microtx")
}
_, err = sdk.AccAddressFromBech32(msg.Receiver)
if err != nil {
return sdkerrors.Wrap(err, "invalid receiver in microtx msg microtx")
}
if err := msg.Amount.Validate(); err != nil {
return sdkerrors.Wrap(err, "invalid coin in microtx msg microtx")
}
if msg.Amount.Amount.Equal(sdk.ZeroInt()) {
return sdkerrors.Wrap(ErrInvalidMicrotx, "zero amount in microtx msg microtx")
}
return nil
}
// GetSigners requires the Sender to be the signer
func (msg *MsgMicrotx) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// GetSignBytes Implements Msg.
func (msg MsgMicrotx) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// NewMsgLiquify returns a new MsgLiquify
func NewMsgLiquify(sender string) *MsgLiquify {
return &MsgLiquify{
sender,
}
}
// Route should return the name of the module
func (msg *MsgLiquify) Route() string { return RouterKey }
func (msg MsgLiquify) Type() string { return TypeMsgLiquify }
// ValidateBasic checks for valid addresses
func (msg *MsgLiquify) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrap(err, "invalid sender in microtx msg liquify")
}
return nil
}
// GetSigners requires the Sender to be the signer
func (msg *MsgLiquify) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
}
// GetSignBytes Implements Msg.
func (msg MsgLiquify) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}