Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7748 first changes #7797

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
42 changes: 42 additions & 0 deletions src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private void BuildEngineUrls(bool includeWebSockets)

private void BuildAdditionalUrls(bool includeWebSockets)
{
List<string[]> additionalRpcUrlRows = new List<string[]>();
foreach (string additionalRpcUrl in _jsonRpcConfig.AdditionalRpcUrls)
{
try
Expand Down Expand Up @@ -119,13 +120,54 @@ private void BuildAdditionalUrls(bool includeWebSockets)
else
{
Add(url.Port, url);
string[] row = new[]
{
$"{url.Host}:{url.Port}",
url.RpcEndpoint.ToString(),
string.Join(", ", url.EnabledModules)
};
additionalRpcUrlRows.Add(row);
}
}
catch (FormatException fe)
{
if (_logger.IsInfo) _logger.Info($"Additional JSON RPC URL packed value '{additionalRpcUrl}' format error: {fe.Message}; skipping...");
}
}
LogTable(additionalRpcUrlRows);
}
private void LogTable(List<string[]> 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++)
{
columnWidths[i] = headers[i].Length;
foreach (var row in rows)
{
if (i < row.Length)
{
columnWidths[i] = Math.Max(columnWidths[i], row[i]?.Length ?? 0);
}
}
}

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);

foreach (var row in rows)
{
_logger.Info(redSeparator + " " + string.Join(" " + redSeparator + " ", row.Select((cell, i) => (cell ?? "").PadRight(columnWidths[i]))) + " " + redSeparator);
}

_logger.Info(separator);
}
}