From dcd3ec94e0d90d521c9d83f5c171eef0c0acc85a Mon Sep 17 00:00:00 2001 From: alexmpa <62516783+alexmpa@users.noreply.github.com> Date: Sun, 20 Dec 2020 20:03:23 +0300 Subject: [PATCH] Fix second bug leading to testnet automatically switching to mainnet RPC RPC benchmarking thread launched by switching to mainnet were still working after switching to other nexus, and after finding fastest mainnet RPC it changed setting to it --- Assets/Scripts/Wallet/AccountManager.cs | 77 ++++++++++++++++--------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/Assets/Scripts/Wallet/AccountManager.cs b/Assets/Scripts/Wallet/AccountManager.cs index 6aab82af..15ba30f2 100644 --- a/Assets/Scripts/Wallet/AccountManager.cs +++ b/Assets/Scripts/Wallet/AccountManager.cs @@ -458,12 +458,16 @@ public void UpdateRPCURL(PlatformKind platformKind) if (String.IsNullOrEmpty(Settings.phantasmaRPCURL)) { - // If we have no previously used RPC, we select random one at first. - var index = ((int)(Time.realtimeSinceStartup * 1000)) % rpcNumberPhantasma; - var node = response.GetNodeByIndex(index); - var result = node.GetString("url") + "/rpc"; - Settings.phantasmaRPCURL = result; - Log.Write($"Changed Phantasma RPC url {index} => {result}"); + // Checking if we are still on mainnet + if (Settings.nexusKind == NexusKind.Main_Net) + { + // If we have no previously used RPC, we select random one at first. + var index = ((int)(Time.realtimeSinceStartup * 1000)) % rpcNumberPhantasma; + var node = response.GetNodeByIndex(index); + var result = node.GetString("url") + "/rpc"; + Settings.phantasmaRPCURL = result; + Log.Write($"Changed Phantasma RPC url {index} => {result}"); + } } UpdateAPIs(); @@ -498,9 +502,14 @@ public void UpdateRPCURL(PlatformKind platformKind) else { Log.Write($"Fastest Phantasma RPC is {bestRpcUrl}: {new DateTime(bestTime.Ticks).ToString("ss.fff")} sec."); - Settings.phantasmaRPCURL = bestRpcUrl; - UpdateAPIs(); - Settings.SaveOnExit(); + + // Checking if we are still on mainnet + if (Settings.nexusKind == NexusKind.Main_Net) + { + Settings.phantasmaRPCURL = bestRpcUrl; + UpdateAPIs(); + Settings.SaveOnExit(); + } } } }, @@ -527,10 +536,14 @@ public void UpdateRPCURL(PlatformKind platformKind) } else { - Log.Write($"Fastest Phantasma RPC is {bestRpcUrl}: {new DateTime(bestTime.Ticks).ToString("ss.fff")} sec."); - Settings.phantasmaRPCURL = bestRpcUrl; - UpdateAPIs(); - Settings.SaveOnExit(); + // Checking if we are still on mainnet + if (Settings.nexusKind == NexusKind.Main_Net) + { + Log.Write($"Fastest Phantasma RPC is {bestRpcUrl}: {new DateTime(bestTime.Ticks).ToString("ss.fff")} sec."); + Settings.phantasmaRPCURL = bestRpcUrl; + UpdateAPIs(); + Settings.SaveOnExit(); + } } } }) @@ -549,11 +562,15 @@ public void UpdateRPCURL(PlatformKind platformKind) if (String.IsNullOrEmpty(Settings.neoRPCURL)) { - // If we have no previously used RPC, we select random one at first. - var index = ((int)(Time.realtimeSinceStartup * 1000)) % rpcNumberNeo; - var result = neoRpcList[index]; - Settings.neoRPCURL = result; - Log.Write($"Changed Neo RPC url {index} => {result}"); + // Checking if we are still on mainnet + if (Settings.nexusKind == NexusKind.Main_Net) + { + // If we have no previously used RPC, we select random one at first. + var index = ((int)(Time.realtimeSinceStartup * 1000)) % rpcNumberNeo; + var result = neoRpcList[index]; + Settings.neoRPCURL = result; + Log.Write($"Changed Neo RPC url {index} => {result}"); + } } UpdateAPIs(); @@ -585,10 +602,14 @@ public void UpdateRPCURL(PlatformKind platformKind) } else { - Log.Write($"Fastest Neo RPC is {bestRpcUrl}: {new DateTime(bestTime.Ticks).ToString("ss.fff")} sec."); - Settings.neoRPCURL = bestRpcUrl; - UpdateAPIs(); - Settings.SaveOnExit(); + // Checking if we are still on mainnet + if (Settings.nexusKind == NexusKind.Main_Net) + { + Log.Write($"Fastest Neo RPC is {bestRpcUrl}: {new DateTime(bestTime.Ticks).ToString("ss.fff")} sec."); + Settings.neoRPCURL = bestRpcUrl; + UpdateAPIs(); + Settings.SaveOnExit(); + } } } }, @@ -615,10 +636,14 @@ public void UpdateRPCURL(PlatformKind platformKind) } else { - Log.Write($"Fastest Neo RPC is {bestRpcUrl}: {new DateTime(bestTime.Ticks).ToString("ss.fff")} sec."); - Settings.neoRPCURL = bestRpcUrl; - UpdateAPIs(); - Settings.SaveOnExit(); + // Checking if we are still on mainnet + if (Settings.nexusKind == NexusKind.Main_Net) + { + Log.Write($"Fastest Neo RPC is {bestRpcUrl}: {new DateTime(bestTime.Ticks).ToString("ss.fff")} sec."); + Settings.neoRPCURL = bestRpcUrl; + UpdateAPIs(); + Settings.SaveOnExit(); + } } } })