-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract auction and price query validation logic into separate functions
to share code between msg validation and genesis validation
- Loading branch information
Showing
6 changed files
with
96 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package types | ||
|
||
import ( | ||
"errors" | ||
fmt "fmt" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
"cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
func ValidateCreateAuctionParams( | ||
auctionName string, | ||
auctionType AuctionType, | ||
sellingDenom string, | ||
paymentDenom string, | ||
priceMultiplier math.LegacyDec, | ||
minBidAmount math.Int, | ||
beneficiary string, | ||
) error { | ||
if auctionName == "" { | ||
return errors.New("auction-name must be specified") | ||
} | ||
if _, ok := AuctionType_name[int32(auctionType)]; !ok { | ||
return fmt.Errorf("auction-type %d is invalid", auctionType) | ||
} | ||
if sellingDenom == "" { | ||
return errors.New("selling-denom must be specified") | ||
} | ||
if paymentDenom == "" { | ||
return errors.New("payment-denom must be specified") | ||
} | ||
if !(priceMultiplier.GT(math.LegacyZeroDec()) && priceMultiplier.LTE(math.LegacyOneDec())) { | ||
return errors.New("price-multiplier must be > 0 and <= 1 (0 > priceMultiplier >= 1)") | ||
} | ||
if minBidAmount.LT(math.ZeroInt()) { | ||
return errors.New("min-bid-amount must be >= 0") | ||
} | ||
if _, err := sdk.AccAddressFromBech32(beneficiary); err != nil { | ||
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid beneficiary address (%s)", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package types | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
) | ||
|
||
func ValidateTokenPriceQueryParams(baseDenom, quoteDenom, osmosisPoolId, osmosisBaseDenom, osmosisQuoteDenom string) error { | ||
if baseDenom == "" { | ||
return errors.New("base-denom must be specified") | ||
} | ||
if quoteDenom == "" { | ||
return errors.New("quote-denom must be specified") | ||
} | ||
if _, err := strconv.ParseUint(osmosisPoolId, 10, 64); err != nil { | ||
return errors.New("osmosis-pool-id must be uint64") | ||
} | ||
if osmosisBaseDenom == "" { | ||
return errors.New("osmosis-base-denom must be specified") | ||
} | ||
if osmosisQuoteDenom == "" { | ||
return errors.New("osmosis-quote-denom must be specified") | ||
} | ||
|
||
return nil | ||
} |