diff --git a/x/feepay/client/cli/tx.go b/x/feepay/client/cli/tx.go index a18c3696d..4f7b217a0 100644 --- a/x/feepay/client/cli/tx.go +++ b/x/feepay/client/cli/tx.go @@ -51,8 +51,6 @@ func NewRegisterFeePayContract() *cobra.Command { wallet_limit := args[1] dec_limit, err := strconv.ParseUint(wallet_limit, 10, 64) - // todo bech32 validation - if err != nil { return err } diff --git a/x/feepay/types/errors.go b/x/feepay/types/errors.go index ff29f83f8..dd3fe0a96 100644 --- a/x/feepay/types/errors.go +++ b/x/feepay/types/errors.go @@ -12,4 +12,6 @@ var ( ErrWalletExceededUsageLimit = errorsmod.Register(ModuleName, 5, "wallet exceeded usage limit") ErrContractNotAdmin = errorsmod.Register(ModuleName, 6, "sender is not the contract admin") ErrContractNotCreator = errorsmod.Register(ModuleName, 7, "sender is not the contract creator") + ErrInvalidWalletLimit = errorsmod.Register(ModuleName, 8, "invalid wallet limit; must be between 0 and 1,000,000") + ErrInvalidJunoFundAmount = errorsmod.Register(ModuleName, 9, "fee pay contracts only accept juno funds") ) diff --git a/x/feepay/types/msg.go b/x/feepay/types/msg.go index db43ec860..4114970d5 100644 --- a/x/feepay/types/msg.go +++ b/x/feepay/types/msg.go @@ -26,6 +26,18 @@ func (msg MsgRegisterFeePayContract) Type() string { return TypeMsgRegisterFeePa // ValidateBasic runs stateless checks on the message func (msg MsgRegisterFeePayContract) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.SenderAddress); err != nil { + return err + } + + if _, err := sdk.AccAddressFromBech32(msg.Contract.ContractAddress); err != nil { + return err + } + + if msg.Contract.WalletLimit < 0 || msg.Contract.WalletLimit > 1_000_000 { + return ErrInvalidWalletLimit + } + return nil } @@ -48,6 +60,15 @@ func (msg MsgUnregisterFeePayContract) Type() string { return TypeMsgUnregisterF // ValidateBasic runs stateless checks on the message func (msg MsgUnregisterFeePayContract) ValidateBasic() error { + + if _, err := sdk.AccAddressFromBech32(msg.SenderAddress); err != nil { + return err + } + + if _, err := sdk.AccAddressFromBech32(msg.ContractAddress); err != nil { + return err + } + return nil } @@ -70,6 +91,19 @@ func (msg MsgFundFeePayContract) Type() string { return TypeMsgFundFeePayContrac // ValidateBasic runs stateless checks on the message func (msg MsgFundFeePayContract) ValidateBasic() error { + + if _, err := sdk.AccAddressFromBech32(msg.SenderAddress); err != nil { + return err + } + + if _, err := sdk.AccAddressFromBech32(msg.ContractAddress); err != nil { + return err + } + + if len(msg.Amount) != 1 { + return ErrInvalidJunoFundAmount + } + return nil }