From b94be97b67dc5a0d750f3f788b1f098a469f39d2 Mon Sep 17 00:00:00 2001 From: Shubham Sonthalia Date: Sat, 23 Nov 2024 21:04:27 +0530 Subject: [PATCH 1/5] first changes --- .../JsonRpcUrlCollection.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs index b7a60475d2f..4b8b81f5cb5 100644 --- a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs +++ b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs @@ -89,6 +89,7 @@ private void BuildEngineUrls(bool includeWebSockets) private void BuildAdditionalUrls(bool includeWebSockets) { + List additionalRpcUrlRows = new List(); foreach (string additionalRpcUrl in _jsonRpcConfig.AdditionalRpcUrls) { try @@ -118,6 +119,8 @@ private void BuildAdditionalUrls(bool includeWebSockets) else { Add(url.Port, url); + string[] row = [url.Host + ":" + url.Port.ToString(), url.RpcEndpoint.ToString(), string.Join(", ", url.EnabledModules)]; + additionalRpcUrlRows.Add(row); } } catch (FormatException fe) @@ -125,6 +128,41 @@ private void BuildAdditionalUrls(bool includeWebSockets) if (_logger.IsInfo) _logger.Info($"Additional JSON RPC URL packed value '{additionalRpcUrl}' format error: {fe.Message}; skipping..."); } } + LogTable(additionalRpcUrlRows); + } + private void LogTable(List rows) + { + // Calculate column widths + string[] headers = ["Additional Url", "Protocols", "Modules"]; + var columnWidths = new int[headers.Length]; + + for (int i = 0; i < headers.Length; i++) + { + columnWidths[i] = headers[i].Length; // Start with header length + foreach (var row in rows) + { + if (i < row.Length) + { + columnWidths[i] = Math.Max(columnWidths[i], row[i]?.Length ?? 0); + } + } + } + + // Generate the separator + var separator = string.Join("+", columnWidths.Select(width => new string('-', width + 2))); + + // Print header + _logger.Info(separator); + _logger.Info("| " + string.Join(" | ", headers.Select((h, i) => h.PadRight(columnWidths[i]))) + " |"); + _logger.Info(separator); + + // Print rows + foreach (var row in rows) + { + _logger.Info("| " + string.Join(" | ", row.Select((cell, i) => (cell ?? "").PadRight(columnWidths[i]))) + " |"); + } + + _logger.Info(separator); } } From 0434014ea85b97d248e8e36d4c38e0a26214ae76 Mon Sep 17 00:00:00 2001 From: Shubham Sonthalia Date: Sat, 23 Nov 2024 21:08:52 +0530 Subject: [PATCH 2/5] removing comments --- src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs index 4b8b81f5cb5..7dbe4e110b2 100644 --- a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs +++ b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs @@ -132,13 +132,12 @@ private void BuildAdditionalUrls(bool includeWebSockets) } private void LogTable(List rows) { - // Calculate column widths string[] headers = ["Additional Url", "Protocols", "Modules"]; var columnWidths = new int[headers.Length]; for (int i = 0; i < headers.Length; i++) { - columnWidths[i] = headers[i].Length; // Start with header length + columnWidths[i] = headers[i].Length; foreach (var row in rows) { if (i < row.Length) @@ -148,15 +147,13 @@ private void LogTable(List rows) } } - // Generate the separator var separator = string.Join("+", columnWidths.Select(width => new string('-', width + 2))); - // Print header + _logger.Info(separator); _logger.Info("| " + string.Join(" | ", headers.Select((h, i) => h.PadRight(columnWidths[i]))) + " |"); _logger.Info(separator); - // Print rows foreach (var row in rows) { _logger.Info("| " + string.Join(" | ", row.Select((cell, i) => (cell ?? "").PadRight(columnWidths[i]))) + " |"); From e1fab1479e6f5ea08ad191bbc68fa55cf0566ddf Mon Sep 17 00:00:00 2001 From: Shubham Sonthalia Date: Sat, 23 Nov 2024 21:10:52 +0530 Subject: [PATCH 3/5] string formatting --- src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs index 7dbe4e110b2..6c8a4e18e4d 100644 --- a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs +++ b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs @@ -119,7 +119,12 @@ private void BuildAdditionalUrls(bool includeWebSockets) else { Add(url.Port, url); - string[] row = [url.Host + ":" + url.Port.ToString(), url.RpcEndpoint.ToString(), string.Join(", ", url.EnabledModules)]; + string[] row = new[] + { + $"{url.Host}:{url.Port}", + url.RpcEndpoint.ToString(), + string.Join(", ", url.EnabledModules) + }; additionalRpcUrlRows.Add(row); } } From e1974eed12bfb16cafbb281eaa77a8b9bd1546c1 Mon Sep 17 00:00:00 2001 From: Shubham Sonthalia Date: Thu, 28 Nov 2024 20:39:07 +0530 Subject: [PATCH 4/5] Table adjustment --- src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs index 6c8a4e18e4d..2df3ca7c19f 100644 --- a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs +++ b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs @@ -138,6 +138,7 @@ private void BuildAdditionalUrls(bool includeWebSockets) private void LogTable(List rows) { string[] headers = ["Additional Url", "Protocols", "Modules"]; + string redSeparator = "\u001b[31m|\u001b[0m"; var columnWidths = new int[headers.Length]; for (int i = 0; i < headers.Length; i++) @@ -152,16 +153,16 @@ private void LogTable(List rows) } } - var separator = string.Join("+", columnWidths.Select(width => new string('-', width + 2))); + var separator = "-" + string.Join("-", columnWidths.Select(width => new string('-', width + 2))) + "-"; _logger.Info(separator); - _logger.Info("| " + string.Join(" | ", headers.Select((h, i) => h.PadRight(columnWidths[i]))) + " |"); + _logger.Info(redSeparator + " " + string.Join(" " + redSeparator + " ", headers.Select((h, i) => h.PadRight(columnWidths[i]))) + " " + redSeparator); _logger.Info(separator); foreach (var row in rows) { - _logger.Info("| " + string.Join(" | ", row.Select((cell, i) => (cell ?? "").PadRight(columnWidths[i]))) + " |"); + _logger.Info(redSeparator + " " + string.Join(" " + redSeparator + " ", row.Select((cell, i) => (cell ?? "").PadRight(columnWidths[i]))) + " " + redSeparator); } _logger.Info(separator); From 15442d023c83226ffa56063c31d174051caf4bdf Mon Sep 17 00:00:00 2001 From: Shubham Sonthalia Date: Thu, 5 Dec 2024 23:35:16 +0530 Subject: [PATCH 5/5] adding heading --- src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs index 2df3ca7c19f..591e520c988 100644 --- a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs +++ b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs @@ -137,6 +137,7 @@ private void BuildAdditionalUrls(bool includeWebSockets) } private void LogTable(List rows) { + string[] headers = ["Additional Url", "Protocols", "Modules"]; string redSeparator = "\u001b[31m|\u001b[0m"; var columnWidths = new int[headers.Length]; @@ -155,7 +156,7 @@ private void LogTable(List rows) var separator = "-" + string.Join("-", columnWidths.Select(width => new string('-', width + 2))) + "-"; - + _logger.Info("\u001b[31m*****\u001b[0m Additional RPC URLs \u001b[31m*****\u001b[0m"); _logger.Info(separator); _logger.Info(redSeparator + " " + string.Join(" " + redSeparator + " ", headers.Select((h, i) => h.PadRight(columnWidths[i]))) + " " + redSeparator); _logger.Info(separator);