Skip to content

Commit

Permalink
add validation for duration
Browse files Browse the repository at this point in the history
  • Loading branch information
harish551 committed Sep 13, 2022
1 parent e623cf0 commit 733e505
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions x/marketplace/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ func (msg MsgCreateAuction) ValidateBasic() error {
if err = ValidatePrice(msg.StartPrice); err != nil {
return err
}
if err = ValidateDuration(*msg.Duration); err != nil {
return err
}
if !msg.IncrementPercentage.IsPositive() || !msg.IncrementPercentage.LTE(sdk.NewDec(1)) {
return sdkerrors.Wrapf(ErrInvalidPercentage, "invalid percentage value (%s)", msg.IncrementPercentage.String())
}
Expand Down
10 changes: 6 additions & 4 deletions x/marketplace/types/validation.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"strings"
Expand Down Expand Up @@ -44,10 +43,13 @@ func ValidatePrice(price sdk.Coin) error {
return nil
}

func ValidateTimeStamp(t interface{}) error {
_, ok := t.(time.Duration)
func ValidateDuration(t interface{}) error {
duration, ok := t.(time.Duration)
if !ok {
return fmt.Errorf("invalid value for start time: %T", t)
return sdkerrors.Wrapf(ErrInvalidDuration, "invalid value for duration: %T", t)
}
if duration.Nanoseconds() <= 0 {
return sdkerrors.Wrapf(ErrInvalidDuration, "invalid duration %s, only accepts positive value", duration.String())
}
return nil
}
Expand Down

0 comments on commit 733e505

Please sign in to comment.