laconicd/x/bond/msgs.go
Prathamesh Musale ec147272e6
All checks were successful
E2E Tests / test-e2e (push) Successful in 1m58s
Integration Tests / test-integration (push) Successful in 1m10s
Add module invariants and input validations (#14)
Reviewed-on: deep-stack/laconic2d#14
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-03-06 09:24:15 +00:00

66 lines
1.6 KiB
Go

package bond
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
var (
_ sdk.Msg = &MsgCreateBond{}
)
// NewMsgCreateBond is the constructor function for MsgCreateBond.
func NewMsgCreateBond(coins sdk.Coins, signer sdk.AccAddress) MsgCreateBond {
return MsgCreateBond{
Coins: coins,
Signer: signer.String(),
}
}
func (msg MsgCreateBond) ValidateBasic() error {
if len(msg.Signer) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
}
return nil
}
func (msg MsgRefillBond) ValidateBasic() error {
if len(msg.Id) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
}
if len(msg.Signer) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
}
return nil
}
func (msg MsgWithdrawBond) ValidateBasic() error {
if len(msg.Id) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
}
if len(msg.Signer) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
}
return nil
}
func (msg MsgCancelBond) ValidateBasic() error {
if len(msg.Id) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
}
if len(msg.Signer) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
return nil
}