Skip to content

Commit

Permalink
Fix second bug leading to testnet automatically switching to mainnet RPC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexmpa committed Dec 20, 2020
1 parent 2c43305 commit dcd3ec9
Showing 1 changed file with 51 additions and 26 deletions.
77 changes: 51 additions & 26 deletions Assets/Scripts/Wallet/AccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}
}
},
Expand All @@ -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();
}
}
}
})
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
}
}
},
Expand All @@ -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();
}
}
}
})
Expand Down

0 comments on commit dcd3ec9

Please sign in to comment.