-
Notifications
You must be signed in to change notification settings - Fork 39
/
msgs.go
95 lines (74 loc) · 2.69 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
package types
import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
chaintypes "github.com/InjectiveLabs/sdk-go/chain/types"
)
const (
RouterKey = ModuleName
TypeMsgBid = "bid"
TypeMsgUpdateParams = "updateParams"
)
var (
_ sdk.Msg = &MsgBid{}
_ sdk.Msg = &MsgUpdateParams{}
)
// Route implements the sdk.Msg interface. It should return the name of the module
func (msg MsgUpdateParams) Route() string { return RouterKey }
// Type implements the sdk.Msg interface. It should return the action.
func (msg MsgUpdateParams) Type() string { return TypeMsgUpdateParams }
// ValidateBasic implements the sdk.Msg interface. It runs stateless checks on the message
func (msg MsgUpdateParams) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
return errors.Wrap(err, "invalid authority address")
}
if err := msg.Params.Validate(); err != nil {
return err
}
return nil
}
// GetSignBytes implements the sdk.Msg interface. It encodes the message for signing
func (msg *MsgUpdateParams) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners implements the sdk.Msg interface. It defines whose signature is required
func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Authority)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}
// Route implements the sdk.Msg interface. It should return the name of the module
func (msg MsgBid) Route() string { return RouterKey }
// Type implements the sdk.Msg interface. It should return the action.
func (msg MsgBid) Type() string { return TypeMsgBid }
// ValidateBasic implements the sdk.Msg interface. It runs stateless checks on the message
func (msg MsgBid) ValidateBasic() error {
if msg.Sender == "" {
return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.Sender)
}
if !msg.BidAmount.IsValid() {
return errors.Wrap(sdkerrors.ErrInvalidCoins, msg.BidAmount.String())
}
if !msg.BidAmount.IsPositive() {
return errors.Wrap(sdkerrors.ErrInvalidCoins, msg.BidAmount.String())
}
if msg.BidAmount.Denom != chaintypes.InjectiveCoin {
return errors.Wrap(ErrBidInvalid, msg.BidAmount.Denom)
}
return nil
}
// GetSignBytes implements the sdk.Msg interface. It encodes the message for signing
func (msg *MsgBid) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners implements the sdk.Msg interface. It defines whose signature is required
func (msg MsgBid) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}