Skip to content

Commit

Permalink
chore: add denom validation for string type denom
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeseung-bae committed May 8, 2024
1 parent c76058c commit e4def6a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
13 changes: 9 additions & 4 deletions x/fswap/types/fswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@ import (

// ValidateBasic validates the set of Swap
func (s *Swap) ValidateBasic() error {
if s.FromDenom == "" {
return sdkerrors.ErrInvalidRequest.Wrap("from denomination cannot be empty")
if err := sdk.ValidateDenom(s.FromDenom); err != nil {
return sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}
if s.ToDenom == "" {
return sdkerrors.ErrInvalidRequest.Wrap("to denomination cannot be empty")

if err := sdk.ValidateDenom(s.ToDenom); err != nil {
return sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}

if s.FromDenom == s.ToDenom {
return sdkerrors.ErrInvalidRequest.Wrap("from denomination cannot be equal to to denomination")
}

if s.AmountCapForToDenom.LT(sdk.OneInt()) {
return sdkerrors.ErrInvalidRequest.Wrap("amount cannot be less than one")
}

if s.SwapRate.IsZero() {
return sdkerrors.ErrInvalidRequest.Wrap("swap rate cannot be zero")
}

return nil
}

Expand Down
12 changes: 6 additions & 6 deletions x/fswap/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func (m *MsgSwap) ValidateBasic() error {
return sdkerrors.ErrInvalidCoins.Wrap(m.FromCoinAmount.String())
}

if len(m.GetToDenom()) == 0 {
return sdkerrors.ErrInvalidRequest.Wrap("invalid denom (empty denom)")
if err := sdk.ValidateDenom(m.GetToDenom()); err != nil {
return sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}

return nil
Expand Down Expand Up @@ -53,12 +53,12 @@ func (m *MsgSwapAll) ValidateBasic() error {
return sdkerrors.ErrInvalidAddress.Wrapf("Invalid address (%s)", err)
}

if len(m.GetFromDenom()) == 0 {
return sdkerrors.ErrInvalidRequest.Wrap("invalid denom (empty denom)")
if err := sdk.ValidateDenom(m.FromDenom); err != nil {
return sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}

if len(m.GetToDenom()) == 0 {
return sdkerrors.ErrInvalidRequest.Wrap("invalid denom (empty denom)")
if err := sdk.ValidateDenom(m.ToDenom); err != nil {
return sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}

return nil
Expand Down

0 comments on commit e4def6a

Please sign in to comment.