-
Notifications
You must be signed in to change notification settings - Fork 41
/
msgs.go
57 lines (43 loc) · 1.53 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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
chaintypes "github.com/InjectiveLabs/sdk-go/chain/types"
)
const TypeMsgBid = "bid"
const RouterKey = ModuleName
var (
_ sdk.Msg = &MsgBid{}
)
// 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 sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Sender)
}
if !msg.BidAmount.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.BidAmount.String())
}
if !msg.BidAmount.IsPositive() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.BidAmount.String())
}
if msg.BidAmount.Denom != chaintypes.InjectiveCoin {
return sdkerrors.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}
}