From b25165e9ccae3cbdee2bee876b663a7855aef68a Mon Sep 17 00:00:00 2001 From: Dreamer <745124335@qq.com> Date: Thu, 19 Oct 2023 18:11:10 +0800 Subject: [PATCH] can not mint nft from ibc class --- modules/nft/types/errors.go | 22 +++++++++++----------- modules/nft/types/msgs.go | 31 ++++++++++++++++++------------- modules/nft/types/validation.go | 10 +++++----- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/modules/nft/types/errors.go b/modules/nft/types/errors.go index e5f77082..89134067 100644 --- a/modules/nft/types/errors.go +++ b/modules/nft/types/errors.go @@ -1,18 +1,18 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errormod "cosmossdk.io/errors" ) var ( - ErrInvalidCollection = sdkerrors.Register(ModuleName, 9, "invalid nft collection") - ErrUnknownCollection = sdkerrors.Register(ModuleName, 10, "unknown nft collection") - ErrInvalidNFT = sdkerrors.Register(ModuleName, 11, "invalid nft") - ErrNFTAlreadyExists = sdkerrors.Register(ModuleName, 12, "nft already exists") - ErrUnknownNFT = sdkerrors.Register(ModuleName, 13, "unknown nft") - ErrEmptyTokenData = sdkerrors.Register(ModuleName, 14, "nft data can't be empty") - ErrUnauthorized = sdkerrors.Register(ModuleName, 15, "unauthorized address") - ErrInvalidDenom = sdkerrors.Register(ModuleName, 16, "invalid denom") - ErrInvalidTokenID = sdkerrors.Register(ModuleName, 17, "invalid nft id") - ErrInvalidTokenURI = sdkerrors.Register(ModuleName, 18, "invalid nft uri") + ErrInvalidCollection = errormod.Register(ModuleName, 9, "invalid nft collection") + ErrUnknownCollection = errormod.Register(ModuleName, 10, "unknown nft collection") + ErrInvalidNFT = errormod.Register(ModuleName, 11, "invalid nft") + ErrNFTAlreadyExists = errormod.Register(ModuleName, 12, "nft already exists") + ErrUnknownNFT = errormod.Register(ModuleName, 13, "unknown nft") + ErrEmptyTokenData = errormod.Register(ModuleName, 14, "nft data can't be empty") + ErrUnauthorized = errormod.Register(ModuleName, 15, "unauthorized address") + ErrInvalidDenom = errormod.Register(ModuleName, 16, "invalid denom") + ErrInvalidTokenID = errormod.Register(ModuleName, 17, "invalid nft id") + ErrInvalidTokenURI = errormod.Register(ModuleName, 18, "invalid nft uri") ) diff --git a/modules/nft/types/msgs.go b/modules/nft/types/msgs.go index 4063feeb..9d038e1d 100644 --- a/modules/nft/types/msgs.go +++ b/modules/nft/types/msgs.go @@ -3,6 +3,8 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + errormod "cosmossdk.io/errors" "github.com/tidwall/gjson" ) @@ -58,11 +60,11 @@ func (msg MsgIssueDenom) ValidateBasic() error { } if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) + return errormod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) } if len(msg.Data) != 0 && !gjson.Valid(msg.Data) { - return sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, "invalid data, must be a JSON string or empty") + return errormod.Wrap(sdkerrors.ErrJSONUnmarshal, "invalid data, must be a JSON string or empty") } return ValidateKeywords(msg.Id) } @@ -111,15 +113,15 @@ func (msg MsgTransferNFT) ValidateBasic() error { } if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) + return errormod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) } if _, err := sdk.AccAddressFromBech32(msg.Recipient); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid recipient address (%s)", err) + return errormod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid recipient address (%s)", err) } if len(msg.Data) != 0 && Modified(msg.Data) && !gjson.Valid(msg.Data) { - return sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, "invalid data, must be a JSON string or empty") + return errormod.Wrap(sdkerrors.ErrJSONUnmarshal, "invalid data, must be a JSON string or empty") } return ValidateTokenID(msg.Id) } @@ -163,7 +165,7 @@ func (msg MsgEditNFT) Type() string { return TypeMsgEditNFT } // ValidateBasic Implements Msg. func (msg MsgEditNFT) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) + return errormod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) } if err := ValidateDenomID(msg.DenomId); err != nil { @@ -175,7 +177,7 @@ func (msg MsgEditNFT) ValidateBasic() error { } if len(msg.Data) != 0 && Modified(msg.Data) && !gjson.Valid(msg.Data) { - return sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, "invalid data, must be a JSON string or empty") + return errormod.Wrap(sdkerrors.ErrJSONUnmarshal, "invalid data, must be a JSON string or empty") } return ValidateTokenID(msg.Id) } @@ -220,10 +222,13 @@ func (msg MsgMintNFT) Type() string { return TypeMsgMintNFT } // ValidateBasic Implements Msg. func (msg MsgMintNFT) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) + return errormod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) } if _, err := sdk.AccAddressFromBech32(msg.Recipient); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid receipt address (%s)", err) + return errormod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid receipt address (%s)", err) + } + if IsIBCDenom(msg.DenomId){ + return errormod.Wrapf(sdkerrors.ErrInvalidRequest, "can not mint nft in denom (%s)", msg.DenomId) } if err := ValidateDenomID(msg.DenomId); err != nil { return err @@ -232,7 +237,7 @@ func (msg MsgMintNFT) ValidateBasic() error { return err } if len(msg.Data) != 0 && !gjson.Valid(msg.Data) { - return sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, "invalid data, must be a JSON string or empty") + return errormod.Wrap(sdkerrors.ErrJSONUnmarshal, "invalid data, must be a JSON string or empty") } return ValidateTokenID(msg.Id) } @@ -270,7 +275,7 @@ func (msg MsgBurnNFT) Type() string { return TypeMsgBurnNFT } // ValidateBasic Implements Msg. func (msg MsgBurnNFT) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) + return errormod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) } if err := ValidateDenomID(msg.DenomId); err != nil { return err @@ -311,10 +316,10 @@ func (msg MsgTransferDenom) Type() string { return TypeMsgTransferDenom } // ValidateBasic Implements Msg. func (msg MsgTransferDenom) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) + return errormod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) } if _, err := sdk.AccAddressFromBech32(msg.Recipient); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid recipient address (%s)", err) + return errormod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid recipient address (%s)", err) } if err := ValidateDenomID(msg.Id); err != nil { return err diff --git a/modules/nft/types/validation.go b/modules/nft/types/validation.go index 69ade71d..3d0cb7c4 100644 --- a/modules/nft/types/validation.go +++ b/modules/nft/types/validation.go @@ -5,7 +5,7 @@ import ( "regexp" "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errormod "cosmossdk.io/errors" ) const ( @@ -34,7 +34,7 @@ var ( func ValidateDenomID(denomID string) error { boolPrifix := strings.HasPrefix(denomID, "tibc-") if !regexpID(denomID) && !boolPrifix { - return sdkerrors.Wrapf(ErrInvalidDenom, "denomID can only accept characters that match the regular expression: (%s),but got (%s)", idString, denomID) + return errormod.Wrapf(ErrInvalidDenom, "denomID can only accept characters that match the regular expression: (%s),but got (%s)", idString, denomID) } return nil } @@ -42,7 +42,7 @@ func ValidateDenomID(denomID string) error { // ValidateTokenID verify that the tokenID is legal func ValidateTokenID(tokenID string) error { if !regexpID(tokenID) { - return sdkerrors.Wrapf(ErrInvalidDenom, "tokenID can only accept characters that match the regular expression: (%s),but got (%s)", idString, tokenID) + return errormod.Wrapf(ErrInvalidDenom, "tokenID can only accept characters that match the regular expression: (%s),but got (%s)", idString, tokenID) } return nil } @@ -50,7 +50,7 @@ func ValidateTokenID(tokenID string) error { // ValidateTokenURI verify that the tokenURI is legal func ValidateTokenURI(tokenURI string) error { if len(tokenURI) > MaxTokenURILen { - return sdkerrors.Wrapf(ErrInvalidTokenURI, "the length of nft uri(%s) only accepts value [0, %d]", tokenURI, MaxTokenURILen) + return errormod.Wrapf(ErrInvalidTokenURI, "the length of nft uri(%s) only accepts value [0, %d]", tokenURI, MaxTokenURILen) } return nil } @@ -70,7 +70,7 @@ func Modify(origin, target string) string { // ValidateKeywords checks if the given denomId begins with `DenomKeywords` func ValidateKeywords(denomId string) error { if regexpKeyword(denomId) { - return sdkerrors.Wrapf(ErrInvalidDenom, "invalid denomId: %s, can not begin with keyword: (%s)", denomId, keywords) + return errormod.Wrapf(ErrInvalidDenom, "invalid denomId: %s, can not begin with keyword: (%s)", denomId, keywords) } return nil }