diff --git a/helpers/base/error.go b/helpers/base/error.go new file mode 100644 index 000000000..9e1fb2624 --- /dev/null +++ b/helpers/base/error.go @@ -0,0 +1,12 @@ +package base + +import ( + "github.com/AssetMantle/modules/helpers" + sdkErrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +var _ helpers.Error = (*sdkErrors.Error)(nil) + +func NewError(codeSpace string, code uint32, description string) helpers.Error { + return sdkErrors.Register(codeSpace, code, description) +} diff --git a/helpers/base/module.go b/helpers/base/module.go index 09eeb8079..c06676dd4 100644 --- a/helpers/base/module.go +++ b/helpers/base/module.go @@ -8,7 +8,6 @@ import ( "fmt" "math/rand" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/cosmos/cosmos-sdk/client" sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" @@ -153,7 +152,7 @@ func (module module) RegisterInvariants(invariantRegistry sdkTypes.InvariantRegi func (module module) Route() sdkTypes.Route { return sdkTypes.NewRoute(module.Name(), func(context sdkTypes.Context, msg sdkTypes.Msg) (*sdkTypes.Result, error) { if module.transactions == nil { - panic(errorConstants.UninitializedUsage.Wrapf("transactions for module %s not initialized", module.Name())) + panic(fmt.Errorf("transactions for module %s not initialized", module.Name())) } if message, ok := msg.(helpers.Message); ok { @@ -161,7 +160,7 @@ func (module module) Route() sdkTypes.Route { return transaction.HandleMessage(sdkTypes.WrapSDKContext(context.WithEventManager(sdkTypes.NewEventManager())), message) } } - return nil, errorConstants.InvalidMessage.Wrapf("message type %T is not supported by module %s", msg, module.Name()) + return nil, fmt.Errorf("message type %T is not supported by module %s", msg, module.Name()) }) } func (module module) QuerierRoute() string { @@ -170,7 +169,7 @@ func (module module) QuerierRoute() string { func (module module) LegacyQuerierHandler(_ *sdkCodec.LegacyAmino) sdkTypes.Querier { return func(context sdkTypes.Context, path []string, requestQuery abciTypes.RequestQuery) ([]byte, error) { if module.queries == nil { - panic(errorConstants.UninitializedUsage.Wrapf("queries for module %s not initialized", module.Name())) + panic(fmt.Errorf("queries for module %s not initialized", module.Name())) } if query := module.queries.GetQuery(path[0]); query != nil { @@ -200,7 +199,7 @@ func (module module) InitGenesis(context sdkTypes.Context, jsonCodec sdkCodec.JS genesisState := module.genesisPrototype().Decode(jsonCodec, rawMessage) if module.mapper == nil || module.parameterManager == nil { - panic(errorConstants.UninitializedUsage.Wrapf("mapper or parameter manager for module %s not initialized", module.Name())) + panic(fmt.Errorf("mapper or parameter manager for module %s not initialized", module.Name())) } genesisState.Import(sdkTypes.WrapSDKContext(context), module.mapper, module.parameterManager) @@ -209,7 +208,7 @@ func (module module) InitGenesis(context sdkTypes.Context, jsonCodec sdkCodec.JS } func (module module) ExportGenesis(context sdkTypes.Context, jsonCodec sdkCodec.JSONCodec) json.RawMessage { if module.mapper == nil || module.parameterManager == nil { - panic(errorConstants.UninitializedUsage.Wrapf("mapper or parameter manager for module %s not initialized", module.Name())) + panic(fmt.Errorf("mapper or parameter manager for module %s not initialized", module.Name())) } return module.genesisPrototype().Export(sdkTypes.WrapSDKContext(context), module.mapper, module.parameterManager).Encode(jsonCodec) @@ -235,7 +234,7 @@ func (module module) DecodeModuleTransactionRequest(transactionName string, rawM return transaction.DecodeTransactionRequest(rawMessage) } - return nil, errorConstants.InvalidMessage.Wrapf("transaction %s is not supported by module %s", transactionName, module.Name()) + return nil, fmt.Errorf("transaction %s is not supported by module %s", transactionName, module.Name()) } func (module module) Initialize(kvStoreKey *sdkTypes.KVStoreKey, paramsSubspace paramsTypes.Subspace, auxiliaryKeepers ...interface{}) helpers.Module { module.mapper = module.mapperPrototype().Initialize(kvStoreKey) diff --git a/helpers/base/parameter_manager.go b/helpers/base/parameter_manager.go index d4843e521..8a29f2827 100644 --- a/helpers/base/parameter_manager.go +++ b/helpers/base/parameter_manager.go @@ -7,7 +7,6 @@ import ( "fmt" "net/http" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" "github.com/AssetMantle/schema/go/lists" baseLists "github.com/AssetMantle/schema/go/lists/base" @@ -51,15 +50,15 @@ func (parameterManager parameterManager) GetValidatableParameter(propertyID ids. return nil } func (parameterManager parameterManager) ValidateParameter(parameter parameters.Parameter) error { - validator := parameterManager.GetValidatableParameter(parameter.GetMetaProperty().GetID()) - if validator != nil { + if validator := parameterManager.GetValidatableParameter(parameter.GetMetaProperty().GetID()); validator != nil { if err := parameter.ValidateBasic(); err != nil { return err } return validator.GetValidator()(parameter.GetMetaProperty().GetData().Get().AsString()) } - return errorConstants.EntityNotFound.Wrapf("parameter with id %s not found", parameter.GetMetaProperty().GetID().AsString()) + + return fmt.Errorf("validator not found for parameter %s", parameter.GetMetaProperty().GetID().AsString()) } func (parameterManager parameterManager) Fetch(context context.Context) helpers.ParameterManager { for _, validatableParameter := range parameterManager.validatableParameters { diff --git a/helpers/base/query.go b/helpers/base/query.go index 6f2467dad..55fe4502f 100644 --- a/helpers/base/query.go +++ b/helpers/base/query.go @@ -4,9 +4,9 @@ package base import ( + "fmt" "net/http" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/cosmos/cosmos-sdk/client" sdkModuleTypes "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/rest" @@ -35,7 +35,7 @@ var _ helpers.Query = (*query)(nil) func (query query) RegisterService(configurator sdkModuleTypes.Configurator) { if query.queryKeeper == nil { - panic(errorConstants.UninitializedUsage.Wrapf("query keeper for query %s not initialized", query.name)) + panic(fmt.Errorf("query keeper for query %s not initialized", query.name)) } query.serviceRegistrar(configurator.QueryServer(), query.queryKeeper) } diff --git a/helpers/base/transaction.go b/helpers/base/transaction.go index cf310d6de..96d97d79c 100644 --- a/helpers/base/transaction.go +++ b/helpers/base/transaction.go @@ -6,12 +6,9 @@ package base import ( "context" "encoding/json" - "github.com/AssetMantle/modules/utilities/rest/queuing" - "net/http" - "reflect" - + "fmt" "github.com/AssetMantle/modules/helpers" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + "github.com/AssetMantle/modules/utilities/rest/queuing" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" sdkCodec "github.com/cosmos/cosmos-sdk/codec" @@ -22,6 +19,8 @@ import ( "github.com/gogo/protobuf/grpc" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" + "net/http" + "reflect" ) type transaction struct { @@ -40,12 +39,12 @@ var _ helpers.Transaction = (*transaction)(nil) func (transaction transaction) GetName() string { return transaction.name } func (transaction transaction) Command() *cobra.Command { runE := func(command *cobra.Command, args []string) error { - context, err := client.GetClientTxContext(command) + Context, err := client.GetClientTxContext(command) if err != nil { return err } - transactionRequest, err := transaction.requestPrototype().FromCLI(transaction.cliCommand, context) + transactionRequest, err := transaction.requestPrototype().FromCLI(transaction.cliCommand, Context) if err != nil { return err } @@ -63,7 +62,7 @@ func (transaction transaction) Command() *cobra.Command { return err } - return tx.GenerateOrBroadcastTxCLI(context, command.Flags(), msg) + return tx.GenerateOrBroadcastTxCLI(Context, command.Flags(), msg) } return transaction.cliCommand.CreateCommand(runE) @@ -81,7 +80,7 @@ func (transaction transaction) RESTRequestHandler(context client.Context) http.H if !rest.ReadRESTReq(responseWriter, httpRequest, context.LegacyAmino, &transactionRequest) { return } else if reflect.TypeOf(transaction.requestPrototype()) != reflect.TypeOf(transactionRequest) { - rest.CheckBadRequestError(responseWriter, errorConstants.InvalidRequest.Wrapf("expected %s, got %s", reflect.TypeOf(transaction.requestPrototype()), reflect.TypeOf(transactionRequest))) + rest.CheckBadRequestError(responseWriter, fmt.Errorf("expected %s, got %s", reflect.TypeOf(transaction.requestPrototype()), reflect.TypeOf(transactionRequest))) return } else if rest.CheckBadRequestError(responseWriter, transactionRequest.Validate()) { return @@ -89,7 +88,7 @@ func (transaction transaction) RESTRequestHandler(context client.Context) http.H baseReq := transactionRequest.GetBaseReq().Sanitize() if !baseReq.ValidateBasic(responseWriter) { - rest.CheckBadRequestError(responseWriter, errorConstants.InvalidRequest.Wrapf("invalid base request")) + rest.CheckBadRequestError(responseWriter, fmt.Errorf("invalid base request")) } msg, err := transactionRequest.MakeMsg() @@ -112,7 +111,7 @@ func (transaction transaction) RegisterInterfaces(interfaceRegistry codecTypes.I } func (transaction transaction) RegisterService(configurator sdkModuleTypes.Configurator) { if transaction.keeper == nil { - panic(errorConstants.UninitializedUsage.Wrapf("keeper for transaction %s is not initialized", transaction.name)) + panic(fmt.Errorf("keeper for transaction %s is not initialized", transaction.name)) } transaction.serviceRegistrar(configurator.MsgServer(), transaction.keeper) } diff --git a/helpers/constants/errors.go b/helpers/constants/errors.go new file mode 100644 index 000000000..e34e9e785 --- /dev/null +++ b/helpers/constants/errors.go @@ -0,0 +1,25 @@ +// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors +// SPDX-License-Identifier: Apache-2.0 + +package constants + +import ( + "github.com/AssetMantle/modules/helpers/base" +) + +const projectRoute = "/AssetMantle" + +var ( + MockError = base.NewError(projectRoute, 100, "mock error") + EntityAlreadyExists = base.NewError(projectRoute, 102, "entity already exists") + EntityNotFound = base.NewError(projectRoute, 103, "entity not found") + IncorrectFormat = base.NewError(projectRoute, 104, "incorrect format") + InvalidMessage = base.NewError(projectRoute, 105, "invalid message") + InsufficientBalance = base.NewError(projectRoute, 106, "insufficient balance") + InvalidParameter = base.NewError(projectRoute, 107, "invalid parameter") + InvalidRequest = base.NewError(projectRoute, 108, "invalid request") + MetaDataError = base.NewError(projectRoute, 109, "meta data error") + NotAuthorized = base.NewError(projectRoute, 110, "not authorized") + UninitializedUsage = base.NewError(projectRoute, 111, "uninitialized usage") + InvalidKey = base.NewError(projectRoute, 112, "invalid key") +) diff --git a/helpers/constants/queryRequest.go b/helpers/constants/queryRequest.go new file mode 100644 index 000000000..cdf29393b --- /dev/null +++ b/helpers/constants/queryRequest.go @@ -0,0 +1,3 @@ +package constants + +const PaginationLimit = 100 diff --git a/helpers/error.go b/helpers/error.go new file mode 100644 index 000000000..64938afc5 --- /dev/null +++ b/helpers/error.go @@ -0,0 +1,7 @@ +package helpers + +type Error interface { + Wrapf(string, ...interface{}) error + Is(error) bool + error +} diff --git a/helpers/key.go b/helpers/key.go index 56c3fcb17..8b61fc560 100644 --- a/helpers/key.go +++ b/helpers/key.go @@ -5,6 +5,7 @@ package helpers // Key SHOULD be derivable from the object it is referencing and SHOULD not be totally arbitrary or sequential type Key interface { + ValidateBasic() error GenerateStorePrefixBytes() []byte GenerateStoreKeyBytes() []byte GeneratePrefixedStoreKeyBytes() []byte diff --git a/helpers/legacy_codec.go b/helpers/legacy_codec.go index c20a92ee0..9f9a52933 100644 --- a/helpers/legacy_codec.go +++ b/helpers/legacy_codec.go @@ -9,4 +9,7 @@ func RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { legacyAmino.RegisterInterface((*QueryResponse)(nil), nil) legacyAmino.RegisterInterface((*QueryRequest)(nil), nil) legacyAmino.RegisterInterface((*TransactionRequest)(nil), nil) + legacyAmino.RegisterInterface((*Request)(nil), nil) + legacyAmino.RegisterInterface((*Error)(nil), nil) + legacyAmino.RegisterInterface((*error)(nil), nil) } diff --git a/utilities/rest/id_getters/docs/identity.go b/utilities/rest/id_getters/docs/identity.go index 9d64508b4..c00e77c71 100644 --- a/utilities/rest/id_getters/docs/identity.go +++ b/utilities/rest/id_getters/docs/identity.go @@ -1,11 +1,11 @@ package docs import ( + "fmt" "net/http" baseData "github.com/AssetMantle/schema/go/data/base" baseDocuments "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/types/rest" @@ -15,11 +15,11 @@ func nameIdentityIDHandler(context client.Context) http.HandlerFunc { return func(responseWriter http.ResponseWriter, httpRequest *http.Request) { transactionRequest := Prototype() if !rest.ReadRESTReq(responseWriter, httpRequest, context.LegacyAmino, &transactionRequest) { - panic(errorConstants.IncorrectFormat) + panic(fmt.Errorf("failed to read request")) } if rest.CheckBadRequestError(responseWriter, transactionRequest.Validate()) { - panic(errorConstants.IncorrectFormat) + panic(fmt.Errorf("failed to validate request")) } rest.PostProcessResponse(responseWriter, context, newResponse(baseDocuments.NewNameIdentity(baseIDs.NewStringID(transactionRequest.(request).Name), baseData.PrototypeListData()).GetNameIdentityID().AsString(), nil)) diff --git a/utilities/rest/id_getters/docs/request.go b/utilities/rest/id_getters/docs/request.go index 0d464c470..2d2a4e52b 100644 --- a/utilities/rest/id_getters/docs/request.go +++ b/utilities/rest/id_getters/docs/request.go @@ -4,12 +4,6 @@ package docs import ( - "encoding/json" - - "github.com/asaskevich/govalidator" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/AssetMantle/modules/helpers" @@ -34,37 +28,16 @@ type request struct { Coins string `json:"coins" valid:"optional"` } -var _ helpers.TransactionRequest = &request{} - -func (request request) FromCLI(command helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { - // TODO implement me - panic("implement me") -} - -func (request) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { - // TODO implement me - panic("implement me") -} - -func (request request) FromJSON(message json.RawMessage) (helpers.TransactionRequest, error) { - // TODO implement me - panic("implement me") -} - -func (request request) MakeMsg() (sdkTypes.Msg, error) { - // TODO implement me - panic("implement me") -} +var _ helpers.Request = &request{} func (request request) Validate() error { - _, err := govalidator.ValidateStruct(request) - return err + return nil } func (request request) GetBaseReq() rest.BaseReq { return request.BaseReq } -func Prototype() helpers.TransactionRequest { +func Prototype() helpers.Request { return request{} } diff --git a/utilities/rest/id_getters/docs/split.go b/utilities/rest/id_getters/docs/split.go index 0be594665..6f29661b8 100644 --- a/utilities/rest/id_getters/docs/split.go +++ b/utilities/rest/id_getters/docs/split.go @@ -1,26 +1,25 @@ package docs import ( - "net/http" - + "fmt" baseDocuments "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/cosmos/cosmos-sdk/client" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" + "net/http" ) func splitIDHandler(context client.Context) http.HandlerFunc { return func(responseWriter http.ResponseWriter, httpRequest *http.Request) { transactionRequest := Prototype() if !rest.ReadRESTReq(responseWriter, httpRequest, context.LegacyAmino, &transactionRequest) { - panic(errorConstants.IncorrectFormat) + panic(fmt.Errorf("failed to read request")) } if rest.CheckBadRequestError(responseWriter, transactionRequest.Validate()) { - panic(errorConstants.IncorrectFormat) + panic(fmt.Errorf("failed to validate request")) } req := transactionRequest.(request) diff --git a/utilities/wasm/custom_encoder.go b/utilities/wasm/custom_encoder.go index 969ca835d..afb866d61 100644 --- a/utilities/wasm/custom_encoder.go +++ b/utilities/wasm/custom_encoder.go @@ -5,9 +5,9 @@ package wasm import ( "encoding/json" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "strings" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/CosmWasm/wasmd/x/wasm" sdkTypes "github.com/cosmos/cosmos-sdk/types" diff --git a/x/assets/genesis/genesis.go b/x/assets/genesis/genesis.go index 95de9481d..5fb5e60b8 100644 --- a/x/assets/genesis/genesis.go +++ b/x/assets/genesis/genesis.go @@ -2,8 +2,8 @@ package genesis import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/lists" "github.com/AssetMantle/schema/go/lists/base" sdkCodec "github.com/cosmos/cosmos-sdk/codec" @@ -34,11 +34,11 @@ func (genesis *Genesis) ValidateBasic(parameterManager helpers.ParameterManager) } if !isPresent { - return errorConstants.IncorrectFormat.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) + return errorConstants.EntityNotFound.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) } if err := parameterManager.ValidateParameter(parameter); err != nil { - return err + return errorConstants.InvalidParameter.Wrapf("parameter %s: %s", parameter.GetMetaProperty().GetKey().AsString(), err.Error()) } } diff --git a/x/assets/key/key.go b/x/assets/key/key.go index 87c018520..4d99e0d3f 100644 --- a/x/assets/key/key.go +++ b/x/assets/key/key.go @@ -4,7 +4,7 @@ package key import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" @@ -13,6 +13,14 @@ import ( var _ helpers.Key = (*Key)(nil) +func (key *Key) ValidateBasic() error { + if key.AssetID != nil { + if err := key.AssetID.ValidateBasic(); err != nil { + return errorConstants.InvalidKey.Wrapf(err.Error()) + } + } + return nil +} func (key *Key) GenerateStorePrefixBytes() []byte { return []byte{} } diff --git a/x/assets/parameters/burn_enabled/parameter.go b/x/assets/parameters/burn_enabled/parameter.go index 7c66d4645..541a4bff5 100644 --- a/x/assets/parameters/burn_enabled/parameter.go +++ b/x/assets/parameters/burn_enabled/parameter.go @@ -4,8 +4,8 @@ package burn_enabled import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/assets/parameters/mint_enabled/parameter.go b/x/assets/parameters/mint_enabled/parameter.go index 4d5fdf1aa..476963b17 100644 --- a/x/assets/parameters/mint_enabled/parameter.go +++ b/x/assets/parameters/mint_enabled/parameter.go @@ -4,8 +4,8 @@ package mint_enabled import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/assets/parameters/renumerate_enabled/parameter.go b/x/assets/parameters/renumerate_enabled/parameter.go index 363c25085..9c9f678aa 100644 --- a/x/assets/parameters/renumerate_enabled/parameter.go +++ b/x/assets/parameters/renumerate_enabled/parameter.go @@ -4,8 +4,8 @@ package renumerate_enabled import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/assets/parameters/unwrap_allowed_coins/parameter.go b/x/assets/parameters/unwrap_allowed_coins/parameter.go index b616ffc2b..de72ce149 100644 --- a/x/assets/parameters/unwrap_allowed_coins/parameter.go +++ b/x/assets/parameters/unwrap_allowed_coins/parameter.go @@ -4,9 +4,9 @@ package unwrap_allowed_coins import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" @@ -16,7 +16,7 @@ import ( ) var ID = constantProperties.UnwrapAllowedCoinsProperty.GetKey() -var Parameter = baseParameters.NewParameter(base.NewMetaProperty(ID, baseData.NewListData())) +var Parameter = baseParameters.NewParameter(base.NewMetaProperty(ID, baseData.NewListData(baseData.NewStringData(sdkTypes.DefaultBondDenom)))) func validator(i interface{}) error { switch value := i.(type) { diff --git a/x/assets/parameters/wrap_allowed_coins/parameter.go b/x/assets/parameters/wrap_allowed_coins/parameter.go index ce827c9ab..320209b57 100644 --- a/x/assets/parameters/wrap_allowed_coins/parameter.go +++ b/x/assets/parameters/wrap_allowed_coins/parameter.go @@ -4,9 +4,9 @@ package wrap_allowed_coins import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/assets/queries/asset/query_keeper.go b/x/assets/queries/asset/query_keeper.go index 6ebcdfaeb..18f3585b0 100644 --- a/x/assets/queries/asset/query_keeper.go +++ b/x/assets/queries/asset/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchRecord(queryRequest.Key)), nil } diff --git a/x/assets/queries/asset/query_request.go b/x/assets/queries/asset/query_request.go index 0932f151d..c4c466f62 100644 --- a/x/assets/queries/asset/query_request.go +++ b/x/assets/queries/asset/query_request.go @@ -8,7 +8,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/AssetMantle/modules/helpers" @@ -30,8 +29,11 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error." // @Router /assets/assets/{assetID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { if assetID, err := baseIDs.PrototypeAssetID().FromString(cliCommand.ReadString(constants.AssetID)); err != nil { diff --git a/x/assets/queries/assets/query_keeper.go b/x/assets/queries/assets/query_keeper.go index 0bc49715c..67e954caa 100644 --- a/x/assets/queries/assets/query_keeper.go +++ b/x/assets/queries/assets/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchPaginated(queryRequest.Key, queryRequest.Limit)), nil } func (queryKeeper queryKeeper) Initialize(mapper helpers.Mapper, _ helpers.ParameterManager, _ []interface{}) helpers.Keeper { diff --git a/x/assets/queries/assets/query_request.go b/x/assets/queries/assets/query_request.go index 95f0cff3b..28cdf836a 100644 --- a/x/assets/queries/assets/query_request.go +++ b/x/assets/queries/assets/query_request.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/types/query" @@ -32,8 +31,19 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error." // @Router /assets/assets/{assetID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + if queryRequest.Limit > constants.PaginationLimit { + return constants.InvalidRequest.Wrapf("limit cannot be greater than %d", constants.PaginationLimit) + } + + if queryRequest.Limit < 0 { + return constants.InvalidRequest.Wrapf("limit cannot be less than 0") + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { assetID, err := baseIDs.PrototypeAssetID().FromString(cliCommand.ReadString(constants.AssetID)) diff --git a/x/assets/transactions/burn/transaction_keeper.go b/x/assets/transactions/burn/transaction_keeper.go index a385d173b..39754f2cc 100644 --- a/x/assets/transactions/burn/transaction_keeper.go +++ b/x/assets/transactions/burn/transaction_keeper.go @@ -5,9 +5,9 @@ package burn import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/properties" propertyConstants "github.com/AssetMantle/schema/go/properties/constants" baseTypes "github.com/AssetMantle/schema/go/types/base" diff --git a/x/assets/transactions/burn/transaction_request.go b/x/assets/transactions/burn/transaction_request.go index 6380375cd..c7f3dfcbb 100644 --- a/x/assets/transactions/burn/transaction_request.go +++ b/x/assets/transactions/burn/transaction_request.go @@ -9,7 +9,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,8 +20,8 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID "` - AssetID string `json:"assetID" valid:"required~required field assetID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field assetID "` + FromID string `json:"fromID"` + AssetID string `json:"assetID"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -38,8 +37,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error in the transaction." // @Router /assets/burn [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/assets/transactions/define/transaction_request.go b/x/assets/transactions/define/transaction_request.go index 6d982d947..7a38533fb 100644 --- a/x/assets/transactions/define/transaction_request.go +++ b/x/assets/transactions/define/transaction_request.go @@ -10,7 +10,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -22,11 +21,11 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - ImmutableMetaProperties string `json:"immutableMetaProperties" valid:"required~required field immutableMetaProperties missing, matches(^.*$)~invalid field immutableMetaProperties"` - ImmutableProperties string `json:"immutableProperties" valid:"required~required field immutableProperties missing, matches(^.*$)~invalid field immutableProperties"` - MutableMetaProperties string `json:"mutableMetaProperties" valid:"required~required field mutableMetaProperties missing, matches(^.*$)~invalid field mutableMetaProperties"` - MutableProperties string `json:"mutableProperties" valid:"required~required field mutableProperties missing, matches(^.*$)~invalid field mutableProperties"` + FromID string `json:"fromID"` + ImmutableMetaProperties string `json:"immutableMetaProperties"` + ImmutableProperties string `json:"immutableProperties"` + MutableMetaProperties string `json:"mutableMetaProperties"` + MutableProperties string `json:"mutableProperties"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -42,10 +41,12 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error in the transaction." // @Router /assets/define [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - if err != nil { + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { return err } + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { diff --git a/x/assets/transactions/deputize/transaction_request.go b/x/assets/transactions/deputize/transaction_request.go index e905c7342..0e4e0a1f2 100644 --- a/x/assets/transactions/deputize/transaction_request.go +++ b/x/assets/transactions/deputize/transaction_request.go @@ -10,7 +10,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -22,10 +21,10 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - ToID string `json:"toID" valid:"required~required field toID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field toID"` - ClassificationID string `json:"classificationID" valid:"required~required field classificationID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field classificationID"` - MaintainedProperties string `json:"maintainedProperties" valid:"required~required field maintainedProperties missing, matches(^.*$)~invalid field maintainedProperties"` + FromID string `json:"fromID"` + ToID string `json:"toID"` + ClassificationID string `json:"classificationID"` + MaintainedProperties string `json:"maintainedProperties"` CanMintAsset bool `json:"canMintAsset"` CanRenumerateAsset bool `json:"canRenumerateAsset"` CanBurnAsset bool `json:"canBurnAsset"` @@ -47,10 +46,12 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /assets/deputize [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - if err != nil { + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { return err } + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { diff --git a/x/assets/transactions/mint/transaction_keeper.go b/x/assets/transactions/mint/transaction_keeper.go index 8b7dd2027..442916ac9 100644 --- a/x/assets/transactions/mint/transaction_keeper.go +++ b/x/assets/transactions/mint/transaction_keeper.go @@ -5,10 +5,10 @@ package mint import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" "github.com/AssetMantle/schema/go/properties" diff --git a/x/assets/transactions/mint/transaction_request.go b/x/assets/transactions/mint/transaction_request.go index de30c67a4..49e0ff013 100644 --- a/x/assets/transactions/mint/transaction_request.go +++ b/x/assets/transactions/mint/transaction_request.go @@ -10,7 +10,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -22,13 +21,13 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - ToID string `json:"toID" valid:"required~required field toID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field toID"` - ClassificationID string `json:"classificationID" valid:"required~required field classificationID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field classificationID"` - ImmutableMetaProperties string `json:"immutableMetaProperties" valid:"required~required field immutableMetaProperties missing, matches(^.*$)~invalid field immutableMetaProperties"` - ImmutableProperties string `json:"immutableProperties" valid:"required~required field immutableProperties missing, matches(^.*$)~invalid field immutableProperties"` - MutableMetaProperties string `json:"mutableMetaProperties" valid:"required~required field mutableMetaProperties missing, matches(^.*$)~invalid field mutableMetaProperties"` - MutableProperties string `json:"mutableProperties" valid:"required~required field mutableProperties missing, matches(^.*$)~invalid field mutableProperties"` + FromID string `json:"fromID"` + ToID string `json:"toID"` + ClassificationID string `json:"classificationID"` + ImmutableMetaProperties string `json:"immutableMetaProperties"` + ImmutableProperties string `json:"immutableProperties"` + MutableMetaProperties string `json:"mutableMetaProperties"` + MutableProperties string `json:"mutableProperties"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -44,10 +43,12 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /assets/mint [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - if err != nil { + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { return err } + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { diff --git a/x/assets/transactions/mutate/transaction_keeper.go b/x/assets/transactions/mutate/transaction_keeper.go index 6a94671e0..9270414e9 100644 --- a/x/assets/transactions/mutate/transaction_keeper.go +++ b/x/assets/transactions/mutate/transaction_keeper.go @@ -5,6 +5,7 @@ package mutate import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/helpers" "github.com/AssetMantle/modules/x/assets/key" @@ -14,7 +15,6 @@ import ( "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" "github.com/AssetMantle/modules/x/maintainers/auxiliaries/maintain" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseLists "github.com/AssetMantle/schema/go/lists/base" baseQualified "github.com/AssetMantle/schema/go/qualified/base" ) diff --git a/x/assets/transactions/mutate/transaction_request.go b/x/assets/transactions/mutate/transaction_request.go index 7a3c18210..9855bc673 100644 --- a/x/assets/transactions/mutate/transaction_request.go +++ b/x/assets/transactions/mutate/transaction_request.go @@ -10,7 +10,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -22,10 +21,10 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - AssetID string `json:"assetID" valid:"required~required field assetID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field assetID"` - MutableMetaProperties string `json:"mutableMetaProperties" valid:"matches(^.*$)~invalid field mutableMetaProperties"` - MutableProperties string `json:"mutableProperties" valid:"matches(^.*$)~invalid field mutableProperties"` + FromID string `json:"fromID"` + AssetID string `json:"assetID"` + MutableMetaProperties string `json:"mutableMetaProperties"` + MutableProperties string `json:"mutableProperties"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -41,10 +40,12 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /assets/mutate [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - if err != nil { + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { return err } + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { diff --git a/x/assets/transactions/renumerate/transaction_keeper.go b/x/assets/transactions/renumerate/transaction_keeper.go index 55b953eab..7276b1b74 100644 --- a/x/assets/transactions/renumerate/transaction_keeper.go +++ b/x/assets/transactions/renumerate/transaction_keeper.go @@ -5,6 +5,7 @@ package renumerate import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/helpers" "github.com/AssetMantle/modules/x/assets/constants" @@ -13,10 +14,8 @@ import ( "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" "github.com/AssetMantle/modules/x/maintainers/auxiliaries/authorize" "github.com/AssetMantle/modules/x/metas/auxiliaries/supplement" - "github.com/AssetMantle/modules/x/splits/auxiliaries/mint" "github.com/AssetMantle/modules/x/splits/auxiliaries/renumerate" "github.com/AssetMantle/schema/go/data" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/properties" propertyConstants "github.com/AssetMantle/schema/go/properties/constants" ) @@ -78,7 +77,7 @@ func (transactionKeeper transactionKeeper) Handle(context context.Context, messa return nil, errorConstants.MetaDataError.Wrapf("asset supply is negative") } - if _, err := transactionKeeper.renumerateAuxiliary.GetKeeper().Help(context, mint.NewAuxiliaryRequest(message.FromID, message.AssetID, supply)); err != nil { + if _, err := transactionKeeper.renumerateAuxiliary.GetKeeper().Help(context, renumerate.NewAuxiliaryRequest(message.FromID, message.AssetID, supply)); err != nil { return nil, err } diff --git a/x/assets/transactions/renumerate/transaction_request.go b/x/assets/transactions/renumerate/transaction_request.go index f8f6bb76d..f1c354622 100644 --- a/x/assets/transactions/renumerate/transaction_request.go +++ b/x/assets/transactions/renumerate/transaction_request.go @@ -9,7 +9,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,8 +20,8 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID "` - AssetID string `json:"assetID" valid:"required~required field assetID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field assetID "` + FromID string `json:"fromID"` + AssetID string `json:"assetID"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -38,8 +37,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /assets/renumerate [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/assets/transactions/revoke/transaction_request.go b/x/assets/transactions/revoke/transaction_request.go index a3fe29131..b10dff2cb 100644 --- a/x/assets/transactions/revoke/transaction_request.go +++ b/x/assets/transactions/revoke/transaction_request.go @@ -9,7 +9,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,9 +20,9 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - ToID string `json:"toID" valid:"required~required field toID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field toID"` - ClassificationID string `json:"classificationID" valid:"required~required field classificationID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field classificationID"` + FromID string `json:"fromID"` + ToID string `json:"toID"` + ClassificationID string `json:"classificationID"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -39,8 +38,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for unexpected error response." // @Router /assets/revoke [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/assets/transactions/send/message.go b/x/assets/transactions/send/message.go index 80f44966c..69853e979 100644 --- a/x/assets/transactions/send/message.go +++ b/x/assets/transactions/send/message.go @@ -4,8 +4,8 @@ package send import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/cosmos/cosmos-sdk/codec" diff --git a/x/assets/transactions/send/message_test.go b/x/assets/transactions/send/message_test.go index 454a14cd2..595bba1dc 100644 --- a/x/assets/transactions/send/message_test.go +++ b/x/assets/transactions/send/message_test.go @@ -4,9 +4,8 @@ package send import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/documents/base" - "github.com/AssetMantle/schema/go/errors" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/tendermint/tendermint/crypto/ed25519" "reflect" "testing" @@ -35,7 +34,7 @@ func TestMessage_ValidateBasic(t *testing.T) { tests := []struct { name string message *Message - wantErr errors.Error + wantErr helpers.Error }{ { "valid message", diff --git a/x/assets/transactions/send/transaction_keeper.go b/x/assets/transactions/send/transaction_keeper.go index 9f354dc6b..4d9272387 100644 --- a/x/assets/transactions/send/transaction_keeper.go +++ b/x/assets/transactions/send/transaction_keeper.go @@ -6,13 +6,13 @@ package send import ( "context" "github.com/AssetMantle/modules/helpers" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/x/assets/key" "github.com/AssetMantle/modules/x/assets/mappable" "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" "github.com/AssetMantle/modules/x/metas/auxiliaries/supplement" "github.com/AssetMantle/modules/x/splits/auxiliaries/transfer" "github.com/AssetMantle/schema/go/data" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/properties" propertyConstants "github.com/AssetMantle/schema/go/properties/constants" baseTypes "github.com/AssetMantle/schema/go/types/base" diff --git a/x/assets/transactions/send/transaction_keeper_test.go b/x/assets/transactions/send/transaction_keeper_test.go index 24d733fd6..dbd32dbb9 100644 --- a/x/assets/transactions/send/transaction_keeper_test.go +++ b/x/assets/transactions/send/transaction_keeper_test.go @@ -6,6 +6,7 @@ package send import ( "context" "github.com/AssetMantle/modules/helpers" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/utilities/random" "github.com/AssetMantle/modules/x/assets/constants" "github.com/AssetMantle/modules/x/assets/mapper" @@ -17,8 +18,6 @@ import ( baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents" baseDocuments "github.com/AssetMantle/schema/go/documents/base" - "github.com/AssetMantle/schema/go/errors" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" @@ -187,7 +186,7 @@ func TestTransactionKeeperTransact(t *testing.T) { args args setup func() want *TransactionResponse - wantErr errors.Error + wantErr helpers.Error }{ {"sendOne", args{fromAddress, assetID, 1}, diff --git a/x/assets/transactions/send/transaction_request.go b/x/assets/transactions/send/transaction_request.go index 92ae248d2..761b6db71 100644 --- a/x/assets/transactions/send/transaction_request.go +++ b/x/assets/transactions/send/transaction_request.go @@ -7,10 +7,8 @@ import ( "encoding/json" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -22,10 +20,10 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - ToID string `json:"toID" valid:"required~required field toID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field toID"` - AssetID string `json:"assetID" valid:"required~required field assetID missing, matches(^(COI|AI)\|((?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4}|[A-Za-z0-9]{32}))$)~invalid field assetID"` - Value string `json:"value" valid:"required~required field value missing, matches(^[0-9.]+$)~invalid field value"` + FromID string `json:"fromID"` + ToID string `json:"toID"` + AssetID string `json:"assetID"` + Value string `json:"value"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -41,8 +39,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /assets/send [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( @@ -71,7 +74,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { value, ok := sdkTypes.NewIntFromString(transactionRequest.Value) if !ok { - return nil, errorConstants.IncorrectFormat.Wrapf("send value %s is not a valid integer", transactionRequest.Value) + return nil, constants.IncorrectFormat.Wrapf("send value %s is not a valid integer", transactionRequest.Value) } fromID, err := baseIDs.PrototypeIdentityID().FromString(transactionRequest.FromID) diff --git a/x/assets/transactions/unwrap/message.go b/x/assets/transactions/unwrap/message.go index 4fd9ca483..8012ee442 100644 --- a/x/assets/transactions/unwrap/message.go +++ b/x/assets/transactions/unwrap/message.go @@ -4,9 +4,9 @@ package unwrap import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/x/assets/constants" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/cosmos/cosmos-sdk/codec" diff --git a/x/assets/transactions/unwrap/message_test.go b/x/assets/transactions/unwrap/message_test.go index a14f8d468..ec8084ce3 100644 --- a/x/assets/transactions/unwrap/message_test.go +++ b/x/assets/transactions/unwrap/message_test.go @@ -5,8 +5,7 @@ package unwrap import ( "github.com/AssetMantle/modules/helpers" - "github.com/AssetMantle/schema/go/errors" - "github.com/AssetMantle/schema/go/errors/constants" + "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/cosmos/cosmos-sdk/codec" @@ -30,7 +29,7 @@ func TestMessage_ValidateBasic(t *testing.T) { tests := []struct { name string message *Message - wantErr errors.Error + wantErr helpers.Error }{ { "valid message", diff --git a/x/assets/transactions/unwrap/transaction_keeper.go b/x/assets/transactions/unwrap/transaction_keeper.go index 68c5df8bf..9f3c9a64b 100644 --- a/x/assets/transactions/unwrap/transaction_keeper.go +++ b/x/assets/transactions/unwrap/transaction_keeper.go @@ -5,11 +5,11 @@ package unwrap import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/x/assets/constants" "github.com/AssetMantle/schema/go/data/base" baseDocuments "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" constantProperties "github.com/AssetMantle/schema/go/properties/constants" sdkTypes "github.com/cosmos/cosmos-sdk/types" bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" diff --git a/x/assets/transactions/unwrap/transaction_keeper_test.go b/x/assets/transactions/unwrap/transaction_keeper_test.go index 8e8e45ea5..ac4dd0028 100644 --- a/x/assets/transactions/unwrap/transaction_keeper_test.go +++ b/x/assets/transactions/unwrap/transaction_keeper_test.go @@ -6,6 +6,7 @@ package unwrap import ( "context" "github.com/AssetMantle/modules/helpers" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/utilities/random" "github.com/AssetMantle/modules/x/assets/constants" "github.com/AssetMantle/modules/x/assets/key" @@ -16,8 +17,6 @@ import ( "github.com/AssetMantle/modules/x/splits/auxiliaries/burn" baseData "github.com/AssetMantle/schema/go/data/base" baseDocuments "github.com/AssetMantle/schema/go/documents/base" - "github.com/AssetMantle/schema/go/errors" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" "github.com/AssetMantle/schema/go/parameters/base" @@ -157,7 +156,7 @@ func TestTransactionKeeperTransact(t *testing.T) { args args setup func() want *TransactionResponse - wantErr errors.Error + wantErr helpers.Error }{ {"unwrapOne", args{genesisAddress, Denom, 1}, diff --git a/x/assets/transactions/unwrap/transaction_request.go b/x/assets/transactions/unwrap/transaction_request.go index 30cd1beaa..58ccbfb6d 100644 --- a/x/assets/transactions/unwrap/transaction_request.go +++ b/x/assets/transactions/unwrap/transaction_request.go @@ -9,7 +9,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,8 +20,8 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - Coins string `json:"coins" valid:"required~required field coins missing, matches(^.*$)~invalid field coins"` + FromID string `json:"fromID"` + Coins string `json:"coins"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -38,8 +37,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /splits/unwrap [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/assets/transactions/wrap/message.go b/x/assets/transactions/wrap/message.go index ddce5d0c6..373d95389 100644 --- a/x/assets/transactions/wrap/message.go +++ b/x/assets/transactions/wrap/message.go @@ -4,9 +4,9 @@ package wrap import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/x/assets/constants" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/cosmos/cosmos-sdk/codec" diff --git a/x/assets/transactions/wrap/message_test.go b/x/assets/transactions/wrap/message_test.go index 02697b02e..b6b01d6fe 100644 --- a/x/assets/transactions/wrap/message_test.go +++ b/x/assets/transactions/wrap/message_test.go @@ -4,8 +4,7 @@ package wrap import ( - "github.com/AssetMantle/schema/go/errors" - "github.com/AssetMantle/schema/go/errors/constants" + "github.com/AssetMantle/modules/helpers/constants" "github.com/tendermint/tendermint/crypto/ed25519" "reflect" "testing" @@ -32,7 +31,7 @@ func TestMessage_ValidateBasic(t *testing.T) { tests := []struct { name string message *Message - wantErr errors.Error + wantErr helpers.Error }{ { "valid message", diff --git a/x/assets/transactions/wrap/transaction_keeper.go b/x/assets/transactions/wrap/transaction_keeper.go index c00a7d364..4d596d68c 100644 --- a/x/assets/transactions/wrap/transaction_keeper.go +++ b/x/assets/transactions/wrap/transaction_keeper.go @@ -6,6 +6,7 @@ package wrap import ( "context" "github.com/AssetMantle/modules/helpers" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/x/assets/constants" "github.com/AssetMantle/modules/x/assets/key" "github.com/AssetMantle/modules/x/assets/record" @@ -13,7 +14,6 @@ import ( "github.com/AssetMantle/modules/x/splits/auxiliaries/mint" "github.com/AssetMantle/schema/go/data/base" baseDocuments "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" constantProperties "github.com/AssetMantle/schema/go/properties/constants" sdkTypes "github.com/cosmos/cosmos-sdk/types" bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" diff --git a/x/assets/transactions/wrap/transaction_keeper_test.go b/x/assets/transactions/wrap/transaction_keeper_test.go index fc97fd1c6..fcf5864ad 100644 --- a/x/assets/transactions/wrap/transaction_keeper_test.go +++ b/x/assets/transactions/wrap/transaction_keeper_test.go @@ -6,6 +6,7 @@ package wrap import ( "context" "github.com/AssetMantle/modules/helpers" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/utilities/random" "github.com/AssetMantle/modules/x/assets/constants" "github.com/AssetMantle/modules/x/assets/key" @@ -15,8 +16,6 @@ import ( "github.com/AssetMantle/modules/x/splits/auxiliaries/mint" baseData "github.com/AssetMantle/schema/go/data/base" baseDocuments "github.com/AssetMantle/schema/go/documents/base" - "github.com/AssetMantle/schema/go/errors" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" "github.com/AssetMantle/schema/go/parameters/base" @@ -154,7 +153,7 @@ func TestTransactionKeeperTransact(t *testing.T) { args args setup func() want *TransactionResponse - wantErr errors.Error + wantErr helpers.Error }{ {"wrapOne", args{genesisAddress, Denom, 1}, diff --git a/x/assets/transactions/wrap/transaction_request.go b/x/assets/transactions/wrap/transaction_request.go index 0d0716a1f..fddfcafdd 100644 --- a/x/assets/transactions/wrap/transaction_request.go +++ b/x/assets/transactions/wrap/transaction_request.go @@ -9,7 +9,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,8 +20,8 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - Coins string `json:"coins" valid:"required~required field coins missing, matches(^.*$)~invalid field coins"` + FromID string `json:"fromID"` + Coins string `json:"coins"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -38,8 +37,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /splits/wrap [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/classifications/auxiliaries/bond/auxiliary_keeper.go b/x/classifications/auxiliaries/bond/auxiliary_keeper.go index cbc8c3cd9..75255685f 100644 --- a/x/classifications/auxiliaries/bond/auxiliary_keeper.go +++ b/x/classifications/auxiliaries/bond/auxiliary_keeper.go @@ -5,8 +5,8 @@ package bond import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" sdkTypes "github.com/cosmos/cosmos-sdk/types" bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" stakingKeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -25,8 +25,15 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } classifications := auxiliaryKeeper.mapper.NewCollection(context).Fetch(key.NewKey(auxiliaryRequest.classificationID)) diff --git a/x/classifications/auxiliaries/bond/auxiliary_request.go b/x/classifications/auxiliaries/bond/auxiliary_request.go index 1ac008c5c..7c69c96f2 100644 --- a/x/classifications/auxiliaries/bond/auxiliary_request.go +++ b/x/classifications/auxiliaries/bond/auxiliary_request.go @@ -4,8 +4,8 @@ package bond import ( + "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" - "github.com/asaskevich/govalidator" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -20,17 +20,19 @@ type auxiliaryRequest struct { var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} + if err := auxiliaryRequest.classificationID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid classification is: %s", err.Error()) + } -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + if auxiliaryRequest.accAddress.Empty() { + return constants.InvalidRequest.Wrapf("address cannot be empty") } + + if auxiliaryRequest.bondAmount.IsNegative() { + return constants.InvalidRequest.Wrapf("bond amount cannot be negative") + } + + return nil } func NewAuxiliaryRequest(classificationID ids.ClassificationID, fromAddress sdkTypes.AccAddress, bondAmount sdkTypes.Int) helpers.AuxiliaryRequest { diff --git a/x/classifications/auxiliaries/burn/auxiliary_keeper.go b/x/classifications/auxiliaries/burn/auxiliary_keeper.go index 3c9602e1d..c48187b70 100644 --- a/x/classifications/auxiliaries/burn/auxiliary_keeper.go +++ b/x/classifications/auxiliaries/burn/auxiliary_keeper.go @@ -5,6 +5,7 @@ package burn import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" sdkTypes "github.com/cosmos/cosmos-sdk/types" bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" @@ -22,8 +23,15 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } if err := auxiliaryKeeper.bankKeeper.BurnCoins(sdkTypes.UnwrapSDKContext(context), constants.ModuleName, sdkTypes.NewCoins(sdkTypes.NewCoin(auxiliaryKeeper.stakingKeeper.BondDenom(sdkTypes.UnwrapSDKContext(context)), auxiliaryRequest.bondAmount))); err != nil { return nil, err diff --git a/x/classifications/auxiliaries/burn/auxiliary_request.go b/x/classifications/auxiliaries/burn/auxiliary_request.go index 7d969c082..5a2cc1a87 100644 --- a/x/classifications/auxiliaries/burn/auxiliary_request.go +++ b/x/classifications/auxiliaries/burn/auxiliary_request.go @@ -4,8 +4,8 @@ package burn import ( + "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" - "github.com/asaskevich/govalidator" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -19,17 +19,15 @@ type auxiliaryRequest struct { var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} + if err := auxiliaryRequest.classificationID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid classification id: %s", err.Error()) + } -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + if auxiliaryRequest.bondAmount.IsNegative() { + return constants.InvalidRequest.Wrapf("bond amount cannot be negative") } + + return nil } func NewAuxiliaryRequest(classificationID ids.ClassificationID, bondAmount sdkTypes.Int) helpers.AuxiliaryRequest { diff --git a/x/classifications/auxiliaries/conform/auxiliary_keeper.go b/x/classifications/auxiliaries/conform/auxiliary_keeper.go index a88aefc7e..de1249139 100644 --- a/x/classifications/auxiliaries/conform/auxiliary_keeper.go +++ b/x/classifications/auxiliaries/conform/auxiliary_keeper.go @@ -5,12 +5,12 @@ package conform import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/modules/helpers" "github.com/AssetMantle/modules/x/classifications/key" "github.com/AssetMantle/modules/x/classifications/mappable" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" ) type auxiliaryKeeper struct { @@ -19,8 +19,16 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } + classifications := auxiliaryKeeper.mapper.NewCollection(context).Fetch(key.NewKey(auxiliaryRequest.ClassificationID)) Mappable := classifications.GetMappable(key.NewKey(auxiliaryRequest.ClassificationID)) diff --git a/x/classifications/auxiliaries/conform/auxiliary_request.go b/x/classifications/auxiliaries/conform/auxiliary_request.go index d0fd51ca1..0a0be9118 100644 --- a/x/classifications/auxiliaries/conform/auxiliary_request.go +++ b/x/classifications/auxiliaries/conform/auxiliary_request.go @@ -4,11 +4,10 @@ package conform import ( + "github.com/AssetMantle/modules/helpers" + "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" "github.com/AssetMantle/schema/go/qualified" - "github.com/asaskevich/govalidator" - - "github.com/AssetMantle/modules/helpers" ) type auxiliaryRequest struct { @@ -20,17 +19,19 @@ type auxiliaryRequest struct { var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} + if err := auxiliaryRequest.ClassificationID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid classification id: %s", err.Error()) + } + + if err := auxiliaryRequest.Immutables.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid immutables: %s", err.Error()) + } -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + if err := auxiliaryRequest.Mutables.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid mutables: %s", err.Error()) } + + return nil } func NewAuxiliaryRequest(classificationID ids.ClassificationID, immutables qualified.Immutables, mutables qualified.Mutables) helpers.AuxiliaryRequest { diff --git a/x/classifications/auxiliaries/conform/auxiliary_request_test.go b/x/classifications/auxiliaries/conform/auxiliary_request_test.go index bcc12daf9..df776dc98 100644 --- a/x/classifications/auxiliaries/conform/auxiliary_request_test.go +++ b/x/classifications/auxiliaries/conform/auxiliary_request_test.go @@ -43,30 +43,6 @@ func TestNewAuxiliaryRequest(t *testing.T) { } } -func Test_auxiliaryRequestFromInterface(t *testing.T) { - immutables := baseQualified.NewImmutables(baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("ImmutableData")))) - mutables := baseQualified.NewMutables(baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID2"), baseData.NewStringData("MutableData")))) - classificationID := baseIDs.NewClassificationID(immutables, mutables) - type args struct { - request helpers.AuxiliaryRequest - } - tests := []struct { - name string - args args - want auxiliaryRequest - }{ - {"+ve", args{NewAuxiliaryRequest(classificationID, immutables, mutables)}, auxiliaryRequest{classificationID, immutables, mutables}}, - {"+ve with nil", args{}, auxiliaryRequest{}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { - t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) - } - }) - } -} - func Test_auxiliaryRequest_Validate(t *testing.T) { immutables := baseQualified.NewImmutables(baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("ImmutableData")))) mutables := baseQualified.NewMutables(baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID2"), baseData.NewStringData("MutableData")))) diff --git a/x/classifications/auxiliaries/define/auxiliary_keeper.go b/x/classifications/auxiliaries/define/auxiliary_keeper.go index 757ed8ec7..a56708058 100644 --- a/x/classifications/auxiliaries/define/auxiliary_keeper.go +++ b/x/classifications/auxiliaries/define/auxiliary_keeper.go @@ -5,10 +5,10 @@ package define import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/properties" baseProperties "github.com/AssetMantle/schema/go/properties/base" @@ -33,13 +33,20 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } + if !auxiliaryKeeper.parameterManager.Fetch(context).GetParameter(constantProperties.DefineEnabledProperty.GetID()).GetMetaProperty().GetData().Get().(data.BooleanData).Get() { return nil, errorConstants.NotAuthorized.Wrapf("classification defining is not enabled") } - auxiliaryRequest := auxiliaryRequestFromInterface(request) - // calculating minimum bound amount totalWeight := sdkTypes.ZeroInt() for _, property := range append(auxiliaryRequest.Immutables.GetImmutablePropertyList().Get(), auxiliaryRequest.Mutables.GetMutablePropertyList().Get()...) { diff --git a/x/classifications/auxiliaries/define/auxiliary_request.go b/x/classifications/auxiliaries/define/auxiliary_request.go index 83205ec55..60e58de24 100644 --- a/x/classifications/auxiliaries/define/auxiliary_request.go +++ b/x/classifications/auxiliaries/define/auxiliary_request.go @@ -4,8 +4,8 @@ package define import ( + "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/qualified" - "github.com/asaskevich/govalidator" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -13,24 +13,26 @@ import ( type auxiliaryRequest struct { sdkTypes.AccAddress - qualified.Immutables `json:"immutables" valid:"required~required field immutableProperties missing"` - qualified.Mutables `json:"mutables" valid:"required~required field mutableProperties missing"` + qualified.Immutables + qualified.Mutables } var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} + if auxiliaryRequest.AccAddress.Empty() { + return constants.InvalidRequest.Wrapf("address cannot be empty") + } -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + if err := auxiliaryRequest.Immutables.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid immutables: %s", err.Error()) } + + if err := auxiliaryRequest.Mutables.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid mutables: %s", err.Error()) + } + + return nil } func NewAuxiliaryRequest(accAddress sdkTypes.AccAddress, immutables qualified.Immutables, mutables qualified.Mutables) helpers.AuxiliaryRequest { diff --git a/x/classifications/auxiliaries/define/auxiliary_request_test.go b/x/classifications/auxiliaries/define/auxiliary_request_test.go index b7456fa30..807832264 100644 --- a/x/classifications/auxiliaries/define/auxiliary_request_test.go +++ b/x/classifications/auxiliaries/define/auxiliary_request_test.go @@ -23,7 +23,5 @@ func Test_Define_Request(t *testing.T) { require.Equal(t, auxiliaryRequest{Immutables: immutables, Mutables: mutables}, testAuxiliaryRequest) require.Equal(t, nil, testAuxiliaryRequest.Validate()) - require.Equal(t, testAuxiliaryRequest, auxiliaryRequestFromInterface(testAuxiliaryRequest)) - require.Equal(t, auxiliaryRequest{}, auxiliaryRequestFromInterface(nil)) } diff --git a/x/classifications/auxiliaries/define/auxiliary_response.go b/x/classifications/auxiliaries/define/auxiliary_response.go index b3ba7d019..6ae7c2cd7 100644 --- a/x/classifications/auxiliaries/define/auxiliary_response.go +++ b/x/classifications/auxiliaries/define/auxiliary_response.go @@ -4,7 +4,7 @@ package define import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" "github.com/AssetMantle/modules/helpers" diff --git a/x/classifications/auxiliaries/define/auxiliary_response_test.go b/x/classifications/auxiliaries/define/auxiliary_response_test.go index 7732ef66c..bbe2e896f 100644 --- a/x/classifications/auxiliaries/define/auxiliary_response_test.go +++ b/x/classifications/auxiliaries/define/auxiliary_response_test.go @@ -4,11 +4,11 @@ package define import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" "reflect" "testing" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" diff --git a/x/classifications/auxiliaries/member/auxiliary_keeper.go b/x/classifications/auxiliaries/member/auxiliary_keeper.go index f48496865..434c52a52 100644 --- a/x/classifications/auxiliaries/member/auxiliary_keeper.go +++ b/x/classifications/auxiliaries/member/auxiliary_keeper.go @@ -5,8 +5,8 @@ package member import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/modules/helpers" @@ -20,8 +20,16 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } + classifications := auxiliaryKeeper.mapper.NewCollection(context).Fetch(key.NewKey(auxiliaryRequest.ClassificationID)) Mappable := classifications.GetMappable(key.NewKey(auxiliaryRequest.ClassificationID)) diff --git a/x/classifications/auxiliaries/member/auxiliary_request.go b/x/classifications/auxiliaries/member/auxiliary_request.go index ae1335480..914926b78 100644 --- a/x/classifications/auxiliaries/member/auxiliary_request.go +++ b/x/classifications/auxiliaries/member/auxiliary_request.go @@ -4,34 +4,38 @@ package member import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + "github.com/AssetMantle/modules/helpers" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" "github.com/AssetMantle/schema/go/qualified" - "github.com/asaskevich/govalidator" - - "github.com/AssetMantle/modules/helpers" ) type auxiliaryRequest struct { - ids.ClassificationID `json:"classificationID" valid:"required~required field classificationID missing"` - qualified.Immutables `json:"immutableProperties"` - qualified.Mutables `json:"mutableProperties"` + ids.ClassificationID + qualified.Immutables + qualified.Mutables } var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} + if err := auxiliaryRequest.ClassificationID.ValidateBasic(); err != nil { + return errorConstants.InvalidRequest.Wrapf("invalid classification id: %s", err.Error()) + } + + if auxiliaryRequest.Immutables != nil { + if err := auxiliaryRequest.Immutables.ValidateBasic(); err != nil { + return errorConstants.InvalidRequest.Wrapf("invalid immutables: %s", err.Error()) + } + } -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - panic(errorConstants.InvalidRequest.Wrapf("invalid request type %T", value)) + if auxiliaryRequest.Mutables != nil { + if err := auxiliaryRequest.Mutables.ValidateBasic(); err != nil { + return errorConstants.InvalidRequest.Wrapf("invalid mutables: %s", err.Error()) + } } + + return nil } func NewAuxiliaryRequest(classificationID ids.ClassificationID, immutables qualified.Immutables, mutables qualified.Mutables) helpers.AuxiliaryRequest { diff --git a/x/classifications/auxiliaries/member/auxiliary_request_test.go b/x/classifications/auxiliaries/member/auxiliary_request_test.go index 167a169d6..e800eb005 100644 --- a/x/classifications/auxiliaries/member/auxiliary_request_test.go +++ b/x/classifications/auxiliaries/member/auxiliary_request_test.go @@ -23,9 +23,5 @@ func Test_Conform_Request(t *testing.T) { require.Equal(t, auxiliaryRequest{classificationID, baseQualified.NewImmutables(immutableProperties), baseQualified.NewMutables(mutableProperties)}, testAuxiliaryRequest) require.Equal(t, nil, testAuxiliaryRequest.Validate()) - require.Equal(t, testAuxiliaryRequest, auxiliaryRequestFromInterface(testAuxiliaryRequest)) - require.Panics(t, func() { - auxiliaryRequestFromInterface(nil) - }) } diff --git a/x/classifications/auxiliaries/unbond/auxiliary_keeper.go b/x/classifications/auxiliaries/unbond/auxiliary_keeper.go index 1ba0b337b..900ff6889 100644 --- a/x/classifications/auxiliaries/unbond/auxiliary_keeper.go +++ b/x/classifications/auxiliaries/unbond/auxiliary_keeper.go @@ -5,6 +5,7 @@ package unbond import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" sdkTypes "github.com/cosmos/cosmos-sdk/types" bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" @@ -22,8 +23,15 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } if err := auxiliaryKeeper.bankKeeper.SendCoinsFromModuleToAccount(sdkTypes.UnwrapSDKContext(context), constants.ModuleName, auxiliaryRequest.accAddress, sdkTypes.NewCoins(sdkTypes.NewCoin(auxiliaryKeeper.stakingKeeper.BondDenom(sdkTypes.UnwrapSDKContext(context)), auxiliaryRequest.bondAmount))); err != nil { return nil, err diff --git a/x/classifications/auxiliaries/unbond/auxiliary_request.go b/x/classifications/auxiliaries/unbond/auxiliary_request.go index e17db1570..0b9c506c0 100644 --- a/x/classifications/auxiliaries/unbond/auxiliary_request.go +++ b/x/classifications/auxiliaries/unbond/auxiliary_request.go @@ -4,8 +4,8 @@ package unbond import ( + "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" - "github.com/asaskevich/govalidator" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -20,17 +20,19 @@ type auxiliaryRequest struct { var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} + if err := auxiliaryRequest.classificationID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid classification id: %s", err.Error()) + } -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + if auxiliaryRequest.accAddress.Empty() { + return constants.InvalidRequest.Wrapf("address cannot be empty") } + + if auxiliaryRequest.bondAmount.IsNegative() { + return constants.InvalidRequest.Wrapf("bond amount cannot be negative") + } + + return nil } func NewAuxiliaryRequest(classificationID ids.ClassificationID, fromAddress sdkTypes.AccAddress, bondAmount sdkTypes.Int) helpers.AuxiliaryRequest { diff --git a/x/classifications/genesis/genesis.go b/x/classifications/genesis/genesis.go index d34f29d82..cb2031a85 100644 --- a/x/classifications/genesis/genesis.go +++ b/x/classifications/genesis/genesis.go @@ -2,9 +2,9 @@ package genesis import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseDocuments "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/lists" "github.com/AssetMantle/schema/go/lists/base" sdkCodec "github.com/cosmos/cosmos-sdk/codec" @@ -35,11 +35,11 @@ func (genesis *Genesis) ValidateBasic(parameterManager helpers.ParameterManager) } if !isPresent { - return errorConstants.IncorrectFormat.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) + return errorConstants.EntityNotFound.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) } if err := parameterManager.ValidateParameter(parameter); err != nil { - return err + return errorConstants.InvalidParameter.Wrapf("parameter %s: %s", parameter.GetMetaProperty().GetKey().AsString(), err.Error()) } } diff --git a/x/classifications/key/key.go b/x/classifications/key/key.go index c571dcc8b..20bdc328e 100644 --- a/x/classifications/key/key.go +++ b/x/classifications/key/key.go @@ -4,7 +4,7 @@ package key import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" @@ -13,6 +13,14 @@ import ( var _ helpers.Key = (*Key)(nil) +func (key *Key) ValidateBasic() error { + if key.ClassificationID != nil { + if err := key.ClassificationID.ValidateBasic(); err != nil { + return errorConstants.InvalidKey.Wrapf(err.Error()) + } + } + return nil +} func (key *Key) GenerateStorePrefixBytes() []byte { return []byte{} } diff --git a/x/classifications/parameters/bond_rate/parameter.go b/x/classifications/parameters/bond_rate/parameter.go index 0976ce8c9..7c81631ae 100644 --- a/x/classifications/parameters/bond_rate/parameter.go +++ b/x/classifications/parameters/bond_rate/parameter.go @@ -4,8 +4,8 @@ package bond_rate import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/classifications/parameters/define_enabled/parameter.go b/x/classifications/parameters/define_enabled/parameter.go index 25bc4f01c..189ca3d0c 100644 --- a/x/classifications/parameters/define_enabled/parameter.go +++ b/x/classifications/parameters/define_enabled/parameter.go @@ -4,8 +4,8 @@ package define_enabled import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/classifications/parameters/max_property_count/parameter.go b/x/classifications/parameters/max_property_count/parameter.go index 96dc94b15..4257b5a39 100644 --- a/x/classifications/parameters/max_property_count/parameter.go +++ b/x/classifications/parameters/max_property_count/parameter.go @@ -4,8 +4,8 @@ package max_property_count import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/classifications/queries/classification/query_keeper.go b/x/classifications/queries/classification/query_keeper.go index f939cf7cd..edf37f41f 100644 --- a/x/classifications/queries/classification/query_keeper.go +++ b/x/classifications/queries/classification/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchRecord(queryRequest.Key)), nil } diff --git a/x/classifications/queries/classification/query_request.go b/x/classifications/queries/classification/query_request.go index 6c9d3bd12..291639fa6 100644 --- a/x/classifications/queries/classification/query_request.go +++ b/x/classifications/queries/classification/query_request.go @@ -8,7 +8,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/AssetMantle/modules/helpers" @@ -30,8 +29,11 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error response." // @Router /classifications/classifications/{classificationID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { if classificationID, err := baseIDs.PrototypeClassificationID().FromString(cliCommand.ReadString(constants.ClassificationID)); err != nil { diff --git a/x/classifications/queries/classifications/query_keeper.go b/x/classifications/queries/classifications/query_keeper.go index f6da36136..d05b5b58b 100644 --- a/x/classifications/queries/classifications/query_keeper.go +++ b/x/classifications/queries/classifications/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchPaginated(queryRequest.Key, queryRequest.Limit)), nil } diff --git a/x/classifications/queries/classifications/query_request.go b/x/classifications/queries/classifications/query_request.go index 2f7cd7956..9ecfaa13f 100644 --- a/x/classifications/queries/classifications/query_request.go +++ b/x/classifications/queries/classifications/query_request.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/types/query" @@ -32,8 +31,19 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error response." // @Router /classifications/classifications/{classificationID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + if queryRequest.Limit > constants.PaginationLimit { + return constants.InvalidRequest.Wrapf("limit cannot be greater than %d", constants.PaginationLimit) + } + + if queryRequest.Limit < 0 { + return constants.InvalidRequest.Wrapf("limit cannot be less than 0") + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { classificationID, err := baseIDs.PrototypeClassificationID().FromString(cliCommand.ReadString(constants.ClassificationID)) diff --git a/x/identities/auxiliaries/authenticate/auxiliary_keeper.go b/x/identities/auxiliaries/authenticate/auxiliary_keeper.go index ae8a62d26..f4931941d 100644 --- a/x/identities/auxiliaries/authenticate/auxiliary_keeper.go +++ b/x/identities/auxiliaries/authenticate/auxiliary_keeper.go @@ -5,8 +5,7 @@ package authenticate import ( "context" - - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/helpers" "github.com/AssetMantle/modules/x/identities/key" @@ -22,8 +21,15 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } Mappable := auxiliaryKeeper.mapper.NewCollection(context).Fetch(key.NewKey(auxiliaryRequest.IdentityID)).GetMappable(key.NewKey(auxiliaryRequest.IdentityID)) if Mappable == nil { diff --git a/x/identities/auxiliaries/authenticate/auxiliary_keeper_test.go b/x/identities/auxiliaries/authenticate/auxiliary_keeper_test.go index 2861cd093..326330c14 100644 --- a/x/identities/auxiliaries/authenticate/auxiliary_keeper_test.go +++ b/x/identities/auxiliaries/authenticate/auxiliary_keeper_test.go @@ -6,6 +6,7 @@ package authenticate import ( "context" "github.com/AssetMantle/modules/helpers" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/utilities/random" "github.com/AssetMantle/modules/x/identities/constants" "github.com/AssetMantle/modules/x/identities/mapper" @@ -14,8 +15,6 @@ import ( baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents" "github.com/AssetMantle/schema/go/documents/base" - "github.com/AssetMantle/schema/go/errors" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/store" @@ -112,7 +111,7 @@ func Test_auxiliaryKeeper_Help(t *testing.T) { setup func() request helpers.AuxiliaryRequest want helpers.AuxiliaryResponse - wantErr errors.Error + wantErr helpers.Error }{ { "valid request", diff --git a/x/identities/auxiliaries/authenticate/auxiliary_request.go b/x/identities/auxiliaries/authenticate/auxiliary_request.go index f8370f50f..b785cd3a3 100644 --- a/x/identities/auxiliaries/authenticate/auxiliary_request.go +++ b/x/identities/auxiliaries/authenticate/auxiliary_request.go @@ -4,32 +4,30 @@ package authenticate import ( + "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" - "github.com/asaskevich/govalidator" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" ) type auxiliaryRequest struct { - Address sdkTypes.AccAddress `json:"address" valid:"required~required field address missing, matches(^[a-z0-9]*$)~field address is invalid"` - ids.IdentityID `json:"identityID" valid:"required~required field identityID missing"` + Address sdkTypes.AccAddress + ids.IdentityID } var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} + if auxiliaryRequest.Address.Empty() { + return constants.InvalidRequest.Wrapf("address cannot be empty") + } -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + if err := auxiliaryRequest.IdentityID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid identity id: %s", err.Error()) } + + return nil } func NewAuxiliaryRequest(address sdkTypes.AccAddress, identityID ids.IdentityID) helpers.AuxiliaryRequest { diff --git a/x/identities/auxiliaries/authenticate/auxiliary_request_test.go b/x/identities/auxiliaries/authenticate/auxiliary_request_test.go index 15492cf46..f355e3d7c 100644 --- a/x/identities/auxiliaries/authenticate/auxiliary_request_test.go +++ b/x/identities/auxiliaries/authenticate/auxiliary_request_test.go @@ -51,27 +51,6 @@ func TestNewAuxiliaryRequest(t *testing.T) { } } -func Test_auxiliaryRequestFromInterface(t *testing.T) { - type args struct { - request helpers.AuxiliaryRequest - } - tests := []struct { - name string - args args - want auxiliaryRequest - }{ - {"+ve with nil", args{}, auxiliaryRequest{}}, - {"+ve", args{auxiliaryRequest{fromAccAddress, testFromID}}, auxiliaryRequest{fromAccAddress, testFromID}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { - t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) - } - }) - } -} - func Test_auxiliaryRequest_Validate(t *testing.T) { type fields struct { Address types.AccAddress diff --git a/x/identities/genesis/genesis.go b/x/identities/genesis/genesis.go index 366d0dfc0..667ff81fe 100644 --- a/x/identities/genesis/genesis.go +++ b/x/identities/genesis/genesis.go @@ -2,9 +2,9 @@ package genesis import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseDocuments "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/lists" "github.com/AssetMantle/schema/go/lists/base" sdkCodec "github.com/cosmos/cosmos-sdk/codec" @@ -42,11 +42,11 @@ func (genesis *Genesis) ValidateBasic(parameterManager helpers.ParameterManager) } if !isPresent { - return errorConstants.IncorrectFormat.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) + return errorConstants.EntityNotFound.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) } if err := parameterManager.ValidateParameter(parameter); err != nil { - return err + return errorConstants.InvalidParameter.Wrapf("parameter %s: %s", parameter.GetMetaProperty().GetKey().AsString(), err.Error()) } } diff --git a/x/identities/key/key.go b/x/identities/key/key.go index 6d85b8434..1660da5ca 100644 --- a/x/identities/key/key.go +++ b/x/identities/key/key.go @@ -4,7 +4,7 @@ package key import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" @@ -13,6 +13,14 @@ import ( var _ helpers.Key = (*Key)(nil) +func (key *Key) ValidateBasic() error { + if key.IdentityID != nil { + if err := key.IdentityID.ValidateBasic(); err != nil { + return errorConstants.InvalidKey.Wrapf(err.Error()) + } + } + return nil +} func (key *Key) GenerateStorePrefixBytes() []byte { return []byte{} } diff --git a/x/identities/parameters/issue_enabled/parameter.go b/x/identities/parameters/issue_enabled/parameter.go index 9d57941b2..19ea4e139 100644 --- a/x/identities/parameters/issue_enabled/parameter.go +++ b/x/identities/parameters/issue_enabled/parameter.go @@ -4,8 +4,8 @@ package issue_enabled import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/identities/parameters/max_provision_address_count/parameter.go b/x/identities/parameters/max_provision_address_count/parameter.go index 272ee7db0..8467a857c 100644 --- a/x/identities/parameters/max_provision_address_count/parameter.go +++ b/x/identities/parameters/max_provision_address_count/parameter.go @@ -4,9 +4,9 @@ package max_provision_address_count import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/data/constants" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/identities/parameters/quash_enabled/parameter.go b/x/identities/parameters/quash_enabled/parameter.go index 2e4a9a6d4..d8b75463a 100644 --- a/x/identities/parameters/quash_enabled/parameter.go +++ b/x/identities/parameters/quash_enabled/parameter.go @@ -4,8 +4,8 @@ package quash_enabled import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/identities/queries/identities/query_keeper.go b/x/identities/queries/identities/query_keeper.go index 3968a3a35..35de5c225 100644 --- a/x/identities/queries/identities/query_keeper.go +++ b/x/identities/queries/identities/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchPaginated(queryRequest.Key, queryRequest.Limit)), nil } diff --git a/x/identities/queries/identities/query_request.go b/x/identities/queries/identities/query_request.go index 11a086ac8..d800dedc5 100644 --- a/x/identities/queries/identities/query_request.go +++ b/x/identities/queries/identities/query_request.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/types/query" @@ -32,8 +31,19 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error response." // @Router /identities/identities/{identityID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + if queryRequest.Limit > constants.PaginationLimit { + return constants.InvalidRequest.Wrapf("limit cannot be greater than %d", constants.PaginationLimit) + } + + if queryRequest.Limit < 0 { + return constants.InvalidRequest.Wrapf("limit cannot be less than 0") + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { identityID, err := baseIDs.PrototypeIdentityID().FromString(cliCommand.ReadString(constants.IdentityID)) diff --git a/x/identities/queries/identity/query_keeper.go b/x/identities/queries/identity/query_keeper.go index 84da34edd..1e6ca171d 100644 --- a/x/identities/queries/identity/query_keeper.go +++ b/x/identities/queries/identity/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchRecord(queryRequest.Key)), nil } diff --git a/x/identities/queries/identity/query_request.go b/x/identities/queries/identity/query_request.go index f1e9cefd4..337f6023c 100644 --- a/x/identities/queries/identity/query_request.go +++ b/x/identities/queries/identity/query_request.go @@ -8,7 +8,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/AssetMantle/modules/helpers" @@ -30,8 +29,11 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error response." // @Router /identities/identities/{identityID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { if identityID, err := baseIDs.PrototypeIdentityID().FromString(cliCommand.ReadString(constants.IdentityID)); err != nil { diff --git a/x/identities/queries/identity/query_response_test.go b/x/identities/queries/identity/query_response_test.go index 52585fe0d..ee90c1c9d 100644 --- a/x/identities/queries/identity/query_response_test.go +++ b/x/identities/queries/identity/query_response_test.go @@ -6,10 +6,10 @@ package identity import ( "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/x/identities/record" base6 "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" baseProperties "github.com/AssetMantle/schema/go/properties/base" diff --git a/x/identities/transactions/define/transaction_keeper.go b/x/identities/transactions/define/transaction_keeper.go index 3ef77e20b..18fc22cf9 100644 --- a/x/identities/transactions/define/transaction_keeper.go +++ b/x/identities/transactions/define/transaction_keeper.go @@ -5,8 +5,8 @@ package define import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseLists "github.com/AssetMantle/schema/go/lists/base" "github.com/AssetMantle/schema/go/properties/constants" "github.com/AssetMantle/schema/go/qualified/base" diff --git a/x/identities/transactions/define/transaction_request.go b/x/identities/transactions/define/transaction_request.go index 5f369b1a4..31c4681de 100644 --- a/x/identities/transactions/define/transaction_request.go +++ b/x/identities/transactions/define/transaction_request.go @@ -10,7 +10,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -22,11 +21,11 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - ImmutableMetaProperties string `json:"immutableMetaProperties" valid:"required~required field immutableMetaProperties missing, matches(^.*$)~invalid field immutableMetaProperties"` - ImmutableProperties string `json:"immutableProperties" valid:"required~required field immutableProperties missing, matches(^.*$)~invalid field immutableProperties"` - MutableMetaProperties string `json:"mutableMetaProperties" valid:"required~required field mutableMetaProperties missing, matches(^.*$)~invalid field mutableMetaProperties"` - MutableProperties string `json:"mutableProperties" valid:"required~required field mutableProperties missing, matches(^.*$)~invalid field mutableProperties"` + FromID string `json:"fromID"` + ImmutableMetaProperties string `json:"immutableMetaProperties"` + ImmutableProperties string `json:"immutableProperties"` + MutableMetaProperties string `json:"mutableMetaProperties"` + MutableProperties string `json:"mutableProperties"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -42,8 +41,9 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /identities/define [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - if err != nil { + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { return err } diff --git a/x/identities/transactions/deputize/transaction_keeper.go b/x/identities/transactions/deputize/transaction_keeper.go index f18c9c311..a964e4eb6 100644 --- a/x/identities/transactions/deputize/transaction_keeper.go +++ b/x/identities/transactions/deputize/transaction_keeper.go @@ -5,13 +5,13 @@ package deputize import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/helpers" "github.com/AssetMantle/modules/x/identities/key" "github.com/AssetMantle/modules/x/identities/mappable" "github.com/AssetMantle/modules/x/identities/utilities" "github.com/AssetMantle/modules/x/maintainers/auxiliaries/deputize" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" ) type transactionKeeper struct { diff --git a/x/identities/transactions/deputize/transaction_request.go b/x/identities/transactions/deputize/transaction_request.go index 3d66d0373..3c4ac42b8 100644 --- a/x/identities/transactions/deputize/transaction_request.go +++ b/x/identities/transactions/deputize/transaction_request.go @@ -10,7 +10,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -22,10 +21,10 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - ToID string `json:"toID" valid:"required~required field toID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field toID"` - ClassificationID string `json:"classificationID" valid:"required~required field classificationID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field classificationID"` - MaintainedProperties string `json:"maintainedProperties" valid:"required~required field maintainedProperties missing, matches(^.*$)~invalid field maintainedProperties"` + FromID string `json:"fromID"` + ToID string `json:"toID"` + ClassificationID string `json:"classificationID"` + MaintainedProperties string `json:"maintainedProperties"` CanIssueIdentity bool `json:"canIssueIdentity"` CanQuashIdentity bool `json:"canQuashIdentity"` CanAddMaintainer bool `json:"canAddMaintainer"` @@ -46,8 +45,9 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /identities/deputize [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - if err != nil { + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { return err } diff --git a/x/identities/transactions/issue/transaction_keeper.go b/x/identities/transactions/issue/transaction_keeper.go index 267cbca40..9a3bcc14a 100644 --- a/x/identities/transactions/issue/transaction_keeper.go +++ b/x/identities/transactions/issue/transaction_keeper.go @@ -5,10 +5,10 @@ package issue import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" "github.com/AssetMantle/schema/go/properties" diff --git a/x/identities/transactions/issue/transaction_request.go b/x/identities/transactions/issue/transaction_request.go index 8dfd699d4..c86610c7d 100644 --- a/x/identities/transactions/issue/transaction_request.go +++ b/x/identities/transactions/issue/transaction_request.go @@ -10,7 +10,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -22,12 +21,12 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID "` - ClassificationID string `json:"classificationID" valid:"required~required field classificationID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field classificationID"` - ImmutableMetaProperties string `json:"immutableMetaProperties" valid:"required~required field immutableMetaProperties missing, matches(^.*$)~invalid field immutableMetaProperties"` - ImmutableProperties string `json:"immutableProperties" valid:"required~required field immutableProperties missing, matches(^.*$)~invalid field immutableProperties"` - MutableMetaProperties string `json:"mutableMetaProperties" valid:"required~required field mutableMetaProperties missing, matches(^.*$)~invalid field mutableMetaProperties"` - MutableProperties string `json:"mutableProperties" valid:"required~required field mutableProperties missing, matches(^.*$)~invalid field mutableProperties"` + FromID string `json:"fromID"` + ClassificationID string `json:"classificationID"` + ImmutableMetaProperties string `json:"immutableMetaProperties"` + ImmutableProperties string `json:"immutableProperties"` + MutableMetaProperties string `json:"mutableMetaProperties"` + MutableProperties string `json:"mutableProperties"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -43,8 +42,9 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /identities/issue [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - if err != nil { + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { return err } diff --git a/x/identities/transactions/name/message.go b/x/identities/transactions/name/message.go index c675286be..9828c2cf8 100644 --- a/x/identities/transactions/name/message.go +++ b/x/identities/transactions/name/message.go @@ -4,6 +4,7 @@ package name import ( + "github.com/AssetMantle/modules/helpers/constants" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" @@ -28,9 +29,15 @@ func (message *Message) ValidateBasic() error { if _, err := sdkTypes.AccAddressFromBech32(message.From); err != nil { return err } + + if message.Name == nil || message.Name.AsString() == "" { + return constants.InvalidRequest.Wrapf("name cannot be empty") + } + if err := message.Name.ValidateBasic(); err != nil { return err } + return nil } func (message *Message) GetSigners() []sdkTypes.AccAddress { diff --git a/x/identities/transactions/name/transaction_keeper.go b/x/identities/transactions/name/transaction_keeper.go index 845cc1dc9..d334d4759 100644 --- a/x/identities/transactions/name/transaction_keeper.go +++ b/x/identities/transactions/name/transaction_keeper.go @@ -5,10 +5,10 @@ package name import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" diff --git a/x/identities/transactions/name/transaction_request.go b/x/identities/transactions/name/transaction_request.go index 2dcbd503a..7c05f37f0 100644 --- a/x/identities/transactions/name/transaction_request.go +++ b/x/identities/transactions/name/transaction_request.go @@ -8,7 +8,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -20,7 +19,7 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - Name string `json:"name" valid:"required~required field name missing, matches(^.*$)~invalid field name"` + Name string `json:"name"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -36,8 +35,9 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /identities/name [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - if err != nil { + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { return err } diff --git a/x/identities/transactions/provision/transaction_keeper.go b/x/identities/transactions/provision/transaction_keeper.go index f5dc36caf..d3b8267d1 100644 --- a/x/identities/transactions/provision/transaction_keeper.go +++ b/x/identities/transactions/provision/transaction_keeper.go @@ -5,9 +5,9 @@ package provision import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/properties/constants" sdkTypes "github.com/cosmos/cosmos-sdk/types" diff --git a/x/identities/transactions/provision/transaction_request.go b/x/identities/transactions/provision/transaction_request.go index 06f2890f4..dd52a4f7b 100644 --- a/x/identities/transactions/provision/transaction_request.go +++ b/x/identities/transactions/provision/transaction_request.go @@ -9,7 +9,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,8 +20,8 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - To string `json:"to" valid:"required~required field to missing, matches(^[a-z0-9]+$)~invalid field to"` - IdentityID string `json:"identityID" valid:"required~required field identityID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field identityID"` + To string `json:"to"` + IdentityID string `json:"identityID"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -38,8 +37,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /identities/provision [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/identities/transactions/quash/transaction_keeper.go b/x/identities/transactions/quash/transaction_keeper.go index e62ca90d8..b04494314 100644 --- a/x/identities/transactions/quash/transaction_keeper.go +++ b/x/identities/transactions/quash/transaction_keeper.go @@ -5,9 +5,9 @@ package quash import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/properties" constantProperties "github.com/AssetMantle/schema/go/properties/constants" baseTypes "github.com/AssetMantle/schema/go/types/base" diff --git a/x/identities/transactions/quash/transaction_request.go b/x/identities/transactions/quash/transaction_request.go index 5605a5fbb..192cf5cba 100644 --- a/x/identities/transactions/quash/transaction_request.go +++ b/x/identities/transactions/quash/transaction_request.go @@ -9,7 +9,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,8 +20,8 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID "` - IdentityID string `json:"identityID" valid:"required~required field identityID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field identityID "` + FromID string `json:"fromID"` + IdentityID string `json:"identityID"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -38,8 +37,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /identities/quash [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/identities/transactions/revoke/transaction_keeper.go b/x/identities/transactions/revoke/transaction_keeper.go index be1a6dd50..4165cca5c 100644 --- a/x/identities/transactions/revoke/transaction_keeper.go +++ b/x/identities/transactions/revoke/transaction_keeper.go @@ -5,12 +5,12 @@ package revoke import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/helpers" "github.com/AssetMantle/modules/x/identities/key" "github.com/AssetMantle/modules/x/identities/mappable" "github.com/AssetMantle/modules/x/maintainers/auxiliaries/revoke" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" ) type transactionKeeper struct { diff --git a/x/identities/transactions/revoke/transaction_request.go b/x/identities/transactions/revoke/transaction_request.go index cad07deae..af71fd483 100644 --- a/x/identities/transactions/revoke/transaction_request.go +++ b/x/identities/transactions/revoke/transaction_request.go @@ -9,7 +9,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,9 +20,9 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - ToID string `json:"toID" valid:"required~required field toID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field toID"` - ClassificationID string `json:"classificationID" valid:"required~required field classificationID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field classificationID"` + FromID string `json:"fromID"` + ToID string `json:"toID"` + ClassificationID string `json:"classificationID"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -39,8 +38,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /identities/revoke [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/identities/transactions/unprovision/transaction_keeper.go b/x/identities/transactions/unprovision/transaction_keeper.go index 324c01acc..d077a5353 100644 --- a/x/identities/transactions/unprovision/transaction_keeper.go +++ b/x/identities/transactions/unprovision/transaction_keeper.go @@ -5,8 +5,8 @@ package unprovision import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" diff --git a/x/identities/transactions/unprovision/transaction_request.go b/x/identities/transactions/unprovision/transaction_request.go index 101abd2c5..1869039f9 100644 --- a/x/identities/transactions/unprovision/transaction_request.go +++ b/x/identities/transactions/unprovision/transaction_request.go @@ -9,7 +9,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,8 +20,8 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - To string `json:"to" valid:"required~required field to missing, matches(^[a-z0-9]+$)~invalid field to"` - IdentityID string `json:"identityID" valid:"required~required field identityID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field identityID"` + To string `json:"to"` + IdentityID string `json:"identityID"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -38,8 +37,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /identities/unprovision [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/identities/transactions/update/transaction_keeper.go b/x/identities/transactions/update/transaction_keeper.go index 0d2cc704a..60f5ff6ed 100644 --- a/x/identities/transactions/update/transaction_keeper.go +++ b/x/identities/transactions/update/transaction_keeper.go @@ -5,6 +5,7 @@ package update import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/helpers" "github.com/AssetMantle/modules/x/classifications/auxiliaries/member" @@ -13,7 +14,6 @@ import ( "github.com/AssetMantle/modules/x/identities/record" "github.com/AssetMantle/modules/x/maintainers/auxiliaries/maintain" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseLists "github.com/AssetMantle/schema/go/lists/base" baseQualified "github.com/AssetMantle/schema/go/qualified/base" ) diff --git a/x/identities/transactions/update/transaction_request.go b/x/identities/transactions/update/transaction_request.go index c8382096e..e277d3a75 100644 --- a/x/identities/transactions/update/transaction_request.go +++ b/x/identities/transactions/update/transaction_request.go @@ -10,7 +10,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -22,10 +21,10 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - IdentityID string `json:"identityID" valid:"required~required field identityID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field identityID"` - MutableMetaProperties string `json:"mutableMetaProperties" valid:"required~required field mutableMetaProperties missing, matches(^.*$)~invalid field mutableMetaProperties"` - MutableProperties string `json:"mutableProperties" valid:"required~required field mutableProperties missing, matches(^.*$)~invalid field mutableProperties"` + FromID string `json:"fromID"` + IdentityID string `json:"identityID"` + MutableMetaProperties string `json:"mutableMetaProperties"` + MutableProperties string `json:"mutableProperties"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -41,10 +40,12 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /identities/update [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - if err != nil { + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { return err } + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { diff --git a/x/maintainers/auxiliaries/authorize/auxiliary_keeper.go b/x/maintainers/auxiliaries/authorize/auxiliary_keeper.go index 7e01a8a77..bc11a4b6c 100644 --- a/x/maintainers/auxiliaries/authorize/auxiliary_keeper.go +++ b/x/maintainers/auxiliaries/authorize/auxiliary_keeper.go @@ -5,10 +5,10 @@ package authorize import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" baseProperties "github.com/AssetMantle/schema/go/properties/base" @@ -26,8 +26,16 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } + maintainerID := baseIDs.NewMaintainerID(base.PrototypeMaintainer().GetClassificationID(), baseQualified.NewImmutables(baseLists.NewPropertyList( baseProperties.NewMetaProperty(constantProperties.MaintainedClassificationIDProperty.GetKey(), baseData.NewIDData(auxiliaryRequest.MaintainedClassificationID)), diff --git a/x/maintainers/auxiliaries/authorize/auxiliary_request.go b/x/maintainers/auxiliaries/authorize/auxiliary_request.go index 69fd8426a..e9df21d0a 100644 --- a/x/maintainers/auxiliaries/authorize/auxiliary_request.go +++ b/x/maintainers/auxiliaries/authorize/auxiliary_request.go @@ -4,32 +4,35 @@ package authorize import ( - "github.com/AssetMantle/schema/go/ids" - "github.com/asaskevich/govalidator" - "github.com/AssetMantle/modules/helpers" + "github.com/AssetMantle/modules/helpers/constants" + "github.com/AssetMantle/schema/go/ids" ) type auxiliaryRequest struct { - MaintainedClassificationID ids.ClassificationID `json:"maintainedClassificationID" valid:"required~required field maintainedClassificationID missing"` - MaintainerIdentityID ids.IdentityID `json:"maintainerIdentityID" valid:"required~required field maintainerIdentityID missing"` - PermissionIDs []ids.StringID `json:"permissionID" valid:"required~required field permissionID missing"` + MaintainedClassificationID ids.ClassificationID + MaintainerIdentityID ids.IdentityID + PermissionIDs []ids.StringID } var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} + if err := auxiliaryRequest.MaintainedClassificationID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid maintained classification id: %s ", err.Error()) + } + + if err := auxiliaryRequest.MaintainerIdentityID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid maintainer identity id: %s", err.Error()) + } -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + for _, permissionID := range auxiliaryRequest.PermissionIDs { + if err := permissionID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid permission id: %s", err.Error()) + } } + + return nil } func NewAuxiliaryRequest(maintainedClassificationID ids.ClassificationID, maintainerIdentityID ids.IdentityID, permissionIDs ...ids.StringID) helpers.AuxiliaryRequest { diff --git a/x/maintainers/auxiliaries/authorize/auxiliary_request_test.go b/x/maintainers/auxiliaries/authorize/auxiliary_request_test.go index 9d2ecea75..006439030 100644 --- a/x/maintainers/auxiliaries/authorize/auxiliary_request_test.go +++ b/x/maintainers/auxiliaries/authorize/auxiliary_request_test.go @@ -48,26 +48,6 @@ func TestNewAuxiliaryRequest(t *testing.T) { } } -func Test_auxiliaryRequestFromInterface(t *testing.T) { - type args struct { - request helpers.AuxiliaryRequest - } - tests := []struct { - name string - args args - want auxiliaryRequest - }{ - {"+ve", args{NewAuxiliaryRequest(classificationID, identityID)}, auxiliaryRequest{classificationID, identityID, []ids.StringID{}}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { - t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) - } - }) - } -} - func Test_auxiliaryRequest_Validate(t *testing.T) { type fields struct { MaintainedClassificationID ids.ClassificationID diff --git a/x/maintainers/auxiliaries/deputize/auxiliary_keeper.go b/x/maintainers/auxiliaries/deputize/auxiliary_keeper.go index e30adac0b..9ff7b7077 100644 --- a/x/maintainers/auxiliaries/deputize/auxiliary_keeper.go +++ b/x/maintainers/auxiliaries/deputize/auxiliary_keeper.go @@ -5,11 +5,11 @@ package deputize import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists" @@ -35,13 +35,20 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } + if !auxiliaryKeeper.parameterManager.Fetch(context).GetParameter(constantProperties.DeputizeAllowedProperty.GetID()).GetMetaProperty().GetData().Get().(data.BooleanData).Get() { return nil, errorConstants.NotAuthorized.Wrapf("deputize is not allowed") } - auxiliaryRequest := auxiliaryRequestFromInterface(request) - fromMaintainerID := baseIDs.NewMaintainerID(base.PrototypeMaintainer().GetClassificationID(), baseQualified.NewImmutables(baseLists.NewPropertyList( baseProperties.NewMetaProperty(constantProperties.MaintainedClassificationIDProperty.GetKey(), baseData.NewIDData(auxiliaryRequest.MaintainedClassificationID)), diff --git a/x/maintainers/auxiliaries/deputize/auxiliary_request.go b/x/maintainers/auxiliaries/deputize/auxiliary_request.go index 1376dec61..d8702b7f3 100644 --- a/x/maintainers/auxiliaries/deputize/auxiliary_request.go +++ b/x/maintainers/auxiliaries/deputize/auxiliary_request.go @@ -4,38 +4,49 @@ package deputize import ( + "github.com/AssetMantle/modules/helpers" + "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" "github.com/AssetMantle/schema/go/lists" - "github.com/asaskevich/govalidator" - - "github.com/AssetMantle/modules/helpers" ) type auxiliaryRequest struct { - FromIdentityID ids.IdentityID `json:"fromIdentityID" valid:"required~required field fromIdentityID missing"` - ToIdentityID ids.IdentityID `json:"toIdentityID" valid:"required~required field toIdentityID missing"` - MaintainedClassificationID ids.ClassificationID `json:"maintainedClassificationID" valid:"required~required field maintainedClassificationID missing"` - MaintainedProperties lists.PropertyList `json:"maintainedProperties" valid:"required~required field maintainedProperties missing"` - CanAddMaintainer bool `json:"canAddMaintainer" valid:"required~required field canAddMaintainer missing"` - CanRemoveMaintainer bool `json:"canRemoveMaintainer" valid:"required~required field canRemoveMaintainer missing"` - CanMutateMaintainer bool `json:"canMutateMaintainer" valid:"required~required field canMutateMaintainer missing"` - PermissionIDs []ids.StringID `json:"permissionIDs" valid:"required~required field permissionIDs missing"` + FromIdentityID ids.IdentityID + ToIdentityID ids.IdentityID + MaintainedClassificationID ids.ClassificationID + MaintainedProperties lists.PropertyList + CanAddMaintainer bool + CanRemoveMaintainer bool + CanMutateMaintainer bool + PermissionIDs []ids.StringID } var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} + if err := auxiliaryRequest.FromIdentityID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid from identity id: %s", err.Error()) + } + + if err := auxiliaryRequest.ToIdentityID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid to identity id: %s", err.Error()) + } + + if err := auxiliaryRequest.MaintainedClassificationID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid maintained classification id: %s", err.Error()) + } -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + if err := auxiliaryRequest.MaintainedProperties.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid maintained properties: %s", err.Error()) } + + for _, permissionID := range auxiliaryRequest.PermissionIDs { + if err := permissionID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid permission id: %s", err.Error()) + } + } + + return nil } func NewAuxiliaryRequest(fromIdentityID ids.IdentityID, toIdentityID ids.IdentityID, maintainedClassificationID ids.ClassificationID, maintainedProperties lists.PropertyList, canAddMaintainer bool, canRemoveMaintainer bool, canMutateMaintainer bool, permissionIDs ...ids.StringID) helpers.AuxiliaryRequest { diff --git a/x/maintainers/auxiliaries/deputize/auxiliary_request_test.go b/x/maintainers/auxiliaries/deputize/auxiliary_request_test.go index d134710d7..57f56be0f 100644 --- a/x/maintainers/auxiliaries/deputize/auxiliary_request_test.go +++ b/x/maintainers/auxiliaries/deputize/auxiliary_request_test.go @@ -41,26 +41,6 @@ func TestNewAuxiliaryRequest(t *testing.T) { } } -func Test_auxiliaryRequestFromInterface(t *testing.T) { - type args struct { - request helpers.AuxiliaryRequest - } - tests := []struct { - name string - args args - want auxiliaryRequest - }{ - {"+ve", args{NewAuxiliaryRequest(testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, []ids.StringID{}...)}, auxiliaryRequest{testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, []ids.StringID{}}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { - t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) - } - }) - } -} - func Test_auxiliaryRequest_Validate(t *testing.T) { type fields struct { FromID ids.IdentityID diff --git a/x/maintainers/auxiliaries/maintain/auxiliary_keeper.go b/x/maintainers/auxiliaries/maintain/auxiliary_keeper.go index e7294fa6b..c8ddf50a3 100644 --- a/x/maintainers/auxiliaries/maintain/auxiliary_keeper.go +++ b/x/maintainers/auxiliaries/maintain/auxiliary_keeper.go @@ -5,10 +5,10 @@ package maintain import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" baseProperties "github.com/AssetMantle/schema/go/properties/base" @@ -26,8 +26,15 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } maintainerID := baseIDs.NewMaintainerID(base.PrototypeMaintainer().GetClassificationID(), baseQualified.NewImmutables(baseLists.NewPropertyList( diff --git a/x/maintainers/auxiliaries/maintain/auxiliary_request.go b/x/maintainers/auxiliaries/maintain/auxiliary_request.go index c96974062..800fbb4a2 100644 --- a/x/maintainers/auxiliaries/maintain/auxiliary_request.go +++ b/x/maintainers/auxiliaries/maintain/auxiliary_request.go @@ -4,33 +4,34 @@ package maintain import ( + "github.com/AssetMantle/modules/helpers" + "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" "github.com/AssetMantle/schema/go/qualified" - "github.com/asaskevich/govalidator" - - "github.com/AssetMantle/modules/helpers" ) type auxiliaryRequest struct { - MaintainedClassificationID ids.ClassificationID `json:"maintainedClassificationID" valid:"required~required field maintainedClassificationID missing"` - ids.IdentityID `json:"identityID" valid:"required~required field identityID missing"` - MaintainedMutables qualified.Mutables `json:"maintainedMutables" valid:"required~required field maintainedProperties missing"` + MaintainedClassificationID ids.ClassificationID + ids.IdentityID + MaintainedMutables qualified.Mutables } var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} + if err := auxiliaryRequest.MaintainedClassificationID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid maintained classification id %s", err.Error()) + } + + if err := auxiliaryRequest.IdentityID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid identity id %s", err.Error()) + } -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + if err := auxiliaryRequest.MaintainedMutables.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid maintained mutables %s", err.Error()) } + + return nil } func NewAuxiliaryRequest(maintainedClassificationID ids.ClassificationID, identityID ids.IdentityID, maintainedMutables qualified.Mutables) helpers.AuxiliaryRequest { diff --git a/x/maintainers/auxiliaries/maintain/auxiliary_request_test.go b/x/maintainers/auxiliaries/maintain/auxiliary_request_test.go index dfa068a1f..a7b28ee9e 100644 --- a/x/maintainers/auxiliaries/maintain/auxiliary_request_test.go +++ b/x/maintainers/auxiliaries/maintain/auxiliary_request_test.go @@ -36,26 +36,6 @@ func TestNewAuxiliaryRequest(t *testing.T) { } } -func Test_auxiliaryRequestFromInterface(t *testing.T) { - type args struct { - request helpers.AuxiliaryRequest - } - tests := []struct { - name string - args args - want auxiliaryRequest - }{ - {"+ve", args{NewAuxiliaryRequest(testClassificationID, testFromID, mutables)}, auxiliaryRequest{testClassificationID, testFromID, mutables}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { - t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) - } - }) - } -} - func Test_auxiliaryRequest_Validate(t *testing.T) { type fields struct { MaintainedClassificationID ids.ClassificationID diff --git a/x/maintainers/auxiliaries/revoke/auxiliary_keeper.go b/x/maintainers/auxiliaries/revoke/auxiliary_keeper.go index 75ca65b5b..898d34d3d 100644 --- a/x/maintainers/auxiliaries/revoke/auxiliary_keeper.go +++ b/x/maintainers/auxiliaries/revoke/auxiliary_keeper.go @@ -5,10 +5,10 @@ package revoke import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" baseProperties "github.com/AssetMantle/schema/go/properties/base" @@ -28,8 +28,16 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } + maintainers := auxiliaryKeeper.mapper.NewCollection(context) fromMaintainerID := baseIDs.NewMaintainerID(base.PrototypeMaintainer().GetClassificationID(), diff --git a/x/maintainers/auxiliaries/revoke/auxiliary_request.go b/x/maintainers/auxiliaries/revoke/auxiliary_request.go index b6e021aef..79fde9333 100644 --- a/x/maintainers/auxiliaries/revoke/auxiliary_request.go +++ b/x/maintainers/auxiliaries/revoke/auxiliary_request.go @@ -4,31 +4,33 @@ package revoke import ( - "github.com/AssetMantle/schema/go/ids" - "github.com/asaskevich/govalidator" - "github.com/AssetMantle/modules/helpers" + "github.com/AssetMantle/modules/helpers/constants" + "github.com/AssetMantle/schema/go/ids" ) type auxiliaryRequest struct { - FromID ids.IdentityID `json:"fromID" valid:"required~required field fromID missing"` - ToID ids.IdentityID `json:"toID" valid:"required~required field toID missing"` - MaintainedClassificationID ids.ClassificationID `json:"maintainedClassificationID" valid:"required~required field maintainedClassificationID missing"` + FromID ids.IdentityID + ToID ids.IdentityID + MaintainedClassificationID ids.ClassificationID } var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + if err := auxiliaryRequest.FromID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid from id: %s", err.Error()) } + + if err := auxiliaryRequest.ToID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid to id: %s", err.Error()) + } + + if err := auxiliaryRequest.MaintainedClassificationID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid maintained classification id: %s", err.Error()) + } + + return nil } func NewAuxiliaryRequest(fromID ids.IdentityID, toID ids.IdentityID, maintainedClassificationID ids.ClassificationID) helpers.AuxiliaryRequest { diff --git a/x/maintainers/auxiliaries/revoke/auxiliary_request_test.go b/x/maintainers/auxiliaries/revoke/auxiliary_request_test.go index 0cb2fb645..80b145c1f 100644 --- a/x/maintainers/auxiliaries/revoke/auxiliary_request_test.go +++ b/x/maintainers/auxiliaries/revoke/auxiliary_request_test.go @@ -34,26 +34,6 @@ func TestNewAuxiliaryRequest(t *testing.T) { } } -func Test_auxiliaryRequestFromInterface(t *testing.T) { - type args struct { - request helpers.AuxiliaryRequest - } - tests := []struct { - name string - args args - want auxiliaryRequest - }{ - {"+ve", args{NewAuxiliaryRequest(testFromID, testFromID, testClassificationID)}, auxiliaryRequest{testFromID, testFromID, testClassificationID}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { - t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) - } - }) - } -} - func Test_auxiliaryRequest_Validate(t *testing.T) { type fields struct { FromID ids.IdentityID diff --git a/x/maintainers/auxiliaries/super/auxiliary_keeper.go b/x/maintainers/auxiliaries/super/auxiliary_keeper.go index de89c7a92..8b61afb66 100644 --- a/x/maintainers/auxiliaries/super/auxiliary_keeper.go +++ b/x/maintainers/auxiliaries/super/auxiliary_keeper.go @@ -5,10 +5,10 @@ package super import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" baseProperties "github.com/AssetMantle/schema/go/properties/base" @@ -27,8 +27,16 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } + maintainerID := baseIDs.NewMaintainerID(base.PrototypeMaintainer().GetClassificationID(), baseQualified.NewImmutables(baseLists.NewPropertyList( baseProperties.NewMetaProperty(constantProperties.MaintainedClassificationIDProperty.GetKey(), baseData.NewIDData(auxiliaryRequest.MaintainedClassificationID)), diff --git a/x/maintainers/auxiliaries/super/auxiliary_request.go b/x/maintainers/auxiliaries/super/auxiliary_request.go index 33155cd45..f64a97934 100644 --- a/x/maintainers/auxiliaries/super/auxiliary_request.go +++ b/x/maintainers/auxiliaries/super/auxiliary_request.go @@ -4,34 +4,42 @@ package super import ( + "github.com/AssetMantle/modules/helpers" + "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" "github.com/AssetMantle/schema/go/qualified" - "github.com/asaskevich/govalidator" - - "github.com/AssetMantle/modules/helpers" ) type auxiliaryRequest struct { - MaintainedClassificationID ids.ClassificationID `json:"maintainedClassificationID" valid:"required~required field maintainedClassificationID missing"` - ToIdentityID ids.IdentityID `json:"toIdentityID" valid:"required~required field identityID missing"` - MaintainedMutables qualified.Mutables `json:"maintainedMutables" valid:"required~required field maintainedMutables missing"` - PermissionIDs []ids.StringID `json:"permissionIDs"` + MaintainedClassificationID ids.ClassificationID + ToIdentityID ids.IdentityID + MaintainedMutables qualified.Mutables + PermissionIDs []ids.StringID } var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} + if err := auxiliaryRequest.MaintainedClassificationID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid maintained classification id: %s", err.Error()) + } -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + if err := auxiliaryRequest.ToIdentityID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid to identity id: %s", err.Error()) } + + if err := auxiliaryRequest.MaintainedMutables.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid maintained mutables: %s", err.Error()) + } + + for _, permissionID := range auxiliaryRequest.PermissionIDs { + if err := permissionID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid permission id: %s", err.Error()) + } + } + + return nil + } func NewAuxiliaryRequest(maintainedClassificationID ids.ClassificationID, toIdentityID ids.IdentityID, maintainedMutables qualified.Mutables, permissionIDs ...ids.StringID) helpers.AuxiliaryRequest { diff --git a/x/maintainers/auxiliaries/super/auxiliary_request_test.go b/x/maintainers/auxiliaries/super/auxiliary_request_test.go index 268035f98..ee0dedc81 100644 --- a/x/maintainers/auxiliaries/super/auxiliary_request_test.go +++ b/x/maintainers/auxiliaries/super/auxiliary_request_test.go @@ -35,26 +35,6 @@ func TestNewAuxiliaryRequest(t *testing.T) { } } -func Test_auxiliaryRequestFromInterface(t *testing.T) { - type args struct { - request helpers.AuxiliaryRequest - } - tests := []struct { - name string - args args - want auxiliaryRequest - }{ - {"+ve", args{NewAuxiliaryRequest(testClassificationID, testFromID, mutables)}, auxiliaryRequest{testClassificationID, testFromID, mutables, []ids.StringID{}}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { - t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) - } - }) - } -} - func Test_auxiliaryRequest_Validate(t *testing.T) { type fields struct { MaintainedClassificationID ids.ClassificationID diff --git a/x/maintainers/genesis/genesis.go b/x/maintainers/genesis/genesis.go index b8353a8d7..2933740c9 100644 --- a/x/maintainers/genesis/genesis.go +++ b/x/maintainers/genesis/genesis.go @@ -2,8 +2,8 @@ package genesis import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/lists" "github.com/AssetMantle/schema/go/lists/base" sdkCodec "github.com/cosmos/cosmos-sdk/codec" @@ -34,11 +34,11 @@ func (genesis *Genesis) ValidateBasic(parameterManager helpers.ParameterManager) } if !isPresent { - return errorConstants.IncorrectFormat.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) + return errorConstants.EntityNotFound.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) } if err := parameterManager.ValidateParameter(parameter); err != nil { - return err + return errorConstants.InvalidParameter.Wrapf("parameter %s: %s", parameter.GetMetaProperty().GetKey().AsString(), err.Error()) } } diff --git a/x/maintainers/key/key.go b/x/maintainers/key/key.go index 915bc9d09..fdfe7606a 100644 --- a/x/maintainers/key/key.go +++ b/x/maintainers/key/key.go @@ -4,7 +4,7 @@ package key import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" @@ -13,6 +13,14 @@ import ( var _ helpers.Key = (*Key)(nil) +func (key *Key) ValidateBasic() error { + if key.MaintainerID != nil { + if err := key.MaintainerID.ValidateBasic(); err != nil { + return errorConstants.InvalidKey.Wrapf(err.Error()) + } + } + return nil +} func (key *Key) GenerateStorePrefixBytes() []byte { return []byte{} } diff --git a/x/maintainers/parameters/deputize_allowed/parameter.go b/x/maintainers/parameters/deputize_allowed/parameter.go index f79a8648d..214a8b689 100644 --- a/x/maintainers/parameters/deputize_allowed/parameter.go +++ b/x/maintainers/parameters/deputize_allowed/parameter.go @@ -4,8 +4,8 @@ package deputize_allowed import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/maintainers/queries/maintainer/query_keeper.go b/x/maintainers/queries/maintainer/query_keeper.go index bc2fac66d..6db6151ba 100644 --- a/x/maintainers/queries/maintainer/query_keeper.go +++ b/x/maintainers/queries/maintainer/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchRecord(queryRequest.Key)), nil } diff --git a/x/maintainers/queries/maintainer/query_request.go b/x/maintainers/queries/maintainer/query_request.go index a9306dcae..5befecb2b 100644 --- a/x/maintainers/queries/maintainer/query_request.go +++ b/x/maintainers/queries/maintainer/query_request.go @@ -8,7 +8,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/AssetMantle/modules/helpers" @@ -30,8 +29,11 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error response." // @Router /maintainers/maintainers/{maintainerID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { diff --git a/x/maintainers/queries/maintainers/query_keeper.go b/x/maintainers/queries/maintainers/query_keeper.go index 7687b5990..6bd48a10f 100644 --- a/x/maintainers/queries/maintainers/query_keeper.go +++ b/x/maintainers/queries/maintainers/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchPaginated(queryRequest.Key, queryRequest.Limit)), nil } diff --git a/x/maintainers/queries/maintainers/query_request.go b/x/maintainers/queries/maintainers/query_request.go index e4cb3c2db..c31546b31 100644 --- a/x/maintainers/queries/maintainers/query_request.go +++ b/x/maintainers/queries/maintainers/query_request.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/types/query" @@ -32,8 +31,19 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error response." // @Router /maintainers/maintainers/{maintainerID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + if queryRequest.Limit > constants.PaginationLimit { + return constants.InvalidRequest.Wrapf("limit cannot be greater than %d", constants.PaginationLimit) + } + + if queryRequest.Limit < 0 { + return constants.InvalidRequest.Wrapf("limit cannot be less than 0") + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { diff --git a/x/metas/auxiliaries/scrub/auxiliary_keeper.go b/x/metas/auxiliaries/scrub/auxiliary_keeper.go index 0f2a22cbb..08ae4b749 100644 --- a/x/metas/auxiliaries/scrub/auxiliary_keeper.go +++ b/x/metas/auxiliaries/scrub/auxiliary_keeper.go @@ -5,6 +5,7 @@ package scrub import ( "context" + "github.com/AssetMantle/modules/helpers/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" @@ -20,8 +21,15 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, constants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } scrubbedPropertyList := make([]properties.Property, len(auxiliaryRequest.PropertyList.Get())) metas := auxiliaryKeeper.mapper.NewCollection(context) diff --git a/x/metas/auxiliaries/scrub/auxiliary_request.go b/x/metas/auxiliaries/scrub/auxiliary_request.go index c69dd7de9..6f79d1729 100644 --- a/x/metas/auxiliaries/scrub/auxiliary_request.go +++ b/x/metas/auxiliaries/scrub/auxiliary_request.go @@ -4,10 +4,9 @@ package scrub import ( - "github.com/AssetMantle/schema/go/lists" - "github.com/asaskevich/govalidator" - "github.com/AssetMantle/modules/helpers" + "github.com/AssetMantle/modules/helpers/constants" + "github.com/AssetMantle/schema/go/lists" ) type auxiliaryRequest struct { @@ -17,17 +16,11 @@ type auxiliaryRequest struct { var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} - -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + if err := auxiliaryRequest.PropertyList.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid property list: %s", err.Error()) } + + return nil } func NewAuxiliaryRequest(propertyList lists.PropertyList) helpers.AuxiliaryRequest { diff --git a/x/metas/auxiliaries/scrub/auxiliary_request_test.go b/x/metas/auxiliaries/scrub/auxiliary_request_test.go index eb881c1bc..2e235bc52 100644 --- a/x/metas/auxiliaries/scrub/auxiliary_request_test.go +++ b/x/metas/auxiliaries/scrub/auxiliary_request_test.go @@ -23,7 +23,4 @@ func Test_Scrub_Request(t *testing.T) { require.Equal(t, auxiliaryRequest{PropertyList: metaPropertyList}, testAuxiliaryRequest) require.Equal(t, nil, testAuxiliaryRequest.Validate()) - require.Equal(t, testAuxiliaryRequest, auxiliaryRequestFromInterface(testAuxiliaryRequest)) - require.Equal(t, auxiliaryRequest{}, auxiliaryRequestFromInterface(nil)) - } diff --git a/x/metas/auxiliaries/scrub/auxiliary_response.go b/x/metas/auxiliaries/scrub/auxiliary_response.go index 94765f465..e08caa007 100644 --- a/x/metas/auxiliaries/scrub/auxiliary_response.go +++ b/x/metas/auxiliaries/scrub/auxiliary_response.go @@ -4,7 +4,7 @@ package scrub import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/lists" "github.com/AssetMantle/modules/helpers" diff --git a/x/metas/auxiliaries/supplement/auxiliary_keeper.go b/x/metas/auxiliaries/supplement/auxiliary_keeper.go index ddcf54800..515be5d15 100644 --- a/x/metas/auxiliaries/supplement/auxiliary_keeper.go +++ b/x/metas/auxiliaries/supplement/auxiliary_keeper.go @@ -5,7 +5,7 @@ package supplement import ( "context" - + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data/base" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" @@ -22,16 +22,25 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } propertyList := baseLists.NewPropertyList() for _, property := range auxiliaryRequest.PropertyList { - if property.IsMeta() { + if property == nil { + continue + } else if property.IsMeta() { propertyList = propertyList.Add(property) } else if property.GetDataID().GetHashID().Compare(baseIDs.GenerateHashID()) == 0 { - if zeroData, err := base.PrototypeAnyData().FromString(property.GetDataID().AsString()); err == nil { + if zeroData, err := base.PrototypeAnyData().FromString(property.GetDataTypeID().AsString()); err == nil { propertyList = propertyList.Add(baseProperties.NewMetaProperty(property.GetKey(), zeroData)) } } else { diff --git a/x/metas/auxiliaries/supplement/auxiliary_keeper_test.go b/x/metas/auxiliaries/supplement/auxiliary_keeper_test.go index 5c2e15579..961717b51 100644 --- a/x/metas/auxiliaries/supplement/auxiliary_keeper_test.go +++ b/x/metas/auxiliaries/supplement/auxiliary_keeper_test.go @@ -4,150 +4,275 @@ package supplement import ( - "context" - "fmt" - "reflect" - "testing" - + "github.com/AssetMantle/modules/helpers" + errorConstants "github.com/AssetMantle/modules/helpers/constants" + "github.com/AssetMantle/modules/x/metas/constants" + "github.com/AssetMantle/modules/x/metas/mapper" + "github.com/AssetMantle/modules/x/metas/record" baseData "github.com/AssetMantle/schema/go/data/base" + dataConstants "github.com/AssetMantle/schema/go/data/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" - baseLists "github.com/AssetMantle/schema/go/lists/base" + "github.com/AssetMantle/schema/go/lists/base" + "github.com/AssetMantle/schema/go/properties" baseProperties "github.com/AssetMantle/schema/go/properties/base" - "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/store" sdkTypes "github.com/cosmos/cosmos-sdk/types" - paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/mock" "github.com/tendermint/tendermint/libs/log" protoTendermintTypes "github.com/tendermint/tendermint/proto/tendermint/types" tendermintDB "github.com/tendermint/tm-db" + "math/rand" + "reflect" + "strconv" + "testing" +) - "github.com/AssetMantle/modules/helpers" - baseHelpers "github.com/AssetMantle/modules/helpers/base" - "github.com/AssetMantle/modules/x/metas/mapper" - "github.com/AssetMantle/modules/x/metas/parameters" +type mockAuxiliaryRequest struct { + mock.Mock +} + +func (*mockAuxiliaryRequest) Validate() error { + return nil +} + +const ( + ChainID = "testChain" ) var ( - propertiesList = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("Data1"))) -) + randomMetaPropertyGenerator = func() properties.MetaProperty { + return baseProperties.NewMetaProperty(baseIDs.NewStringID(strconv.Itoa(rand.Intn(99999999999999999))), baseData.NewStringData(strconv.Itoa(rand.Intn(rand.Intn(99999999999999999))))) + } -type TestKeepers struct { - SupplementKeeper helpers.AuxiliaryKeeper -} + randomPropertiesGenerator = func(n int) (unScrubbed []properties.Property, scrubbed []properties.Property) { + unScrubbed = make([]properties.Property, n) + scrubbed = make([]properties.Property, n) + for i := 0; i < n; i++ { + unScrubbed[i] = randomMetaPropertyGenerator() + scrubbed[i] = unScrubbed[i].(properties.MetaProperty).ScrubData().ToAnyProperty().(*baseProperties.AnyProperty) + } -func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mapper, helpers.ParameterManager) { - var legacyAmino = baseHelpers.CodecPrototype().GetLegacyAmino() - - storeKey := sdkTypes.NewKVStoreKey("test") - paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") - paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") - Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := simapp.MakeTestEncodingConfig() - appCodec := encodingConfig.Marshaler - ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, - legacyAmino, - paramsStoreKey, - paramsTransientStoreKeys, - ) - parameterManager := parameters.Prototype().Initialize(ParamsKeeper.Subspace("test")) - - memDB := tendermintDB.NewMemDB() - commitMultiStore := store.NewCommitMultiStore(memDB) - commitMultiStore.MountStoreWithDB(storeKey, sdkTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsStoreKey, sdkTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, sdkTypes.StoreTypeTransient, memDB) - err := commitMultiStore.LoadLatestVersion() - require.Nil(t, err) - - Context := sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ - ChainID: "test", - }, false, log.NewNopLogger()) - - keepers := TestKeepers{ - SupplementKeeper: keeperPrototype().Initialize(Mapper, parameterManager, []interface{}{}).(helpers.AuxiliaryKeeper), + return unScrubbed, scrubbed } - return Context, keepers, Mapper, parameterManager -} + testPropertiesCount = 100 + testUnScrubbedProperties, testScrubbedProperties = randomPropertiesGenerator(testPropertiesCount) + randomIndex = rand.Intn(testPropertiesCount) -func Test_auxiliaryKeeper_Help(t *testing.T) { - Context, _, Mapper, _ := createTestInput(t) - type fields struct { - mapper helpers.Mapper + invalidMetaProperty = &baseProperties.MetaProperty{ + ID: baseIDs.NewPropertyID(baseIDs.NewStringID("invalid"), baseIDs.NewStringID("invalid")).(*baseIDs.PropertyID), + Data: baseData.NewStringData("invalid").ToAnyData().(*baseData.AnyData), } - type args struct { - context context.Context - request helpers.AuxiliaryRequest + + moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) + AuxiliaryKeeper = auxiliaryKeeper{mapper.Prototype().Initialize(moduleStoreKey)} + + setContext = func() sdkTypes.Context { + memDB := tendermintDB.NewMemDB() + commitMultiStore := store.NewCommitMultiStore(memDB) + commitMultiStore.MountStoreWithDB(moduleStoreKey, sdkTypes.StoreTypeIAVL, memDB) + _ = commitMultiStore.LoadLatestVersion() + return sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ChainID: ChainID}, false, log.NewNopLogger()) + } + + Context = setContext() + + setMeta = func() error { + for _, property := range testUnScrubbedProperties { + AuxiliaryKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)). + Add(record.NewRecord(property.(properties.MetaProperty).GetData())) + } + return nil + } + + _ = setMeta() +) + +func Test_auxiliaryKeeper_Help(t *testing.T) { tests := []struct { name string - fields fields - args args + setup func() + request helpers.AuxiliaryRequest want helpers.AuxiliaryResponse - wantErr bool + wantErr helpers.Error }{ - {"+ve", fields{Mapper}, args{Context.Context(), NewAuxiliaryRequest(baseLists.AnyPropertiesToProperties(propertiesList.Get()...)...)}, NewAuxiliaryResponse(propertiesList), false}, + { + "valid request", + func() {}, + NewAuxiliaryRequest(testScrubbedProperties...), + NewAuxiliaryResponse(base.NewPropertyList(testUnScrubbedProperties...)), + nil, + }, + { + "empty request", + func() {}, + NewAuxiliaryRequest(), + NewAuxiliaryResponse(base.NewPropertyList()), + nil, + }, + { + "invalid request", + func() {}, + NewAuxiliaryRequest(invalidMetaProperty), + nil, + errorConstants.InvalidRequest, + }, + { + "invalid request type", + func() {}, + &mockAuxiliaryRequest{}, + nil, + errorConstants.InvalidRequest, + }, + { + "nil properties", + func() {}, + NewAuxiliaryRequest(nil), + NewAuxiliaryResponse(base.NewPropertyList()), + nil, + }, + { + "one property", + func() {}, + NewAuxiliaryRequest(testScrubbedProperties[randomIndex]), + NewAuxiliaryResponse(base.NewPropertyList(testUnScrubbedProperties[randomIndex])), + nil, + }, + { + "two properties", + func() {}, + NewAuxiliaryRequest(testScrubbedProperties[0], testScrubbedProperties[1]), + NewAuxiliaryResponse(base.NewPropertyList(testUnScrubbedProperties[0], testUnScrubbedProperties[1])), + nil, + }, + { + "prototype property", + func() {}, + NewAuxiliaryRequest(baseProperties.PrototypeMetaProperty().ScrubData()), + NewAuxiliaryResponse(base.NewPropertyList()), + nil, + }, + { + "nil with properties", + func() {}, + NewAuxiliaryRequest(nil, testScrubbedProperties[0], nil, testScrubbedProperties[1], nil), + NewAuxiliaryResponse(base.NewPropertyList(testUnScrubbedProperties[0], testUnScrubbedProperties[1])), + nil, + }, + { + "prototype property with properties", + func() {}, + NewAuxiliaryRequest(baseProperties.PrototypeMetaProperty().ScrubData(), testScrubbedProperties[0], baseProperties.PrototypeMetaProperty().ScrubData(), testScrubbedProperties[1]), + NewAuxiliaryResponse(base.NewPropertyList(testUnScrubbedProperties[0], testUnScrubbedProperties[1])), + nil, + }, + { + "property not present", + func() {}, + NewAuxiliaryRequest(randomMetaPropertyGenerator().ScrubData()), + NewAuxiliaryResponse(base.NewPropertyList()), + nil, + }, + { + "meta property", + func() {}, + NewAuxiliaryRequest(testUnScrubbedProperties[randomIndex]), + NewAuxiliaryResponse(base.NewPropertyList(testUnScrubbedProperties[randomIndex])), + nil, + }, + { + "zero value number", + func() {}, + NewAuxiliaryRequest(&baseProperties.MesaProperty{ + ID: baseIDs.NewPropertyID(baseIDs.NewStringID("zero"), dataConstants.NumberDataTypeID).(*baseIDs.PropertyID), + DataID: &baseIDs.DataID{ + TypeID: dataConstants.NumberDataTypeID.(*baseIDs.StringID), + HashID: baseIDs.PrototypeHashID().(*baseIDs.HashID), + }, + }), + NewAuxiliaryResponse(base.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("zero"), baseData.PrototypeNumberData().ZeroValue()))), + nil, + }, + { + "zero value string", + func() {}, + NewAuxiliaryRequest(&baseProperties.MesaProperty{ + ID: baseIDs.NewPropertyID(baseIDs.NewStringID("zero"), dataConstants.StringDataTypeID).(*baseIDs.PropertyID), + DataID: &baseIDs.DataID{ + TypeID: dataConstants.StringDataTypeID.(*baseIDs.StringID), + HashID: baseIDs.PrototypeHashID().(*baseIDs.HashID), + }, + }), + NewAuxiliaryResponse(base.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("zero"), baseData.PrototypeStringData().ZeroValue()))), + nil, + }, + { + "zero value boolean", + func() {}, + NewAuxiliaryRequest(&baseProperties.MesaProperty{ + ID: baseIDs.NewPropertyID(baseIDs.NewStringID("zero"), dataConstants.BooleanDataTypeID).(*baseIDs.PropertyID), + DataID: &baseIDs.DataID{ + TypeID: dataConstants.BooleanDataTypeID.(*baseIDs.StringID), + HashID: baseIDs.PrototypeHashID().(*baseIDs.HashID), + }, + }, + ), + NewAuxiliaryResponse(base.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("zero"), baseData.PrototypeBooleanData().ZeroValue()))), + nil, + }, + { + "zero value list", + func() {}, + NewAuxiliaryRequest(&baseProperties.MesaProperty{ + ID: baseIDs.NewPropertyID(baseIDs.NewStringID("zero"), dataConstants.ListDataTypeID).(*baseIDs.PropertyID), + DataID: &baseIDs.DataID{ + TypeID: dataConstants.ListDataTypeID.(*baseIDs.StringID), + HashID: baseIDs.PrototypeHashID().(*baseIDs.HashID), + }, + }, + ), + NewAuxiliaryResponse(base.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("zero"), baseData.PrototypeListData().ZeroValue()))), + nil, + }, + { + "zero value linked", + func() {}, + NewAuxiliaryRequest(&baseProperties.MesaProperty{ + ID: baseIDs.NewPropertyID(baseIDs.NewStringID("zero"), dataConstants.LinkedDataTypeID).(*baseIDs.PropertyID), + DataID: &baseIDs.DataID{ + TypeID: dataConstants.LinkedDataTypeID.(*baseIDs.StringID), + HashID: baseIDs.PrototypeHashID().(*baseIDs.HashID), + }, + }, + ), + NewAuxiliaryResponse(base.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("zero"), baseData.PrototypeLinkedData().ZeroValue()))), + nil, + }, + { + "very large number of properties", + func() { + for i := 0; i < 100000; i++ { + AuxiliaryKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)). + Add(record.NewRecord(randomMetaPropertyGenerator().GetData())) + } + }, + NewAuxiliaryRequest(testScrubbedProperties...), + NewAuxiliaryResponse(base.NewPropertyList(testUnScrubbedProperties...)), + nil, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - auxiliaryKeeper := auxiliaryKeeper{ - mapper: tt.fields.mapper, - } - got, err := auxiliaryKeeper.Help(tt.args.context, tt.args.request) - if (err != nil) != tt.wantErr { - t.Errorf("Help() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("Help() got = %v, want %v", got, tt.want) - } - }) - } -} + tt.setup() -func Test_auxiliaryKeeper_Initialize(t *testing.T) { - _, _, Mapper, parameterManager := createTestInput(t) - type fields struct { - mapper helpers.Mapper - } - type args struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - in2 []interface{} - } - tests := []struct { - name string - fields fields - args args - want helpers.Keeper - }{ - {"+ve", fields{Mapper}, args{Mapper, parameterManager, []interface{}{}}, auxiliaryKeeper{Mapper}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - au := auxiliaryKeeper{ - mapper: tt.fields.mapper, - } - if got := au.Initialize(tt.args.mapper, tt.args.parameterManager, tt.args.in2); !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) { - t.Errorf("Initialize() = %v, want %v", got, tt.want) + got, err := AuxiliaryKeeper.Help(sdkTypes.WrapSDKContext(Context), tt.request) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("\n got: \n %v \n want: \n %v", got, tt.want) } - }) - } -} -func Test_keeperPrototype(t *testing.T) { - tests := []struct { - name string - want helpers.AuxiliaryKeeper - }{ - {"+ve", auxiliaryKeeper{}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := keeperPrototype(); !reflect.DeepEqual(got, tt.want) { - t.Errorf("keeperPrototype() = %v, want %v", got, tt.want) + if err != nil && tt.wantErr == nil || err == nil && tt.wantErr != nil || err != nil && tt.wantErr != nil && !tt.wantErr.Is(err) { + t.Errorf("\n want error: \n %v \n got error: \n %v", err, tt.wantErr) } }) } diff --git a/x/metas/auxiliaries/supplement/auxiliary_request.go b/x/metas/auxiliaries/supplement/auxiliary_request.go index 8aa181e79..70ad3ae66 100644 --- a/x/metas/auxiliaries/supplement/auxiliary_request.go +++ b/x/metas/auxiliaries/supplement/auxiliary_request.go @@ -4,30 +4,29 @@ package supplement import ( - "github.com/AssetMantle/schema/go/properties" - "github.com/asaskevich/govalidator" - "github.com/AssetMantle/modules/helpers" + "github.com/AssetMantle/modules/helpers/constants" + "github.com/AssetMantle/schema/go/properties" ) type auxiliaryRequest struct { - PropertyList []properties.Property `json:"propertyList"` + PropertyList []properties.Property } var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} - -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + for _, property := range auxiliaryRequest.PropertyList { + if property == nil { + return constants.InvalidRequest.Wrapf("property cannot be nil") + } + + if err := property.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("invalid property %s: %s", property.GetKey().AsString(), err.Error()) + } } + + return nil } func NewAuxiliaryRequest(propertyList ...properties.Property) helpers.AuxiliaryRequest { diff --git a/x/metas/auxiliaries/supplement/auxiliary_request_test.go b/x/metas/auxiliaries/supplement/auxiliary_request_test.go index f1d9c82c6..f95266aac 100644 --- a/x/metas/auxiliaries/supplement/auxiliary_request_test.go +++ b/x/metas/auxiliaries/supplement/auxiliary_request_test.go @@ -20,7 +20,5 @@ func Test_Supplement_Request(t *testing.T) { require.Equal(t, auxiliaryRequest{PropertyList: []properties.Property{property}}, testAuxiliaryRequest) require.Equal(t, nil, testAuxiliaryRequest.Validate()) - require.Equal(t, testAuxiliaryRequest, auxiliaryRequestFromInterface(testAuxiliaryRequest)) - require.Equal(t, auxiliaryRequest{}, auxiliaryRequestFromInterface(nil)) } diff --git a/x/metas/auxiliaries/supplement/auxiliary_response.go b/x/metas/auxiliaries/supplement/auxiliary_response.go index b2d2a3ff1..91389cba1 100644 --- a/x/metas/auxiliaries/supplement/auxiliary_response.go +++ b/x/metas/auxiliaries/supplement/auxiliary_response.go @@ -4,7 +4,7 @@ package supplement import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/lists" "github.com/AssetMantle/modules/helpers" diff --git a/x/metas/genesis/genesis.go b/x/metas/genesis/genesis.go index 28284119c..8effa68c7 100644 --- a/x/metas/genesis/genesis.go +++ b/x/metas/genesis/genesis.go @@ -2,8 +2,8 @@ package genesis import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/lists" "github.com/AssetMantle/schema/go/lists/base" sdkCodec "github.com/cosmos/cosmos-sdk/codec" @@ -34,11 +34,11 @@ func (genesis *Genesis) ValidateBasic(parameterManager helpers.ParameterManager) } if !isPresent { - return errorConstants.IncorrectFormat.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) + return errorConstants.EntityNotFound.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) } if err := parameterManager.ValidateParameter(parameter); err != nil { - return err + return errorConstants.InvalidParameter.Wrapf("parameter %s: %s", parameter.GetMetaProperty().GetKey().AsString(), err.Error()) } } diff --git a/x/metas/key/key.go b/x/metas/key/key.go index 6f61cf9d6..e7249a623 100644 --- a/x/metas/key/key.go +++ b/x/metas/key/key.go @@ -4,7 +4,7 @@ package key import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" @@ -13,6 +13,14 @@ import ( var _ helpers.Key = (*Key)(nil) +func (key *Key) ValidateBasic() error { + if key.DataID != nil { + if err := key.DataID.ValidateBasic(); err != nil { + return errorConstants.InvalidKey.Wrapf(err.Error()) + } + } + return nil +} func (key *Key) GenerateStorePrefixBytes() []byte { return key.DataID.GetTypeID().Bytes() } diff --git a/x/metas/parameters/reveal_enabled/parameter.go b/x/metas/parameters/reveal_enabled/parameter.go index 32830ce9b..0488628dd 100644 --- a/x/metas/parameters/reveal_enabled/parameter.go +++ b/x/metas/parameters/reveal_enabled/parameter.go @@ -4,8 +4,8 @@ package reveal_enabled import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/metas/queries/meta/query_keeper.go b/x/metas/queries/meta/query_keeper.go index 15a157816..9fa15aaac 100644 --- a/x/metas/queries/meta/query_keeper.go +++ b/x/metas/queries/meta/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchRecord(queryRequest.Key)), nil } diff --git a/x/metas/queries/meta/query_request.go b/x/metas/queries/meta/query_request.go index 07d37044f..883d9a2be 100644 --- a/x/metas/queries/meta/query_request.go +++ b/x/metas/queries/meta/query_request.go @@ -8,7 +8,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/AssetMantle/modules/helpers" @@ -30,8 +29,11 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error response." // @Router /metas/metas/{dataID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { if dataID, err := baseIDs.PrototypeDataID().FromString(cliCommand.ReadString(constants.DataID)); err != nil { diff --git a/x/metas/queries/metas/query_keeper.go b/x/metas/queries/metas/query_keeper.go index a121f631a..40c2e0f2b 100644 --- a/x/metas/queries/metas/query_keeper.go +++ b/x/metas/queries/metas/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchPaginated(queryRequest.Key, queryRequest.Limit)), nil } diff --git a/x/metas/queries/metas/query_request.go b/x/metas/queries/metas/query_request.go index 132eb461d..23cd4eb6a 100644 --- a/x/metas/queries/metas/query_request.go +++ b/x/metas/queries/metas/query_request.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/types/query" @@ -32,8 +31,19 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error response." // @Router /metas/metas/{dataID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + if queryRequest.Limit > constants.PaginationLimit { + return constants.InvalidRequest.Wrapf("limit cannot be greater than %d", constants.PaginationLimit) + } + + if queryRequest.Limit < 0 { + return constants.InvalidRequest.Wrapf("limit cannot be less than 0") + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { dataID, err := baseIDs.PrototypeDataID().FromString(cliCommand.ReadString(constants.DataID)) diff --git a/x/metas/transactions/reveal/transaction_keeper.go b/x/metas/transactions/reveal/transaction_keeper.go index 55acc7d8e..5bdb174fb 100644 --- a/x/metas/transactions/reveal/transaction_keeper.go +++ b/x/metas/transactions/reveal/transaction_keeper.go @@ -5,9 +5,9 @@ package reveal import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/metas/transactions/reveal/transaction_request.go b/x/metas/transactions/reveal/transaction_request.go index 62cf7a2bd..7c55bb291 100644 --- a/x/metas/transactions/reveal/transaction_request.go +++ b/x/metas/transactions/reveal/transaction_request.go @@ -8,7 +8,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/data/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -20,7 +19,7 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - Data string `json:"data" valid:"required~required field data missing, matches(^[DHIS]{1}[|]{1}.*$)"` + Data string `json:"data"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -36,8 +35,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /metas/reveal [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/orders/genesis/genesis.go b/x/orders/genesis/genesis.go index 85bf6dce6..9cf810e6d 100644 --- a/x/orders/genesis/genesis.go +++ b/x/orders/genesis/genesis.go @@ -2,8 +2,8 @@ package genesis import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/lists" "github.com/AssetMantle/schema/go/lists/base" sdkCodec "github.com/cosmos/cosmos-sdk/codec" @@ -34,11 +34,11 @@ func (genesis *Genesis) ValidateBasic(parameterManager helpers.ParameterManager) } if !isPresent { - return errorConstants.IncorrectFormat.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) + return errorConstants.EntityNotFound.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) } if err := parameterManager.ValidateParameter(parameter); err != nil { - return err + return errorConstants.InvalidParameter.Wrapf("parameter %s: %s", parameter.GetMetaProperty().GetKey().AsString(), err.Error()) } } diff --git a/x/orders/key/key.go b/x/orders/key/key.go index 78da57130..1ab1ae53f 100644 --- a/x/orders/key/key.go +++ b/x/orders/key/key.go @@ -4,7 +4,7 @@ package key import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" @@ -13,6 +13,14 @@ import ( var _ helpers.Key = (*Key)(nil) +func (key *Key) ValidateBasic() error { + if key.OrderID != nil { + if err := key.OrderID.ValidateBasic(); err != nil { + return errorConstants.InvalidKey.Wrapf(err.Error()) + } + } + return nil +} func (key *Key) GenerateStorePrefixBytes() []byte { return []byte{} } diff --git a/x/orders/parameters/max_order_life/parameter.go b/x/orders/parameters/max_order_life/parameter.go index bbc5a378f..722871e38 100644 --- a/x/orders/parameters/max_order_life/parameter.go +++ b/x/orders/parameters/max_order_life/parameter.go @@ -4,8 +4,8 @@ package max_order_life import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" baseProperties "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/orders/parameters/put_enabled/parameter.go b/x/orders/parameters/put_enabled/parameter.go index 7897f1ee5..2d30520b8 100644 --- a/x/orders/parameters/put_enabled/parameter.go +++ b/x/orders/parameters/put_enabled/parameter.go @@ -4,8 +4,8 @@ package put_enabled import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/orders/queries/order/query_keeper.go b/x/orders/queries/order/query_keeper.go index f1e22d964..f5f5faacf 100644 --- a/x/orders/queries/order/query_keeper.go +++ b/x/orders/queries/order/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchRecord(queryRequest.Key)), nil } diff --git a/x/orders/queries/order/query_request.go b/x/orders/queries/order/query_request.go index ed6218361..b915a0921 100644 --- a/x/orders/queries/order/query_request.go +++ b/x/orders/queries/order/query_request.go @@ -8,7 +8,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/AssetMantle/modules/helpers" @@ -30,8 +29,11 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error response." // @Router /orders/orders/{orderID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { if orderID, err := baseIDs.PrototypeOrderID().FromString(cliCommand.ReadString(constants.OrderID)); err != nil { diff --git a/x/orders/queries/orders/query_keeper.go b/x/orders/queries/orders/query_keeper.go index 58a067a03..5dc2e54f6 100644 --- a/x/orders/queries/orders/query_keeper.go +++ b/x/orders/queries/orders/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchPaginated(queryRequest.Key, queryRequest.Limit)), nil } diff --git a/x/orders/queries/orders/query_request.go b/x/orders/queries/orders/query_request.go index a9302a6ad..da879d74b 100644 --- a/x/orders/queries/orders/query_request.go +++ b/x/orders/queries/orders/query_request.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/types/query" @@ -32,8 +31,19 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error response." // @Router /orders/orders/{orderID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + if queryRequest.Limit > constants.PaginationLimit { + return constants.InvalidRequest.Wrapf("limit cannot be greater than %d", constants.PaginationLimit) + } + + if queryRequest.Limit < 0 { + return constants.InvalidRequest.Wrapf("limit cannot be less than 0") + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { orderID, err := baseIDs.PrototypeOrderID().FromString(cliCommand.ReadString(constants.OrderID)) diff --git a/x/orders/transactions/cancel/transaction_keeper.go b/x/orders/transactions/cancel/transaction_keeper.go index b9f5efb73..8ff2e6102 100644 --- a/x/orders/transactions/cancel/transaction_keeper.go +++ b/x/orders/transactions/cancel/transaction_keeper.go @@ -5,6 +5,7 @@ package cancel import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/helpers" "github.com/AssetMantle/modules/x/classifications/auxiliaries/unbond" @@ -16,7 +17,6 @@ import ( "github.com/AssetMantle/modules/x/orders/mappable" "github.com/AssetMantle/modules/x/orders/record" "github.com/AssetMantle/modules/x/splits/auxiliaries/transfer" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" ) type transactionKeeper struct { diff --git a/x/orders/transactions/cancel/transaction_request.go b/x/orders/transactions/cancel/transaction_request.go index 9f1e96a76..cc25b3528 100644 --- a/x/orders/transactions/cancel/transaction_request.go +++ b/x/orders/transactions/cancel/transaction_request.go @@ -9,7 +9,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,8 +20,8 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - OrderID string `json:"orderID" valid:"required~required field orderID missing, matches(^[A-Za-z0-9-_=.|*]+$)~invalid field orderID"` + FromID string `json:"fromID"` + OrderID string `json:"orderID"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -38,8 +37,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /orders/cancel [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/orders/transactions/define/transaction_request.go b/x/orders/transactions/define/transaction_request.go index b0e05a577..f03bda5dd 100644 --- a/x/orders/transactions/define/transaction_request.go +++ b/x/orders/transactions/define/transaction_request.go @@ -10,7 +10,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -22,11 +21,11 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - ImmutableMetaProperties string `json:"immutableMetaProperties" valid:"required~required field immutableMetaProperties missing, matches(^.*$)~invalid field immutableMetaProperties"` - ImmutableProperties string `json:"immutableProperties" valid:"required~required field immutableProperties missing, matches(^.*$)~invalid field immutableProperties"` - MutableMetaProperties string `json:"mutableMetaProperties" valid:"required~required field mutableMetaProperties missing, matches(^.*$)~invalid field mutableMetaProperties"` - MutableProperties string `json:"mutableProperties" valid:"required~required field mutableProperties missing, matches(^.*$)~invalid field mutableProperties"` + FromID string `json:"fromID"` + ImmutableMetaProperties string `json:"immutableMetaProperties"` + ImmutableProperties string `json:"immutableProperties"` + MutableMetaProperties string `json:"mutableMetaProperties"` + MutableProperties string `json:"mutableProperties"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -42,8 +41,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /orders/define [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/orders/transactions/deputize/transaction_request.go b/x/orders/transactions/deputize/transaction_request.go index 5f230fa42..9878dcf1d 100644 --- a/x/orders/transactions/deputize/transaction_request.go +++ b/x/orders/transactions/deputize/transaction_request.go @@ -10,7 +10,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -22,10 +21,10 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - ToID string `json:"toID" valid:"required~required field toID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field toID"` - ClassificationID string `json:"classificationID" valid:"required~required field classificationID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field classificationID"` - MaintainedProperties string `json:"maintainedProperties" valid:"required~required field maintainedProperties missing, matches(^.*$)~invalid field maintainedProperties"` + FromID string `json:"fromID"` + ToID string `json:"toID"` + ClassificationID string `json:"classificationID"` + MaintainedProperties string `json:"maintainedProperties"` CanMakeOrder bool `json:"canMakeOrder"` CanCancelOrder bool `json:"canCancelOrder"` CanAddMaintainer bool `json:"canAddMaintainer"` @@ -46,8 +45,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /orders/deputize [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/orders/transactions/get/transaction_keeper.go b/x/orders/transactions/get/transaction_keeper.go index d79f8fcd9..98465073e 100644 --- a/x/orders/transactions/get/transaction_keeper.go +++ b/x/orders/transactions/get/transaction_keeper.go @@ -5,8 +5,8 @@ package get import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" diff --git a/x/orders/transactions/get/transaction_request.go b/x/orders/transactions/get/transaction_request.go index 8cf4091ab..396e92380 100644 --- a/x/orders/transactions/get/transaction_request.go +++ b/x/orders/transactions/get/transaction_request.go @@ -9,7 +9,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,8 +20,8 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - OrderID string `json:"orderID" valid:"required~required field orderID missing, matches(^[A-Za-z0-9-_=.|*]+$)~invalid field orderID"` + FromID string `json:"fromID"` + OrderID string `json:"orderID"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -38,8 +37,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /orders/take [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/orders/transactions/immediate/message.go b/x/orders/transactions/immediate/message.go index a6848825f..5a6178072 100644 --- a/x/orders/transactions/immediate/message.go +++ b/x/orders/transactions/immediate/message.go @@ -4,8 +4,8 @@ package immediate import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists" diff --git a/x/orders/transactions/immediate/transaction_keeper.go b/x/orders/transactions/immediate/transaction_keeper.go index c6a7e3d31..f504a7282 100644 --- a/x/orders/transactions/immediate/transaction_keeper.go +++ b/x/orders/transactions/immediate/transaction_keeper.go @@ -5,11 +5,11 @@ package immediate import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" baseProperties "github.com/AssetMantle/schema/go/properties/base" diff --git a/x/orders/transactions/immediate/transaction_request.go b/x/orders/transactions/immediate/transaction_request.go index a822bd927..c998b5e0f 100644 --- a/x/orders/transactions/immediate/transaction_request.go +++ b/x/orders/transactions/immediate/transaction_request.go @@ -7,12 +7,10 @@ import ( "encoding/json" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists/base" baseTypes "github.com/AssetMantle/schema/go/types/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -24,18 +22,18 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - ClassificationID string `json:"classificationID" valid:"required~required field classificationID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field classificationID"` - TakerID string `json:"takerID" valid:"required~required field takerID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field takerID"` - MakerAssetID string `json:"makerAssetID" valid:"required~required field makerAssetID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field makerAssetID"` - TakerAssetID string `json:"takerAssetID" valid:"required~required field takerAssetID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field takerAssetID"` - ExpiresIn int64 `json:"expiresIn" valid:"required~required field expiresIn missing, matches(^[0-9]+$)~invalid field expiresIn"` - MakerSplit string `json:"makerSplit" valid:"required~required field makerSplit missing, matches(^[0-9.]+$)~invalid field makerSplit"` - TakerSplit string `json:"takerSplit" valid:"required~required field takerSplit missing, matches(^[0-9.]+$)~invalid field takerSplit"` - ImmutableMetaProperties string `json:"immutableMetaProperties" valid:"required~required field immutableMetaProperties missing, matches(^.*$)~invalid field immutableMetaProperties"` - ImmutableProperties string `json:"immutableProperties" valid:"required~required field immutableProperties missing, matches(^.*$)~invalid field immutableProperties"` - MutableMetaProperties string `json:"mutableMetaProperties" valid:"required~required field mutableMetaProperties missing, matches(^.*$)~invalid field mutableMetaProperties"` - MutableProperties string `json:"mutableProperties" valid:"required~required field mutableProperties missing, matches(^.*$)~invalid field mutableProperties"` + FromID string `json:"fromID"` + ClassificationID string `json:"classificationID"` + TakerID string `json:"takerID"` + MakerAssetID string `json:"makerAssetID"` + TakerAssetID string `json:"takerAssetID"` + ExpiresIn int64 `json:"expiresIn"` + MakerSplit string `json:"makerSplit"` + TakerSplit string `json:"takerSplit"` + ImmutableMetaProperties string `json:"immutableMetaProperties"` + ImmutableProperties string `json:"immutableProperties"` + MutableMetaProperties string `json:"mutableMetaProperties"` + MutableProperties string `json:"mutableProperties"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -51,8 +49,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /orders/immediate [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( @@ -115,12 +118,12 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { makerSplit, ok := sdkTypes.NewIntFromString(transactionRequest.MakerSplit) if !ok { - return nil, errorConstants.IncorrectFormat.Wrapf("maker split %s is not a valid integer", transactionRequest.MakerSplit) + return nil, constants.IncorrectFormat.Wrapf("maker split %s is not a valid integer", transactionRequest.MakerSplit) } takerSplit, ok := sdkTypes.NewIntFromString(transactionRequest.TakerSplit) if !ok { - return nil, errorConstants.IncorrectFormat.Wrapf("taker split %s is not a valid integer", transactionRequest.TakerSplit) + return nil, constants.IncorrectFormat.Wrapf("taker split %s is not a valid integer", transactionRequest.TakerSplit) } immutableMetaProperties, err := base.NewPropertyList().FromMetaPropertiesString(transactionRequest.ImmutableMetaProperties) diff --git a/x/orders/transactions/make/message.go b/x/orders/transactions/make/message.go index 95fee8ef7..abe439dcb 100644 --- a/x/orders/transactions/make/message.go +++ b/x/orders/transactions/make/message.go @@ -4,8 +4,8 @@ package make import ( + "github.com/AssetMantle/modules/helpers/constants" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists" diff --git a/x/orders/transactions/make/transaction_keeper.go b/x/orders/transactions/make/transaction_keeper.go index 4c5269780..586f153a2 100644 --- a/x/orders/transactions/make/transaction_keeper.go +++ b/x/orders/transactions/make/transaction_keeper.go @@ -5,11 +5,11 @@ package make import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" "github.com/AssetMantle/schema/go/properties" diff --git a/x/orders/transactions/make/transaction_request.go b/x/orders/transactions/make/transaction_request.go index 51d3b4823..157bf2a91 100644 --- a/x/orders/transactions/make/transaction_request.go +++ b/x/orders/transactions/make/transaction_request.go @@ -7,12 +7,10 @@ import ( "encoding/json" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists/base" baseTypes "github.com/AssetMantle/schema/go/types/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -24,18 +22,18 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - ClassificationID string `json:"classificationID" valid:"required~required field classificationID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field classificationID"` - TakerID string `json:"takerID" valid:"required~required field takerID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field takerID"` - MakerAssetID string `json:"makerAssetID" valid:"required~required field makerAssetID missing, matches(^(COI|AI)\|((?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4}|[A-Za-z0-9]{32}))$)~invalid field makerAssetID"` - TakerAssetID string `json:"takerAssetID" valid:"required~required field takerAssetID missing, matches(^(COI|AI)\|((?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4}|[A-Za-z0-9]{32}))$)~invalid field takerAssetID"` - ExpiresIn int64 `json:"expiresIn" valid:"required~required field expiresIn missing, matches(^[0-9]+$)~invalid field expiresIn"` - MakerSplit string `json:"makerSplit" valid:"required~required field makerSplit missing, matches(^[0-9.]+$)~invalid field makerSplit"` - TakerSplit string `json:"takerSplit" valid:"required~required field takerSplit missing, matches(^[0-9.]+$)~invalid field takerSplit"` - ImmutableMetaProperties string `json:"immutableMetaProperties" valid:"required~required field immutableMetaProperties missing, matches(^.*$)~invalid field immutableMetaProperties"` - ImmutableProperties string `json:"immutableProperties" valid:"required~required field immutableProperties missing, matches(^.*$)~invalid field immutableProperties"` - MutableMetaProperties string `json:"mutableMetaProperties" valid:"required~required field mutableMetaProperties missing, matches(^.*$)~invalid field mutableMetaProperties"` - MutableProperties string `json:"mutableProperties" valid:"required~required field mutableProperties missing, matches(^.*$)~invalid field mutableProperties"` + FromID string `json:"fromID"` + ClassificationID string `json:"classificationID"` + TakerID string `json:"takerID"` + MakerAssetID string `json:"makerAssetID"` + TakerAssetID string `json:"takerAssetID"` + ExpiresIn int64 `json:"expiresIn"` + MakerSplit string `json:"makerSplit"` + TakerSplit string `json:"takerSplit"` + ImmutableMetaProperties string `json:"immutableMetaProperties"` + ImmutableProperties string `json:"immutableProperties"` + MutableMetaProperties string `json:"mutableMetaProperties"` + MutableProperties string `json:"mutableProperties"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -51,8 +49,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /orders/make [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( @@ -90,12 +93,12 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { makerSplit, ok := sdkTypes.NewIntFromString(transactionRequest.MakerSplit) if !ok { - return nil, errorConstants.IncorrectFormat.Wrapf("maker split %s is not a valid integer", transactionRequest.MakerSplit) + return nil, constants.IncorrectFormat.Wrapf("maker split %s is not a valid integer", transactionRequest.MakerSplit) } takerSplit, ok := sdkTypes.NewIntFromString(transactionRequest.TakerSplit) if !ok { - return nil, errorConstants.IncorrectFormat.Wrapf("taker split %s is not a valid integer", transactionRequest.TakerSplit) + return nil, constants.IncorrectFormat.Wrapf("taker split %s is not a valid integer", transactionRequest.TakerSplit) } immutableMetaProperties, err := base.NewPropertyList().FromMetaPropertiesString(transactionRequest.ImmutableMetaProperties) diff --git a/x/orders/transactions/modify/message.go b/x/orders/transactions/modify/message.go index 85d816a80..3d5556b96 100644 --- a/x/orders/transactions/modify/message.go +++ b/x/orders/transactions/modify/message.go @@ -4,8 +4,8 @@ package modify import ( + "github.com/AssetMantle/modules/helpers/constants" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists" diff --git a/x/orders/transactions/modify/transaction_keeper.go b/x/orders/transactions/modify/transaction_keeper.go index ee653374f..f79619626 100644 --- a/x/orders/transactions/modify/transaction_keeper.go +++ b/x/orders/transactions/modify/transaction_keeper.go @@ -5,10 +5,10 @@ package modify import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseLists "github.com/AssetMantle/schema/go/lists/base" baseProperties "github.com/AssetMantle/schema/go/properties/base" propertyConstants "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/orders/transactions/modify/transaction_request.go b/x/orders/transactions/modify/transaction_request.go index 1b8400c89..96e5c92a2 100644 --- a/x/orders/transactions/modify/transaction_request.go +++ b/x/orders/transactions/modify/transaction_request.go @@ -7,12 +7,10 @@ import ( "encoding/json" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/lists/base" baseTypes "github.com/AssetMantle/schema/go/types/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -24,13 +22,13 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - OrderID string `json:"orderID" valid:"required~required field orderID missing, matches(^[A-Za-z0-9-_|=.*]+$)~invalid field orderID"` - TakerSplit string `json:"takerSplit" valid:"required~required field takerSplit missing, matches(^[0-9.]+$)~invalid field takerSplit"` - MakerSplit string `json:"makerSplit" valid:"required~required field makerSplit missing, matches(^[0-9.]+$)~invalid field makerSplit"` - ExpiresIn int64 `json:"expiresIn" valid:"required~required field expiresIn missing, matches(^[0-9]+$)~invalid field expiresIn"` - MutableMetaProperties string `json:"mutableMetaProperties" valid:"required~required field mutableMetaProperties missing, matches(^.*$)~invalid field mutableMetaProperties"` - MutableProperties string `json:"mutableProperties" valid:"required~required field mutableProperties missing, matches(^.*$)~invalid field mutableProperties"` + FromID string `json:"fromID"` + OrderID string `json:"orderID"` + TakerSplit string `json:"takerSplit"` + MakerSplit string `json:"makerSplit"` + ExpiresIn int64 `json:"expiresIn"` + MutableMetaProperties string `json:"mutableMetaProperties"` + MutableProperties string `json:"mutableProperties"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -46,8 +44,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /orders/modify [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( @@ -80,12 +83,12 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { makerSplit, ok := sdkTypes.NewIntFromString(transactionRequest.MakerSplit) if !ok { - return nil, errorConstants.IncorrectFormat.Wrapf("maker split %s is not a valid integer", transactionRequest.MakerSplit) + return nil, constants.IncorrectFormat.Wrapf("maker split %s is not a valid integer", transactionRequest.MakerSplit) } takerSplit, ok := sdkTypes.NewIntFromString(transactionRequest.TakerSplit) if !ok { - return nil, errorConstants.IncorrectFormat.Wrapf("taker split %s is not a valid integer", transactionRequest.TakerSplit) + return nil, constants.IncorrectFormat.Wrapf("taker split %s is not a valid integer", transactionRequest.TakerSplit) } mutableMetaProperties, err := base.NewPropertyList().FromMetaPropertiesString(transactionRequest.MutableMetaProperties) diff --git a/x/orders/transactions/put/message.go b/x/orders/transactions/put/message.go index 1d93a8626..f8db80d47 100644 --- a/x/orders/transactions/put/message.go +++ b/x/orders/transactions/put/message.go @@ -4,8 +4,8 @@ package put import ( + "github.com/AssetMantle/modules/helpers/constants" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" typesSchema "github.com/AssetMantle/schema/go/types" diff --git a/x/orders/transactions/put/transaction_keeper.go b/x/orders/transactions/put/transaction_keeper.go index 5b9c4bed9..48af24776 100644 --- a/x/orders/transactions/put/transaction_keeper.go +++ b/x/orders/transactions/put/transaction_keeper.go @@ -5,10 +5,10 @@ package put import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" propertyConstants "github.com/AssetMantle/schema/go/properties/constants" baseTypes "github.com/AssetMantle/schema/go/types/base" sdkTypes "github.com/cosmos/cosmos-sdk/types" diff --git a/x/orders/transactions/put/transaction_request.go b/x/orders/transactions/put/transaction_request.go index d3149038b..e57538c8e 100644 --- a/x/orders/transactions/put/transaction_request.go +++ b/x/orders/transactions/put/transaction_request.go @@ -7,11 +7,9 @@ import ( "encoding/json" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseTypes "github.com/AssetMantle/schema/go/types/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -23,12 +21,12 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - MakerAssetID string `json:"makerAssetID" valid:"required~required field makerAssetID missing, matches(^(COI|AI)\|((?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4}|[A-Za-z0-9]{32}))$)~invalid field makerAssetID"` - TakerAssetID string `json:"takerAssetID" valid:"required~required field takerAssetID missing, matches(^(COI|AI)\|((?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4}|[A-Za-z0-9]{32}))$)~invalid field takerAssetID"` - MakerSplit string `json:"makerSplit" valid:"required~required field makerSplit missing, matches(^[0-9.]+$)~invalid field makerSplit"` - TakerSplit string `json:"takerSplit" valid:"required~required field takerSplit missing, matches(^[0-9.]+$)~invalid field takerSplit"` - ExpiryHeight int64 `json:"expiryHeight" valid:"required~required field expiryHeight missing, matches(^[0-9]+$)~invalid field expiryHeight"` + FromID string `json:"fromID"` + MakerAssetID string `json:"makerAssetID"` + TakerAssetID string `json:"takerAssetID"` + MakerSplit string `json:"makerSplit"` + TakerSplit string `json:"takerSplit"` + ExpiryHeight int64 `json:"expiryHeight"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -44,8 +42,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /orders/make [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( @@ -92,12 +95,12 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { makerSplit, ok := sdkTypes.NewIntFromString(transactionRequest.MakerSplit) if !ok { - return nil, errorConstants.IncorrectFormat.Wrapf("maker split %s is not a valid integer", transactionRequest.MakerSplit) + return nil, constants.IncorrectFormat.Wrapf("maker split %s is not a valid integer", transactionRequest.MakerSplit) } takerSplit, ok := sdkTypes.NewIntFromString(transactionRequest.TakerSplit) if !ok { - return nil, errorConstants.IncorrectFormat.Wrapf("taker split %s is not a valid integer", transactionRequest.TakerSplit) + return nil, constants.IncorrectFormat.Wrapf("taker split %s is not a valid integer", transactionRequest.TakerSplit) } return NewMessage( diff --git a/x/orders/transactions/revoke/transaction_request.go b/x/orders/transactions/revoke/transaction_request.go index 4d2485116..f9b09cce6 100644 --- a/x/orders/transactions/revoke/transaction_request.go +++ b/x/orders/transactions/revoke/transaction_request.go @@ -9,7 +9,6 @@ import ( codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,9 +20,9 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - ToID string `json:"toID" valid:"required~required field toID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field toID"` - ClassificationID string `json:"classificationID" valid:"required~required field classificationID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field classificationID"` + FromID string `json:"fromID"` + ToID string `json:"toID"` + ClassificationID string `json:"classificationID"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -39,8 +38,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /orders/revoke [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( diff --git a/x/orders/transactions/take/message.go b/x/orders/transactions/take/message.go index f53e53c5b..e5cb5ee13 100644 --- a/x/orders/transactions/take/message.go +++ b/x/orders/transactions/take/message.go @@ -4,8 +4,8 @@ package take import ( + "github.com/AssetMantle/modules/helpers/constants" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/cosmos/cosmos-sdk/codec" diff --git a/x/orders/transactions/take/transaction_keeper.go b/x/orders/transactions/take/transaction_keeper.go index 19408eb19..25843af97 100644 --- a/x/orders/transactions/take/transaction_keeper.go +++ b/x/orders/transactions/take/transaction_keeper.go @@ -5,11 +5,11 @@ package take import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" "github.com/AssetMantle/schema/go/properties" diff --git a/x/orders/transactions/take/transaction_request.go b/x/orders/transactions/take/transaction_request.go index 8ca717bfb..66d2b99e8 100644 --- a/x/orders/transactions/take/transaction_request.go +++ b/x/orders/transactions/take/transaction_request.go @@ -5,16 +5,14 @@ package take import ( "encoding/json" + "github.com/cosmos/cosmos-sdk/types/rest" codecUtilities "github.com/AssetMantle/schema/go/codec/utilities" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/rest" "github.com/AssetMantle/modules/helpers" "github.com/AssetMantle/modules/helpers/constants" @@ -22,9 +20,9 @@ import ( type transactionRequest struct { BaseReq rest.BaseReq `json:"baseReq"` - FromID string `json:"fromID" valid:"required~required field fromID missing, matches(^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)~invalid field fromID"` - TakerSplit string `json:"takerSplit" valid:"required~required field takerSplit missing, matches(^[0-9.]+$)"` - OrderID string `json:"orderID" valid:"required~required field orderID missing, matches(^[A-Za-z0-9-_=.|*]+$)~invalid field orderID"` + FromID string `json:"fromID"` + TakerSplit string `json:"takerSplit"` + OrderID string `json:"orderID"` } var _ helpers.TransactionRequest = (*transactionRequest)(nil) @@ -40,8 +38,13 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil) // @Failure default {object} transactionResponse "Message for an unexpected error response." // @Router /orders/take [post] func (transactionRequest transactionRequest) Validate() error { - _, err := govalidator.ValidateStruct(transactionRequest) - return err + if msg, err := transactionRequest.MakeMsg(); err != nil { + return err + } else if err := msg.(helpers.Message).ValidateBasic(); err != nil { + return err + } + + return nil } func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, context client.Context) (helpers.TransactionRequest, error) { return newTransactionRequest( @@ -69,7 +72,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { takerSplit, ok := sdkTypes.NewIntFromString(transactionRequest.TakerSplit) if !ok { - return nil, errorConstants.IncorrectFormat.Wrapf("taker split %s is not a valid integer", transactionRequest.TakerSplit) + return nil, constants.IncorrectFormat.Wrapf("taker split %s is not a valid integer", transactionRequest.TakerSplit) } fromID, err := baseIDs.PrototypeIdentityID().FromString(transactionRequest.FromID) diff --git a/x/splits/auxiliaries/burn/auxiliary_keeper.go b/x/splits/auxiliaries/burn/auxiliary_keeper.go index eaf0af018..a9f28f70b 100644 --- a/x/splits/auxiliaries/burn/auxiliary_keeper.go +++ b/x/splits/auxiliaries/burn/auxiliary_keeper.go @@ -5,10 +5,8 @@ package burn import ( "context" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" - "reflect" - "github.com/AssetMantle/modules/helpers" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/x/splits/utilities" ) @@ -18,16 +16,16 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - if err := request.Validate(); err != nil { - return nil, err +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) } - auxiliaryRequest, ok := request.(auxiliaryRequest) - if !ok { - return nil, errorConstants.InvalidRequest.Wrapf("invalid request type: %s", reflect.TypeOf(request).String()) + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err } - + if _, err := utilities.SubtractSplits(auxiliaryKeeper.mapper.NewCollection(context), auxiliaryRequest.OwnerID, auxiliaryRequest.AssetID, auxiliaryRequest.Value); err != nil { return nil, err } diff --git a/x/splits/auxiliaries/burn/auxiliary_keeper_test.go b/x/splits/auxiliaries/burn/auxiliary_keeper_test.go index 0cec8a2d4..422503fc3 100644 --- a/x/splits/auxiliaries/burn/auxiliary_keeper_test.go +++ b/x/splits/auxiliaries/burn/auxiliary_keeper_test.go @@ -5,6 +5,7 @@ package burn import ( "github.com/AssetMantle/modules/helpers" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/utilities/random" "github.com/AssetMantle/modules/x/splits/constants" "github.com/AssetMantle/modules/x/splits/key" @@ -14,8 +15,6 @@ import ( baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents" baseDocuments "github.com/AssetMantle/schema/go/documents/base" - "github.com/AssetMantle/schema/go/errors" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/types" baseTypes "github.com/AssetMantle/schema/go/types/base" @@ -81,7 +80,7 @@ func Test_auxiliaryKeeper_Help(t *testing.T) { setup func() request helpers.AuxiliaryRequest want helpers.AuxiliaryResponse - wantErr errors.Error + wantErr helpers.Error }{ { "valid request", diff --git a/x/splits/auxiliaries/burn/auxiliary_request.go b/x/splits/auxiliaries/burn/auxiliary_request.go index e96839ab4..92487e7c8 100644 --- a/x/splits/auxiliaries/burn/auxiliary_request.go +++ b/x/splits/auxiliaries/burn/auxiliary_request.go @@ -4,7 +4,7 @@ package burn import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,11 +21,11 @@ var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { if err := auxiliaryRequest.OwnerID.ValidateBasic(); err != nil { - return errorConstants.InvalidRequest.Wrapf("invalid owner ID: %s", err) + return errorConstants.InvalidRequest.Wrapf("invalid owner id: %s", err) } if err := auxiliaryRequest.AssetID.ValidateBasic(); err != nil { - return errorConstants.InvalidRequest.Wrapf("invalid asset ID: %s", err) + return errorConstants.InvalidRequest.Wrapf("invalid asset id: %s", err) } if auxiliaryRequest.Value.LTE(sdkTypes.ZeroInt()) { diff --git a/x/splits/auxiliaries/mint/auxiliary_keeper.go b/x/splits/auxiliaries/mint/auxiliary_keeper.go index 143eec497..1ba8e6115 100644 --- a/x/splits/auxiliaries/mint/auxiliary_keeper.go +++ b/x/splits/auxiliaries/mint/auxiliary_keeper.go @@ -5,10 +5,8 @@ package mint import ( "context" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" - "reflect" - "github.com/AssetMantle/modules/helpers" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/x/splits/utilities" ) @@ -19,13 +17,13 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - if err := AuxiliaryRequest.Validate(); err != nil { - return nil, err - } - auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) if !ok { - return nil, errorConstants.InvalidRequest.Wrapf("invalid request type: %s", reflect.TypeOf(AuxiliaryRequest).String()) + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err } if _, err := utilities.AddSplits(auxiliaryKeeper.mapper.NewCollection(context), auxiliaryRequest.OwnerID, auxiliaryRequest.AssetID, auxiliaryRequest.Value); err != nil { diff --git a/x/splits/auxiliaries/mint/auxiliary_keeper_test.go b/x/splits/auxiliaries/mint/auxiliary_keeper_test.go index b046814a0..513846003 100644 --- a/x/splits/auxiliaries/mint/auxiliary_keeper_test.go +++ b/x/splits/auxiliaries/mint/auxiliary_keeper_test.go @@ -5,6 +5,7 @@ package mint import ( "github.com/AssetMantle/modules/helpers" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/utilities/random" "github.com/AssetMantle/modules/x/splits/constants" "github.com/AssetMantle/modules/x/splits/key" @@ -14,8 +15,6 @@ import ( baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents" "github.com/AssetMantle/schema/go/documents/base" - "github.com/AssetMantle/schema/go/errors" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/types" baseTypes "github.com/AssetMantle/schema/go/types/base" @@ -74,7 +73,7 @@ func Test_auxiliaryKeeper_Help(t *testing.T) { setup func() request helpers.AuxiliaryRequest want helpers.AuxiliaryResponse - wantErr errors.Error + wantErr helpers.Error }{ { "valid request", diff --git a/x/splits/auxiliaries/mint/auxiliary_request.go b/x/splits/auxiliaries/mint/auxiliary_request.go index 51c765497..951e68a8e 100644 --- a/x/splits/auxiliaries/mint/auxiliary_request.go +++ b/x/splits/auxiliaries/mint/auxiliary_request.go @@ -4,7 +4,7 @@ package mint import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -21,11 +21,11 @@ var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { if err := auxiliaryRequest.OwnerID.ValidateBasic(); err != nil { - return errorConstants.InvalidRequest.Wrapf("invalid owner ID: %s", err) + return errorConstants.InvalidRequest.Wrapf("invalid owner id: %s", err) } if err := auxiliaryRequest.AssetID.ValidateBasic(); err != nil { - return errorConstants.InvalidRequest.Wrapf("invalid asset ID: %s", err) + return errorConstants.InvalidRequest.Wrapf("invalid asset id: %s", err) } if auxiliaryRequest.Value.LTE(sdkTypes.ZeroInt()) { diff --git a/x/splits/auxiliaries/purge/auxiliary_keeper.go b/x/splits/auxiliaries/purge/auxiliary_keeper.go index 3f4485977..cc49b7f36 100644 --- a/x/splits/auxiliaries/purge/auxiliary_keeper.go +++ b/x/splits/auxiliaries/purge/auxiliary_keeper.go @@ -5,8 +5,7 @@ package purge import ( "context" - - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/modules/helpers" @@ -22,8 +21,16 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } + splits := auxiliaryKeeper.mapper.NewCollection(context) circulatingSupply := utilities.GetTotalSupply(splits, auxiliaryRequest.AssetID) diff --git a/x/splits/auxiliaries/purge/auxiliary_request.go b/x/splits/auxiliaries/purge/auxiliary_request.go index e2de14786..c21887bc0 100644 --- a/x/splits/auxiliaries/purge/auxiliary_request.go +++ b/x/splits/auxiliaries/purge/auxiliary_request.go @@ -4,8 +4,8 @@ package purge import ( + "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" - "github.com/asaskevich/govalidator" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -20,17 +20,19 @@ type auxiliaryRequest struct { var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} + if err := auxiliaryRequest.OwnerID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("owner id is invalid: %s", err.Error()) + } -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + if err := auxiliaryRequest.AssetID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("asset id is invalid: %s", err.Error()) } + + if auxiliaryRequest.Supply.IsNegative() { + return constants.InvalidRequest.Wrapf("supply cannot be negative") + } + + return nil } func NewAuxiliaryRequest(ownerID ids.IdentityID, assetID ids.AssetID, supply sdkTypes.Int) helpers.AuxiliaryRequest { diff --git a/x/splits/auxiliaries/purge/auxiliary_request_test.go b/x/splits/auxiliaries/purge/auxiliary_request_test.go index 4437fc378..081caef94 100644 --- a/x/splits/auxiliaries/purge/auxiliary_request_test.go +++ b/x/splits/auxiliaries/purge/auxiliary_request_test.go @@ -54,27 +54,6 @@ func TestNewAuxiliaryRequest(t *testing.T) { } } -func Test_auxiliaryRequestFromInterface(t *testing.T) { - testOwnerID, testAssetID, testValue := createTestInput1() - type args struct { - request helpers.AuxiliaryRequest - } - tests := []struct { - name string - args args - want auxiliaryRequest - }{ - {"+ve", args{NewAuxiliaryRequest(testOwnerID, testAssetID, testValue)}, auxiliaryRequest{testOwnerID, testAssetID, testValue}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { - t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) - } - }) - } -} - func Test_auxiliaryRequest_Validate(t *testing.T) { testOwnerID, testAssetID, testValue := createTestInput1() type fields struct { diff --git a/x/splits/auxiliaries/renumerate/auxiliary_keeper.go b/x/splits/auxiliaries/renumerate/auxiliary_keeper.go index a9f199691..b35edf581 100644 --- a/x/splits/auxiliaries/renumerate/auxiliary_keeper.go +++ b/x/splits/auxiliaries/renumerate/auxiliary_keeper.go @@ -5,10 +5,9 @@ package renumerate import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" sdkTypes "github.com/cosmos/cosmos-sdk/types" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" - "github.com/AssetMantle/modules/helpers" "github.com/AssetMantle/modules/x/splits/utilities" ) @@ -19,8 +18,16 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) -func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - auxiliaryRequest := auxiliaryRequestFromInterface(request) +func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) + if !ok { + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err + } + if auxiliaryRequest.Supply.LTE(sdkTypes.ZeroInt()) { return nil, errorConstants.IncorrectFormat.Wrapf("value is less than or equal to 0 for asset: %s", auxiliaryRequest.AssetID.AsString()) } diff --git a/x/splits/auxiliaries/renumerate/auxiliary_request.go b/x/splits/auxiliaries/renumerate/auxiliary_request.go index 5a9afc893..2d7dd14de 100644 --- a/x/splits/auxiliaries/renumerate/auxiliary_request.go +++ b/x/splits/auxiliaries/renumerate/auxiliary_request.go @@ -4,11 +4,10 @@ package renumerate import ( + "github.com/AssetMantle/modules/helpers" + "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" - "github.com/asaskevich/govalidator" sdkTypes "github.com/cosmos/cosmos-sdk/types" - - "github.com/AssetMantle/modules/helpers" ) type auxiliaryRequest struct { @@ -20,17 +19,19 @@ type auxiliaryRequest struct { var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { - _, err := govalidator.ValidateStruct(auxiliaryRequest) - return err -} + if err := auxiliaryRequest.OwnerID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("owner id is invalid: %s", err.Error()) + } + + if err := auxiliaryRequest.AssetID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf("asset id is invalid: %s", err.Error()) + } -func auxiliaryRequestFromInterface(request helpers.AuxiliaryRequest) auxiliaryRequest { - switch value := request.(type) { - case auxiliaryRequest: - return value - default: - return auxiliaryRequest{} + if auxiliaryRequest.Supply.IsNegative() { + return constants.InvalidRequest.Wrapf("supply cannot be negative") } + + return nil } func NewAuxiliaryRequest(ownerID ids.IdentityID, assetID ids.AssetID, supply sdkTypes.Int) helpers.AuxiliaryRequest { diff --git a/x/splits/auxiliaries/renumerate/auxiliary_request_test.go b/x/splits/auxiliaries/renumerate/auxiliary_request_test.go index 610d4d69b..b4749c4c0 100644 --- a/x/splits/auxiliaries/renumerate/auxiliary_request_test.go +++ b/x/splits/auxiliaries/renumerate/auxiliary_request_test.go @@ -53,27 +53,6 @@ func TestNewAuxiliaryRequest(t *testing.T) { } } -func Test_auxiliaryRequestFromInterface(t *testing.T) { - testOwnerID, testAssetID, testValue := createTestInput1() - type args struct { - request helpers.AuxiliaryRequest - } - tests := []struct { - name string - args args - want auxiliaryRequest - }{ - {"+ve", args{NewAuxiliaryRequest(testOwnerID, testAssetID, testValue)}, auxiliaryRequest{testOwnerID, testAssetID, testValue}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { - t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) - } - }) - } -} - func Test_auxiliaryRequest_Validate(t *testing.T) { testOwnerID, testAssetID, testValue := createTestInput1() type fields struct { diff --git a/x/splits/auxiliaries/transfer/auxiliary_keeper.go b/x/splits/auxiliaries/transfer/auxiliary_keeper.go index d7b7b9b4c..0e3ab920b 100644 --- a/x/splits/auxiliaries/transfer/auxiliary_keeper.go +++ b/x/splits/auxiliaries/transfer/auxiliary_keeper.go @@ -5,10 +5,8 @@ package transfer import ( "context" - "reflect" - + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/data" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" propertyConstants "github.com/AssetMantle/schema/go/properties/constants" "github.com/AssetMantle/modules/helpers" @@ -23,13 +21,13 @@ type auxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil) func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - if err := AuxiliaryRequest.Validate(); err != nil { - return nil, err - } - auxiliaryRequest, ok := AuxiliaryRequest.(auxiliaryRequest) if !ok { - return nil, errorConstants.InvalidRequest.Wrapf("invalid request type: %s", reflect.TypeOf(AuxiliaryRequest).String()) + return nil, errorConstants.InvalidRequest.Wrapf("invalid request type %T", AuxiliaryRequest) + } + + if err := auxiliaryRequest.Validate(); err != nil { + return nil, err } if !auxiliaryKeeper.parameterManager.Fetch(context).GetParameter(propertyConstants.TransferEnabledProperty.GetID()).GetMetaProperty().GetData().Get().(data.BooleanData).Get() { diff --git a/x/splits/auxiliaries/transfer/auxiliary_keeper_test.go b/x/splits/auxiliaries/transfer/auxiliary_keeper_test.go index 2cde586ad..c97173d6d 100644 --- a/x/splits/auxiliaries/transfer/auxiliary_keeper_test.go +++ b/x/splits/auxiliaries/transfer/auxiliary_keeper_test.go @@ -6,6 +6,7 @@ package transfer import ( "context" "github.com/AssetMantle/modules/helpers" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/utilities/random" "github.com/AssetMantle/modules/x/splits/constants" "github.com/AssetMantle/modules/x/splits/key" @@ -17,8 +18,6 @@ import ( baseData "github.com/AssetMantle/schema/go/data/base" "github.com/AssetMantle/schema/go/documents" "github.com/AssetMantle/schema/go/documents/base" - "github.com/AssetMantle/schema/go/errors" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseIDs "github.com/AssetMantle/schema/go/ids/base" baseLists "github.com/AssetMantle/schema/go/lists/base" baseParameters "github.com/AssetMantle/schema/go/parameters/base" @@ -135,7 +134,7 @@ func Test_auxiliaryKeeper_Help(t *testing.T) { setup func() request helpers.AuxiliaryRequest want helpers.AuxiliaryResponse - wantErr errors.Error + wantErr helpers.Error }{ { "valid request", diff --git a/x/splits/auxiliaries/transfer/auxiliary_request.go b/x/splits/auxiliaries/transfer/auxiliary_request.go index c845eb4b1..26dea76bc 100644 --- a/x/splits/auxiliaries/transfer/auxiliary_request.go +++ b/x/splits/auxiliaries/transfer/auxiliary_request.go @@ -4,7 +4,7 @@ package transfer import ( - "github.com/AssetMantle/schema/go/errors/constants" + "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -22,15 +22,15 @@ var _ helpers.AuxiliaryRequest = (*auxiliaryRequest)(nil) func (auxiliaryRequest auxiliaryRequest) Validate() error { if err := auxiliaryRequest.FromID.ValidateBasic(); err != nil { - return constants.InvalidRequest.Wrapf("invalid from ID: %s", err) + return constants.InvalidRequest.Wrapf("invalid from id: %s", err) } if err := auxiliaryRequest.ToID.ValidateBasic(); err != nil { - return constants.InvalidRequest.Wrapf("invalid to ID: %s", err) + return constants.InvalidRequest.Wrapf("invalid to id: %s", err) } if err := auxiliaryRequest.AssetID.ValidateBasic(); err != nil { - return constants.InvalidRequest.Wrapf("invalid asset ID: %s", err) + return constants.InvalidRequest.Wrapf("invalid asset id: %s", err) } if auxiliaryRequest.Value.LTE(sdkTypes.ZeroInt()) { diff --git a/x/splits/genesis/genesis.go b/x/splits/genesis/genesis.go index f56c96aa5..ef52a0e8f 100644 --- a/x/splits/genesis/genesis.go +++ b/x/splits/genesis/genesis.go @@ -2,8 +2,8 @@ package genesis import ( "context" + errorConstants "github.com/AssetMantle/modules/helpers/constants" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" "github.com/AssetMantle/schema/go/lists" "github.com/AssetMantle/schema/go/lists/base" sdkCodec "github.com/cosmos/cosmos-sdk/codec" @@ -34,11 +34,11 @@ func (genesis *Genesis) ValidateBasic(parameterManager helpers.ParameterManager) } if !isPresent { - return errorConstants.IncorrectFormat.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) + return errorConstants.EntityNotFound.Wrapf("expected parameter %s not found", parameter.GetMetaProperty().GetKey().AsString()) } if err := parameterManager.ValidateParameter(parameter); err != nil { - return err + return errorConstants.InvalidParameter.Wrapf("parameter %s: %s", parameter.GetMetaProperty().GetKey().AsString(), err.Error()) } } diff --git a/x/splits/key/key.go b/x/splits/key/key.go index b14301023..2a6c9a4fa 100644 --- a/x/splits/key/key.go +++ b/x/splits/key/key.go @@ -4,7 +4,7 @@ package key import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" @@ -13,6 +13,14 @@ import ( var _ helpers.Key = (*Key)(nil) +func (key *Key) ValidateBasic() error { + if key.SplitID != nil { + if err := key.SplitID.ValidateBasic(); err != nil { + return errorConstants.InvalidKey.Wrapf(err.Error()) + } + } + return nil +} func (key *Key) GenerateStorePrefixBytes() []byte { return key.SplitID.GetAssetID().Bytes() } diff --git a/x/splits/parameters/transfer_enabled/parameter.go b/x/splits/parameters/transfer_enabled/parameter.go index 06dc7ff52..1a9076101 100644 --- a/x/splits/parameters/transfer_enabled/parameter.go +++ b/x/splits/parameters/transfer_enabled/parameter.go @@ -4,8 +4,8 @@ package transfer_enabled import ( + errorConstants "github.com/AssetMantle/modules/helpers/constants" baseData "github.com/AssetMantle/schema/go/data/base" - errorConstants "github.com/AssetMantle/schema/go/errors/constants" baseParameters "github.com/AssetMantle/schema/go/parameters/base" "github.com/AssetMantle/schema/go/properties/base" constantProperties "github.com/AssetMantle/schema/go/properties/constants" diff --git a/x/splits/queries/balances/query_keeper.go b/x/splits/queries/balances/query_keeper.go index d1bfe550f..9fffa3698 100644 --- a/x/splits/queries/balances/query_keeper.go +++ b/x/splits/queries/balances/query_keeper.go @@ -21,6 +21,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(utilities.GetAllBalancesForIdentity(queryKeeper.mapper.NewCollection(context), queryRequest.IdentityID)), nil } diff --git a/x/splits/queries/balances/query_request.go b/x/splits/queries/balances/query_request.go index eba991f3a..bb6148ab2 100644 --- a/x/splits/queries/balances/query_request.go +++ b/x/splits/queries/balances/query_request.go @@ -8,7 +8,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/AssetMantle/modules/helpers" @@ -29,8 +28,25 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryRequest "Message for an unexpected error response." // @Router /balances/{identityID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + if queryRequest.Limit > constants.PaginationLimit { + return constants.InvalidRequest.Wrapf("limit cannot be greater than %d", constants.PaginationLimit) + } + + if queryRequest.Limit < 0 { + return constants.InvalidRequest.Wrapf("limit cannot be less than 0") + } + + if queryRequest.IdentityID != nil { + if err := queryRequest.IdentityID.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { diff --git a/x/splits/queries/split/query_keeper.go b/x/splits/queries/split/query_keeper.go index 8e8040b81..2d430163a 100644 --- a/x/splits/queries/split/query_keeper.go +++ b/x/splits/queries/split/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchRecord(queryRequest.Key)), nil } diff --git a/x/splits/queries/split/query_request.go b/x/splits/queries/split/query_request.go index f6ee33d08..d229632fd 100644 --- a/x/splits/queries/split/query_request.go +++ b/x/splits/queries/split/query_request.go @@ -8,7 +8,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/AssetMantle/modules/helpers" @@ -30,8 +29,11 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error response." // @Router /splits/splits/{splitID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { diff --git a/x/splits/queries/splits/query_keeper.go b/x/splits/queries/splits/query_keeper.go index 9d1f0e9e7..51a3b3f03 100644 --- a/x/splits/queries/splits/query_keeper.go +++ b/x/splits/queries/splits/query_keeper.go @@ -20,6 +20,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(queryKeeper.mapper.NewCollection(context).FetchPaginated(queryRequest.Key, queryRequest.Limit)), nil } diff --git a/x/splits/queries/splits/query_request.go b/x/splits/queries/splits/query_request.go index 351e119a7..f7e14afd0 100644 --- a/x/splits/queries/splits/query_request.go +++ b/x/splits/queries/splits/query_request.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/types/query" @@ -32,8 +31,19 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryResponse "Message for an unexpected error response." // @Router /splits/splits/{splitID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.Key.ValidateBasic(); err != nil { + return constants.InvalidRequest.Wrapf(err.Error()) + } + + if queryRequest.Limit > constants.PaginationLimit { + return constants.InvalidRequest.Wrapf("limit cannot be greater than %d", constants.PaginationLimit) + } + + if queryRequest.Limit < 0 { + return constants.InvalidRequest.Wrapf("limit cannot be less than 0") + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { diff --git a/x/splits/queries/supply/query_keeper.go b/x/splits/queries/supply/query_keeper.go index 9f43bd720..efc254803 100644 --- a/x/splits/queries/supply/query_keeper.go +++ b/x/splits/queries/supply/query_keeper.go @@ -21,6 +21,9 @@ func (queryKeeper queryKeeper) Enquire(context context.Context, queryRequest hel return queryResponse, err } func (queryKeeper queryKeeper) Handle(context context.Context, queryRequest *QueryRequest) (*QueryResponse, error) { + if err := queryRequest.Validate(); err != nil { + return nil, err + } return newQueryResponse(utilities.GetTotalSupply(queryKeeper.mapper.NewCollection(context), queryRequest.AssetID)), nil } diff --git a/x/splits/queries/supply/query_request.go b/x/splits/queries/supply/query_request.go index 94f6835f7..423b5cd4e 100644 --- a/x/splits/queries/supply/query_request.go +++ b/x/splits/queries/supply/query_request.go @@ -4,16 +4,13 @@ package supply import ( - "net/http" - - "github.com/AssetMantle/schema/go/ids" - baseIDs "github.com/AssetMantle/schema/go/ids/base" - "github.com/asaskevich/govalidator" - "github.com/cosmos/cosmos-sdk/client" - "github.com/AssetMantle/modules/helpers" "github.com/AssetMantle/modules/helpers/base" "github.com/AssetMantle/modules/helpers/constants" + "github.com/AssetMantle/schema/go/ids" + baseIDs "github.com/AssetMantle/schema/go/ids/base" + "github.com/cosmos/cosmos-sdk/client" + "net/http" ) var _ helpers.QueryRequest = (*QueryRequest)(nil) @@ -29,8 +26,11 @@ var _ helpers.QueryRequest = (*QueryRequest)(nil) // @Failure default {object} queryRequest "Message for an unexpected error response." // @Router /balances/{identityID} [get] func (queryRequest *QueryRequest) Validate() error { - _, err := govalidator.ValidateStruct(queryRequest) - return err + if err := queryRequest.AssetID.ValidateBasic(); err != nil { + return err + } + + return nil } func (*QueryRequest) FromCLI(cliCommand helpers.CLICommand, _ client.Context) (helpers.QueryRequest, error) { diff --git a/x/splits/utilities/split.go b/x/splits/utilities/split.go index 328dfb228..0a0154bb2 100644 --- a/x/splits/utilities/split.go +++ b/x/splits/utilities/split.go @@ -4,7 +4,7 @@ package utilities import ( - errorConstants "github.com/AssetMantle/schema/go/errors/constants" + errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/schema/go/ids" baseIDs "github.com/AssetMantle/schema/go/ids/base" "github.com/AssetMantle/schema/go/types/base"