Simplify backwardscomp check
MODIFY
WalletWasabi.Backend/Config.cs
WalletWasabi.Backend/Config.cs
@@ -162,49 +162,46 @@ namespace WalletWasabi.Backend
}
private bool TryEnsureBackwardsCompatibility(string jsonString)
+ {
+ try
{
var jsObject = JsonConvert.DeserializeObject<JObject>(jsonString);
bool saveIt = false;
- if (jsObject.TryGetValue("MainNetBitcoinCoreHost", out JToken jMainNetBitcoinCoreHost))
- {
- int port = Constants.DefaultMainNetBitcoinP2pPort;
- if (jsObject.TryGetValue("MainNetBitcoinCorePort", out JToken jMainNetBitcoinCorePort) && int.TryParse(jMainNetBitcoinCorePort.ToString(), out int p))
+ var mainNetBitcoinCoreHost = jsObject.Value<string>("MainNetBitcoinCoreHost");
+ var mainNetBitcoinCorePort = jsObject.Value<int?>("MainNetBitcoinCorePort");
+ var testNetBitcoinCoreHost = jsObject.Value<string>("TestNetBitcoinCoreHost");
+ var testNetBitcoinCorePort = jsObject.Value<int?>("TestNetBitcoinCorePort");
+ var regTestBitcoinCoreHost = jsObject.Value<string>("RegTestBitcoinCoreHost");
+ var regTestBitcoinCorePort = jsObject.Value<int?>("RegTestBitcoinCorePort");
+
+ if (mainNetBitcoinCoreHost != null)
{
- port = p;
- }
+ int port = mainNetBitcoinCorePort ?? Constants.DefaultMainNetBitcoinP2pPort;
- if (EndPointParser.TryParse(jMainNetBitcoinCoreHost.ToString(), port, out EndPoint ep))
+ if (EndPointParser.TryParse(mainNetBitcoinCoreHost, port, out EndPoint ep))
{
MainNetBitcoinP2pEndPoint = ep;
saveIt = true;
}
}
- if (jsObject.TryGetValue("TestNetBitcoinCoreHost", out JToken jTestNetBitcoinCoreHost))
- {
- int port = Constants.DefaultTestNetBitcoinP2pPort;
- if (jsObject.TryGetValue("TestNetBitcoinCorePort", out JToken jTestNetBitcoinCorePort) && int.TryParse(jTestNetBitcoinCorePort.ToString(), out int p))
+ if (testNetBitcoinCoreHost != null)
{
- port = p;
- }
+ int port = testNetBitcoinCorePort ?? Constants.DefaultTestNetBitcoinP2pPort;
- if (EndPointParser.TryParse(jTestNetBitcoinCoreHost.ToString(), port, out EndPoint ep))
+ if (EndPointParser.TryParse(testNetBitcoinCoreHost, port, out EndPoint ep))
{
TestNetBitcoinP2pEndPoint = ep;
saveIt = true;
}
}
- if (jsObject.TryGetValue("RegTestBitcoinCoreHost", out JToken jRegTestBitcoinCoreHost))
+ if (regTestBitcoinCoreHost != null)
{
- int port = Constants.DefaultRegTestBitcoinP2pPort;
- if (jsObject.TryGetValue("RegTestBitcoinCorePort", out JToken jRegTestBitcoinCorePort) && int.TryParse(jRegTestBitcoinCorePort.ToString(), out int p))
- {
- port = p;
- }
+ int port = regTestBitcoinCorePort ?? Constants.DefaultRegTestBitcoinP2pPort;
- if (EndPointParser.TryParse(jRegTestBitcoinCoreHost.ToString(), port, out EndPoint ep))
+ if (EndPointParser.TryParse(regTestBitcoinCoreHost, port, out EndPoint ep))
{
RegTestBitcoinP2pEndPoint = ep;
saveIt = true;
@@ -213,5 +210,12 @@ namespace WalletWasabi.Backend
return saveIt;
}
+ catch (Exception ex)
+ {
+ Logger.LogWarning<Config>("Backwards compatibility couldn't be ensured.");
+ Logger.LogInfo<Config>(ex);
+ return false;
+ }
+ }
}
}

MODIFY
WalletWasabi.Gui/Config.cs
WalletWasabi.Gui/Config.cs
@@ -420,64 +420,59 @@ namespace WalletWasabi.Gui
}
private bool TryEnsureBackwardsCompatibility(string jsonString)
+ {
+ try
{
var jsObject = JsonConvert.DeserializeObject<JObject>(jsonString);
bool saveIt = false;
- if (jsObject.TryGetValue("TorHost", out JToken jTorHost))
- {
- int port = Constants.DefaultTorSocksPort;
- if (jsObject.TryGetValue("TorSocks5Port", out JToken jTorSocks5Port) && int.TryParse(jTorSocks5Port.ToString(), out int p))
+ var torHost = jsObject.Value<string>("TorHost");
+ var torSocks5Port = jsObject.Value<int?>("TorSocks5Port");
+ var mainNetBitcoinCoreHost = jsObject.Value<string>("MainNetBitcoinCoreHost");
+ var mainNetBitcoinCorePort = jsObject.Value<int?>("MainNetBitcoinCorePort");
+ var testNetBitcoinCoreHost = jsObject.Value<string>("TestNetBitcoinCoreHost");
+ var testNetBitcoinCorePort = jsObject.Value<int?>("TestNetBitcoinCorePort");
+ var regTestBitcoinCoreHost = jsObject.Value<string>("RegTestBitcoinCoreHost");
+ var regTestBitcoinCorePort = jsObject.Value<int?>("RegTestBitcoinCorePort");
+
+ if (torHost != null)
{
- port = p;
- }
+ int port = torSocks5Port ?? Constants.DefaultTorSocksPort;
- if (EndPointParser.TryParse(jTorHost.ToString(), port, out EndPoint ep))
+ if (EndPointParser.TryParse(torHost, port, out EndPoint ep))
{
TorSocks5EndPoint = ep;
saveIt = true;
}
}
- if (jsObject.TryGetValue("MainNetBitcoinCoreHost", out JToken jMainNetBitcoinCoreHost))
+ if (mainNetBitcoinCoreHost != null)
{
- int port = Constants.DefaultMainNetBitcoinP2pPort;
- if (jsObject.TryGetValue("MainNetBitcoinCorePort", out JToken jMainNetBitcoinCorePort) && int.TryParse(jMainNetBitcoinCorePort.ToString(), out int p))
- {
- port = p;
- }
+ int port = mainNetBitcoinCorePort ?? Constants.DefaultMainNetBitcoinP2pPort;
- if (EndPointParser.TryParse(jMainNetBitcoinCoreHost.ToString(), port, out EndPoint ep))
+ if (EndPointParser.TryParse(mainNetBitcoinCoreHost, port, out EndPoint ep))
{
MainNetBitcoinP2pEndPoint = ep;
saveIt = true;
}
}
- if (jsObject.TryGetValue("TestNetBitcoinCoreHost", out JToken jTestNetBitcoinCoreHost))
- {
- int port = Constants.DefaultTestNetBitcoinP2pPort;
- if (jsObject.TryGetValue("TestNetBitcoinCorePort", out JToken jTestNetBitcoinCorePort) && int.TryParse(jTestNetBitcoinCorePort.ToString(), out int p))
+ if (testNetBitcoinCoreHost != null)
{
- port = p;
- }
+ int port = testNetBitcoinCorePort ?? Constants.DefaultTestNetBitcoinP2pPort;
- if (EndPointParser.TryParse(jTestNetBitcoinCoreHost.ToString(), port, out EndPoint ep))
+ if (EndPointParser.TryParse(testNetBitcoinCoreHost, port, out EndPoint ep))
{
TestNetBitcoinP2pEndPoint = ep;
saveIt = true;
}
}
- if (jsObject.TryGetValue("RegTestBitcoinCoreHost", out JToken jRegTestBitcoinCoreHost))
- {
- int port = Constants.DefaultRegTestBitcoinP2pPort;
- if (jsObject.TryGetValue("RegTestBitcoinCorePort", out JToken jRegTestBitcoinCorePort) && int.TryParse(jRegTestBitcoinCorePort.ToString(), out int p))
+ if (regTestBitcoinCoreHost != null)
{
- port = p;
- }
+ int port = regTestBitcoinCorePort ?? Constants.DefaultRegTestBitcoinP2pPort;
- if (EndPointParser.TryParse(jRegTestBitcoinCoreHost.ToString(), port, out EndPoint ep))
+ if (EndPointParser.TryParse(regTestBitcoinCoreHost, port, out EndPoint ep))
{
RegTestBitcoinP2pEndPoint = ep;
saveIt = true;
@@ -486,5 +481,12 @@ namespace WalletWasabi.Gui
return saveIt;
}
+ catch (Exception ex)
+ {
+ Logger.LogWarning<Config>("Backwards compatibility couldn't be ensured.");
+ Logger.LogInfo<Config>(ex);
+ return false;
+ }
+ }
}
}

Simplify backwardscomp check