Skip to content

Commit

Permalink
Use Ordinal rather than InvariantCulture (#7898)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Dec 11, 2024
1 parent f29d19f commit 31e03ca
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/Nethermind/Nethermind.Blockchain/Find/BlockParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,15 @@ public static BlockParameter GetBlockParameter(string? value)
{
case null:
case { } empty when string.IsNullOrWhiteSpace(empty):
case { } latest when latest.Equals("latest", StringComparison.InvariantCultureIgnoreCase):
case { } latest when latest.Equals("latest", StringComparison.OrdinalIgnoreCase):
return BlockParameter.Latest;
case { } earliest when earliest.Equals("earliest", StringComparison.InvariantCultureIgnoreCase):
case { } earliest when earliest.Equals("earliest", StringComparison.OrdinalIgnoreCase):
return BlockParameter.Earliest;
case { } pending when pending.Equals("pending", StringComparison.InvariantCultureIgnoreCase):
case { } pending when pending.Equals("pending", StringComparison.OrdinalIgnoreCase):
return BlockParameter.Pending;
case { } finalized when finalized.Equals("finalized", StringComparison.InvariantCultureIgnoreCase):
case { } finalized when finalized.Equals("finalized", StringComparison.OrdinalIgnoreCase):
return BlockParameter.Finalized;
case { } safe when safe.Equals("safe", StringComparison.InvariantCultureIgnoreCase):
case { } safe when safe.Equals("safe", StringComparison.OrdinalIgnoreCase):
return BlockParameter.Safe;
case { Length: 66 } hash when hash.StartsWith("0x"):
return new BlockParameter(new Hash256(hash));
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Config/ConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public object GetRawValue(string category, string name)

return Categories.TryGetValue(category, out object value) ? value.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.SingleOrDefault(p => string.Equals(p.Name, name, StringComparison.InvariantCultureIgnoreCase))
.SingleOrDefault(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase))
?.GetValue(value) : null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Config/ConfigSourceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static object ParseValue(Type valueType, string valueString, string categ
}

private static bool IsNullString(string valueString) =>
string.IsNullOrEmpty(valueString) || valueString.Equals("null", StringComparison.InvariantCultureIgnoreCase);
string.IsNullOrEmpty(valueString) || valueString.Equals("null", StringComparison.OrdinalIgnoreCase);

public static object GetDefault(Type type) => type.IsValueType ? (false, Activator.CreateInstance(type)) : (false, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static bool TrySetTransactions(this Block block, Transaction[] transactio
public static bool IsByNethermindNode(this BlockHeader block) =>
Ascii.IsValid(block.ExtraData)
&& Encoding.ASCII.GetString(block.ExtraData ?? [])
.Contains(BlocksConfig.DefaultExtraData, StringComparison.InvariantCultureIgnoreCase);
.Contains(BlocksConfig.DefaultExtraData, StringComparison.OrdinalIgnoreCase);

public static string ParsedExtraData(this Block block)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcLocalStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public async Task Orders_alphabetically()
await localStats.ReportCall("B", 3, false);
MakeTimePass();
await localStats.ReportCall("A", 300, true);
_testLogger.LogList[0].IndexOf("A ", StringComparison.InvariantCulture).Should().BeLessThan(_testLogger.LogList[0].IndexOf("B ", StringComparison.InvariantCulture));
_testLogger.LogList[0].IndexOf("B ", StringComparison.InvariantCulture).Should().BeLessThan(_testLogger.LogList[0].IndexOf("C ", StringComparison.InvariantCulture));
_testLogger.LogList[0].IndexOf("A ", StringComparison.Ordinal).Should().BeLessThan(_testLogger.LogList[0].IndexOf("B ", StringComparison.Ordinal));
_testLogger.LogList[0].IndexOf("B ", StringComparison.Ordinal).Should().BeLessThan(_testLogger.LogList[0].IndexOf("C ", StringComparison.Ordinal));
}

private void MakeTimePass(int seconds)
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.JsonRpc/JsonRpcUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static JsonRpcUrl Parse(string packedUrlValue)
if (enabledModules.Length == 0)
throw new FormatException("Third part must contain at least one module delimited by ';'");

bool isAuthenticated = enabledModules.Contains(ModuleType.Engine, StringComparison.InvariantCultureIgnoreCase);
bool isAuthenticated = enabledModules.Contains(ModuleType.Engine, StringComparison.OrdinalIgnoreCase);

// Check if authentication disabled for this url
if (parts.Length == 4)
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public JsonRpcUrlCollection(ILogManager logManager, IJsonRpcConfig jsonRpcConfig

private void BuildUrls(bool includeWebSockets)
{
bool HasEngineApi = _jsonRpcConfig.EnabledModules.Any(m => m.Equals(ModuleType.Engine, StringComparison.InvariantCultureIgnoreCase));
bool HasEngineApi = _jsonRpcConfig.EnabledModules.Any(m => m.Equals(ModuleType.Engine, StringComparison.OrdinalIgnoreCase));
JsonRpcUrl defaultUrl = new(Uri.UriSchemeHttp, _jsonRpcConfig.Host, _jsonRpcConfig.Port, RpcEndpoint.Http, HasEngineApi, _jsonRpcConfig.EnabledModules, HasEngineApi ? SocketClient<WebSocketMessageStream>.MAX_REQUEST_BODY_SIZE_FOR_ENGINE_API : _jsonRpcConfig.MaxRequestBodySize);

Add(defaultUrl.Port, defaultUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public void ReadJson(JsonElement jsonValue, JsonSerializerOptions options)
}

string? text = jsonValue.GetString();
bool isTrue = string.Equals(text, bool.TrueString, StringComparison.InvariantCultureIgnoreCase);
bool isFalse = string.Equals(text, bool.FalseString, StringComparison.InvariantCultureIgnoreCase);
bool isTrue = string.Equals(text, bool.TrueString, StringComparison.OrdinalIgnoreCase);
bool isFalse = string.Equals(text, bool.FalseString, StringComparison.OrdinalIgnoreCase);

IncludeTransactions = isTrue || isFalse
? isTrue
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.KeyStore/FileKeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public FileKeyStore(
_jsonSerializer = jsonSerializer ?? throw new ArgumentNullException(nameof(jsonSerializer));
_symmetricEncrypter = symmetricEncrypter ?? throw new ArgumentNullException(nameof(symmetricEncrypter));
_cryptoRandom = cryptoRandom ?? throw new ArgumentNullException(nameof(cryptoRandom));
_keyStoreEncoding = _config.KeyStoreEncoding.Equals("UTF-8", StringComparison.InvariantCultureIgnoreCase)
_keyStoreEncoding = _config.KeyStoreEncoding.Equals("UTF-8", StringComparison.OrdinalIgnoreCase)
? new UTF8Encoding(false)
: Encoding.GetEncoding(_config.KeyStoreEncoding);
_privateKeyGenerator = new PrivateKeyGenerator(_cryptoRandom);
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Logging/PathUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public static class PathUtils
static PathUtils()
{
Process process = Process.GetCurrentProcess();
if (process.ProcessName.StartsWith("dotnet", StringComparison.InvariantCultureIgnoreCase)
|| process.ProcessName.Equals("ReSharperTestRunner", StringComparison.InvariantCultureIgnoreCase))
if (process.ProcessName.StartsWith("dotnet", StringComparison.OrdinalIgnoreCase)
|| process.ProcessName.Equals("ReSharperTestRunner", StringComparison.OrdinalIgnoreCase))
{
ExecutingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ private void EnsureJsonRpcUrl()

EnsureEngineModuleIsConfigured();

if (!jsonRpcConfig.EnabledModules.Contains(ModuleType.Engine, StringComparison.InvariantCultureIgnoreCase))
if (!jsonRpcConfig.EnabledModules.Contains(ModuleType.Engine, StringComparison.OrdinalIgnoreCase))
{
// Disable it
jsonRpcConfig.EnabledModules = [];
}

jsonRpcConfig.AdditionalRpcUrls = jsonRpcConfig.AdditionalRpcUrls
.Where((url) => JsonRpcUrl.Parse(url).EnabledModules.Contains(ModuleType.Engine, StringComparison.InvariantCultureIgnoreCase))
.Where((url) => JsonRpcUrl.Parse(url).EnabledModules.Contains(ModuleType.Engine, StringComparison.OrdinalIgnoreCase))
.ToArray();
}
else
Expand All @@ -213,7 +213,7 @@ private void EnsureEngineModuleIsConfigured()
JsonRpcUrlCollection urlCollection = new(_api.LogManager, _api.Config<IJsonRpcConfig>(), false);
bool hasEngineApiConfigured = urlCollection
.Values
.Any(rpcUrl => rpcUrl.EnabledModules.Contains(ModuleType.Engine, StringComparison.InvariantCultureIgnoreCase));
.Any(rpcUrl => rpcUrl.EnabledModules.Contains(ModuleType.Engine, StringComparison.OrdinalIgnoreCase));

if (!hasEngineApiConfigured)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Nethermind/Nethermind.Network.Dns/EnrTreeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ public static EnrTreeRoot ParseEnrRoot(string enrTreeRootText)

EnrTreeRoot enrTreeRoot = new();

int ensRootIndex = enrTreeRootText.IndexOf("e=", StringComparison.InvariantCulture);
int ensRootIndex = enrTreeRootText.IndexOf("e=", StringComparison.Ordinal);
enrTreeRoot.EnrRoot = enrTreeRootText.Substring(ensRootIndex + 2, HashLengthBase32);

int linkRootIndex = enrTreeRootText.IndexOf("l=", StringComparison.InvariantCulture);
int linkRootIndex = enrTreeRootText.IndexOf("l=", StringComparison.Ordinal);
enrTreeRoot.LinkRoot = enrTreeRootText.Substring(linkRootIndex + 2, HashLengthBase32);

int seqIndex = enrTreeRootText.IndexOf("seq=", StringComparison.InvariantCulture);
int seqIndex = enrTreeRootText.IndexOf("seq=", StringComparison.Ordinal);
int seqLength = enrTreeRootText.IndexOf(' ', seqIndex) - (seqIndex + 4);
enrTreeRoot.Sequence = int.Parse(enrTreeRootText.AsSpan(seqIndex + 4, seqLength));

int sigIndex = enrTreeRootText.IndexOf("sig=", StringComparison.InvariantCulture);
int sigIndex = enrTreeRootText.IndexOf("sig=", StringComparison.Ordinal);
enrTreeRoot.Signature = enrTreeRootText.Substring(sigIndex + 4, SigLengthBase32);

return enrTreeRoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public bool IsStatic(string enode)
{
NetworkNode node = new(enode);
return _nodes.TryGetValue(node.NodeId, out NetworkNode staticNode) && string.Equals(staticNode.Host,
node.Host, StringComparison.InvariantCultureIgnoreCase);
node.Host, StringComparison.OrdinalIgnoreCase);
}

private Task SaveFileAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void LoadParameters(ChainSpecJson chainSpecJson, ChainSpec chainSpec)
{
long? GetTransitions(string builtInName, Predicate<KeyValuePair<string, JsonElement>> predicate)
{
var allocation = chainSpecJson.Accounts?.Values.FirstOrDefault(v => v.BuiltIn?.Name.Equals(builtInName, StringComparison.InvariantCultureIgnoreCase) == true);
var allocation = chainSpecJson.Accounts?.Values.FirstOrDefault(v => v.BuiltIn?.Name.Equals(builtInName, StringComparison.OrdinalIgnoreCase) == true);
if (allocation is null) return null;
KeyValuePair<string, JsonElement>[] pricing = allocation.BuiltIn.Pricing.Where(o => predicate(o)).ToArray();
if (pricing.Length > 0)
Expand Down

0 comments on commit 31e03ca

Please sign in to comment.