diff --git a/x/interchainqueries/types/errors.go b/x/interchainqueries/types/errors.go index 30a5048c1..edab0926e 100644 --- a/x/interchainqueries/types/errors.go +++ b/x/interchainqueries/types/errors.go @@ -6,26 +6,26 @@ import ( // x/interchainqueries module sentinel errors var ( - ErrInvalidQueryID = sdkerrors.Register(ModuleName, 1100, "invalid query id") - ErrEmptyResult = sdkerrors.Register(ModuleName, 1101, "empty result") - ErrInvalidClientID = sdkerrors.Register(ModuleName, 1102, "invalid client id") - ErrInvalidUpdatePeriod = sdkerrors.Register(ModuleName, 1103, "invalid update period") - ErrInvalidConnectionID = sdkerrors.Register(ModuleName, 1104, "invalid connection id") - ErrInvalidQueryType = sdkerrors.Register(ModuleName, 1105, "invalid query type") - ErrInvalidTransactionsFilter = sdkerrors.Register(ModuleName, 1106, "invalid transactions filter") - ErrInvalidSubmittedResult = sdkerrors.Register(ModuleName, 1107, "invalid result") - ErrProtoMarshal = sdkerrors.Register(ModuleName, 1108, "failed to marshal protobuf bytes") - ErrProtoUnmarshal = sdkerrors.Register(ModuleName, 1109, "failed to unmarshal protobuf bytes") - ErrInvalidType = sdkerrors.Register(ModuleName, 1110, "invalid type") - ErrInternal = sdkerrors.Register(ModuleName, 1111, "internal error") - ErrInvalidProof = sdkerrors.Register(ModuleName, 1112, "merkle proof is invalid") - ErrInvalidHeader = sdkerrors.Register(ModuleName, 1113, "header is invalid") - ErrInvalidHeight = sdkerrors.Register(ModuleName, 1114, "height is invalid") - ErrNoQueryResult = sdkerrors.Register(ModuleName, 1115, "no query result") - ErrNotContract = sdkerrors.Register(ModuleName, 1116, "not a contract") - ErrEmptyKeys = sdkerrors.Register(ModuleName, 1117, "keys are empty") - ErrEmptyKeyPath = sdkerrors.Register(ModuleName, 1118, "key path is empty") - ErrEmptyKeyID = sdkerrors.Register(ModuleName, 1119, "key id is empty") - ErrTooManyKVQueryKeys = sdkerrors.Register(ModuleName, 1120, "too many keys") - ErrEmptyQueryTypeGenesis = sdkerrors.Register(ModuleName, 1121, "empty query type") + ErrInvalidQueryID = sdkerrors.Register(ModuleName, 1100, "invalid query id") + ErrEmptyResult = sdkerrors.Register(ModuleName, 1101, "empty result") + ErrInvalidClientID = sdkerrors.Register(ModuleName, 1102, "invalid client id") + ErrInvalidUpdatePeriod = sdkerrors.Register(ModuleName, 1103, "invalid update period") + ErrInvalidConnectionID = sdkerrors.Register(ModuleName, 1104, "invalid connection id") + ErrInvalidQueryType = sdkerrors.Register(ModuleName, 1105, "invalid query type") + ErrInvalidTransactionsFilter = sdkerrors.Register(ModuleName, 1106, "invalid transactions filter") + ErrInvalidSubmittedResult = sdkerrors.Register(ModuleName, 1107, "invalid result") + ErrProtoMarshal = sdkerrors.Register(ModuleName, 1108, "failed to marshal protobuf bytes") + ErrProtoUnmarshal = sdkerrors.Register(ModuleName, 1109, "failed to unmarshal protobuf bytes") + ErrInvalidType = sdkerrors.Register(ModuleName, 1110, "invalid type") + ErrInternal = sdkerrors.Register(ModuleName, 1111, "internal error") + ErrInvalidProof = sdkerrors.Register(ModuleName, 1112, "merkle proof is invalid") + ErrInvalidHeader = sdkerrors.Register(ModuleName, 1113, "header is invalid") + ErrInvalidHeight = sdkerrors.Register(ModuleName, 1114, "height is invalid") + ErrNoQueryResult = sdkerrors.Register(ModuleName, 1115, "no query result") + ErrNotContract = sdkerrors.Register(ModuleName, 1116, "not a contract") + ErrEmptyKeys = sdkerrors.Register(ModuleName, 1117, "keys are empty") + ErrEmptyKeyPath = sdkerrors.Register(ModuleName, 1118, "key path is empty") + ErrEmptyKeyID = sdkerrors.Register(ModuleName, 1119, "key id is empty") + ErrTooManyKVQueryKeys = sdkerrors.Register(ModuleName, 1120, "too many keys") + ErrUnexpectedQueryTypeGenesis = sdkerrors.Register(ModuleName, 1121, "empty query type") ) diff --git a/x/interchainqueries/types/genesis.go b/x/interchainqueries/types/genesis.go index 9ec099a69..4769bb957 100644 --- a/x/interchainqueries/types/genesis.go +++ b/x/interchainqueries/types/genesis.go @@ -32,22 +32,20 @@ func (gs GenesisState) Validate() error { return sdkerrors.Wrapf(err, "Invalid owner address (%s)", err) } - if val.QueryType == "" { - return sdkerrors.Wrapf(ErrEmptyQueryTypeGenesis, "Query type is empty, id: %d", val.Id) - } - - if val.QueryType == "tx" { + switch val.QueryType { + case "tx": if err := ValidateTransactionsFilter(val.TransactionsFilter); err != nil { return sdkerrors.Wrap(ErrInvalidTransactionsFilter, err.Error()) } - } - if val.QueryType == "kv" { + case "kv": if len(val.Keys) == 0 { return sdkerrors.Wrap(ErrEmptyKeys, "keys cannot be empty") } if err := validateKeys(val.GetKeys()); err != nil { return err } + default: + return sdkerrors.Wrapf(ErrUnexpectedQueryTypeGenesis, "Unexpected query type: %s", val.QueryType) } } return nil