Example #1
0
        private (ErrorType?ErrorType, string ErrorMessage) Validate(JsonRpcRequest rpcRequest)
        {
            if (rpcRequest == null)
            {
                return(ErrorType.InvalidRequest, "Invalid request");
            }

            var methodName = rpcRequest.Method;

            if (string.IsNullOrWhiteSpace(methodName))
            {
                return(ErrorType.InvalidRequest, "Method is required");
            }

            methodName = methodName.Trim().ToLower();

            var module = _rpcModuleProvider.GetAllModules().FirstOrDefault(x => x.MethodDictionary.ContainsKey(methodName));

            if (module == null)
            {
                return(ErrorType.MethodNotFound, $"Method {methodName} is not supported");
            }

            if (_rpcModuleProvider.GetEnabledModules().All(x => x.ModuleType != module.ModuleType))
            {
                return(ErrorType.InvalidRequest, $"{module.ModuleType} module is disabled");
            }

            return(null, null);
        }