-
Notifications
You must be signed in to change notification settings - Fork 618
/
Copy pathmsgs.go
93 lines (75 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
89
90
91
92
93
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// constants.
const (
TypeMsgSwapExactAmountIn = "swap_exact_amount_in"
TypeMsgSwapExactAmountOut = "swap_exact_amount_out"
)
var _ sdk.Msg = &MsgSwapExactAmountIn{}
func (msg MsgSwapExactAmountIn) Route() string { return RouterKey }
func (msg MsgSwapExactAmountIn) Type() string { return TypeMsgSwapExactAmountIn }
func (msg MsgSwapExactAmountIn) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err)
}
err = SwapAmountInRoutes(msg.Routes).Validate()
if err != nil {
return err
}
if !msg.TokenIn.IsValid() || !msg.TokenIn.IsPositive() {
// TODO: remove sdk errors
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.TokenIn.String())
}
if !msg.TokenOutMinAmount.IsPositive() {
return nonPositiveAmountError{msg.TokenOutMinAmount.String()}
}
return nil
}
// TODO: uncomment when types are registered.
func (msg MsgSwapExactAmountIn) GetSignBytes() []byte {
// return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
panic("not implemented")
}
func (msg MsgSwapExactAmountIn) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}
var _ sdk.Msg = &MsgSwapExactAmountOut{}
func (msg MsgSwapExactAmountOut) Route() string { return RouterKey }
func (msg MsgSwapExactAmountOut) Type() string { return TypeMsgSwapExactAmountOut }
func (msg MsgSwapExactAmountOut) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err)
}
err = SwapAmountOutRoutes(msg.Routes).Validate()
if err != nil {
return err
}
if !msg.TokenOut.IsValid() || !msg.TokenOut.IsPositive() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.TokenOut.String())
}
if !msg.TokenInMaxAmount.IsPositive() {
return nonPositiveAmountError{msg.TokenInMaxAmount.String()}
}
return nil
}
// TODO: uncomment when types are registered.
func (msg MsgSwapExactAmountOut) GetSignBytes() []byte {
// return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
panic("not implemented")
}
func (msg MsgSwapExactAmountOut) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}