github.com/InjectiveLabs/sdk-go@v1.53.0/chain/auction/types/msgs.go (about) 1 package types 2 3 import ( 4 "cosmossdk.io/errors" 5 sdk "github.com/cosmos/cosmos-sdk/types" 6 sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" 7 8 chaintypes "github.com/InjectiveLabs/sdk-go/chain/types" 9 ) 10 11 const ( 12 RouterKey = ModuleName 13 14 TypeMsgBid = "bid" 15 TypeMsgUpdateParams = "updateParams" 16 ) 17 18 var ( 19 _ sdk.Msg = &MsgBid{} 20 _ sdk.Msg = &MsgUpdateParams{} 21 ) 22 23 // Route implements the sdk.Msg interface. It should return the name of the module 24 func (msg MsgUpdateParams) Route() string { return RouterKey } 25 26 // Type implements the sdk.Msg interface. It should return the action. 27 func (msg MsgUpdateParams) Type() string { return TypeMsgUpdateParams } 28 29 // ValidateBasic implements the sdk.Msg interface. It runs stateless checks on the message 30 func (msg MsgUpdateParams) ValidateBasic() error { 31 if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { 32 return errors.Wrap(err, "invalid authority address") 33 } 34 35 if err := msg.Params.Validate(); err != nil { 36 return err 37 } 38 39 return nil 40 } 41 42 // GetSignBytes implements the sdk.Msg interface. It encodes the message for signing 43 func (msg *MsgUpdateParams) GetSignBytes() []byte { 44 return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) 45 } 46 47 // GetSigners implements the sdk.Msg interface. It defines whose signature is required 48 func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { 49 sender, err := sdk.AccAddressFromBech32(msg.Authority) 50 if err != nil { 51 panic(err) 52 } 53 return []sdk.AccAddress{sender} 54 } 55 56 // Route implements the sdk.Msg interface. It should return the name of the module 57 func (msg MsgBid) Route() string { return RouterKey } 58 59 // Type implements the sdk.Msg interface. It should return the action. 60 func (msg MsgBid) Type() string { return TypeMsgBid } 61 62 // ValidateBasic implements the sdk.Msg interface. It runs stateless checks on the message 63 func (msg MsgBid) ValidateBasic() error { 64 if msg.Sender == "" { 65 return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.Sender) 66 } 67 68 if !msg.BidAmount.IsValid() { 69 return errors.Wrap(sdkerrors.ErrInvalidCoins, msg.BidAmount.String()) 70 } 71 72 if !msg.BidAmount.IsPositive() { 73 return errors.Wrap(sdkerrors.ErrInvalidCoins, msg.BidAmount.String()) 74 } 75 76 if msg.BidAmount.Denom != chaintypes.InjectiveCoin { 77 return errors.Wrap(ErrBidInvalid, msg.BidAmount.Denom) 78 } 79 80 return nil 81 } 82 83 // GetSignBytes implements the sdk.Msg interface. It encodes the message for signing 84 func (msg *MsgBid) GetSignBytes() []byte { 85 return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) 86 } 87 88 // GetSigners implements the sdk.Msg interface. It defines whose signature is required 89 func (msg MsgBid) GetSigners() []sdk.AccAddress { 90 sender, err := sdk.AccAddressFromBech32(msg.Sender) 91 if err != nil { 92 panic(err) 93 } 94 return []sdk.AccAddress{sender} 95 }