private JsonRpcResponse ExecuteRequest(JsonRpcRequest rpcRequest) { var methodName = rpcRequest.Method.Trim().ToLower(); var module = _rpcModuleProvider.GetEnabledModules().FirstOrDefault(x => x.MethodDictionary.ContainsKey(methodName)); if (module != null) { return(Execute(rpcRequest, methodName, module.MethodDictionary[methodName], module.ModuleObject)); } return(GetErrorResponse(ErrorType.MethodNotFound, $"Method {rpcRequest.Method} is not supported", rpcRequest.Id, methodName)); }
public JsonRpcService(IRpcModuleProvider rpcModuleProvider, ILogManager logManager) { _logger = logManager.GetClassLogger(); _rpcModuleProvider = rpcModuleProvider; _serializer = new JsonSerializer(); foreach (ModuleInfo module in _rpcModuleProvider.GetEnabledModules()) { foreach (JsonConverter converter in module.Converters) { if (_logger.IsDebug) { _logger.Debug($"Registering {converter.GetType().Name} ({module.ModuleType} module)"); } _serializer.Converters.Add(converter); _converterLookup.Add(converter.GetType().BaseType.GenericTypeArguments[0], converter); Converters.Add(converter); } } foreach (JsonConverter converter in EthereumJsonSerializer.BasicConverters) { if (_logger.IsDebug) { _logger.Debug($"Registering {converter.GetType().Name} (default)"); } _serializer.Converters.Add(converter); _converterLookup.Add(converter.GetType().BaseType.GenericTypeArguments[0], converter); Converters.Add(converter); } }
public JsonRpcService(IRpcModuleProvider rpcModuleProvider, IConfigProvider configurationProvider, ILogManager logManager) { _logger = logManager.GetClassLogger(); _jsonRpcConfig = configurationProvider.GetConfig <IJsonRpcConfig>(); _rpcModuleProvider = rpcModuleProvider; _serializer = new JsonSerializer(); foreach (ModuleInfo module in _rpcModuleProvider.GetEnabledModules()) { foreach (JsonConverter converter in module.Converters) { if (_logger.IsDebug) { _logger.Debug($"Registering {converter.GetType().Name}"); } _serializer.Converters.Add(converter); _converterLookup.Add(converter.GetType().BaseType.GenericTypeArguments[0], converter); } } foreach (JsonConverter converter in GetStandardConverters()) { if (_logger.IsDebug) { _logger.Debug($"Registering {converter.GetType().Name}"); } _serializer.Converters.Add(converter); _converterLookup.Add(converter.GetType().BaseType.GenericTypeArguments[0], converter); } }
public Task Start() { if (_logger.IsDebug) { _logger.Debug("Initializing JSON RPC"); } var hostVariable = Environment.GetEnvironmentVariable("NETHERMIND_URL"); var host = string.IsNullOrWhiteSpace(hostVariable) ? $"http://{_initConfig.HttpHost}:{_initConfig.HttpPort}" : hostVariable; if (_logger.IsInfo) { _logger.Info($"Running server, url: {host}"); } var webHost = WebHost.CreateDefaultBuilder() .ConfigureServices(s => { s.AddSingleton(_configurationProvider); s.AddSingleton(_jsonRpcProcessor); s.AddSingleton(_webSocketsManager); }) .UseStartup <Startup>() .UseUrls(host) .ConfigureLogging(logging => { logging.SetMinimumLevel(LogLevel.Information); logging.ClearProviders(); logging.AddProvider(new CustomMicrosoftLoggerProvider(_logManager)); }) .Build(); var modules = GetModules(_initConfig.JsonRpcEnabledModules)?.ToList(); if (modules != null && modules.Any()) { _jsonRpcConfig.EnabledModules = modules; } _webHost = webHost; _webHost.Start(); if (_logger.IsInfo) { _logger.Info($"JSON RPC : {host}"); } if (_logger.IsInfo) { _logger.Info($"RPC modules : {string.Join(", ", _moduleProvider.GetEnabledModules().Select(m => m.ModuleType.ToString()).OrderBy(x => x))}"); } return(Task.CompletedTask); }