Fix a few nullability warnings in config classes.
MODIFY
WalletWasabi.Backend/Config.cs
WalletWasabi.Backend/Config.cs
@@ -52,7 +52,7 @@ public class Config : ConfigBase
[DefaultValue("user:password")]
[JsonProperty(PropertyName = "BitcoinRpcConnectionString", DefaultValueHandling = DefaultValueHandling.Populate)]
- public string BitcoinRpcConnectionString { get; private set; }
+ public string BitcoinRpcConnectionString { get; private set; } = "user:password";
[JsonProperty(PropertyName = "MainNetBitcoinP2pEndPoint")]
[JsonConverter(typeof(EndPointJsonConverter), Constants.DefaultMainNetBitcoinP2pPort)]
@@ -123,6 +123,13 @@ public class Config : ConfigBase
try
{
var jsObject = JsonConvert.DeserializeObject<JObject>(jsonString);
+
+ if (jsObject is null)
+ {
+ Logger.LogWarning("Failed to parse config JSON.");
+ return false;
+ }
+
bool saveIt = false;
var mainNetBitcoinCoreHost = jsObject.Value<string>("MainNetBitcoinCoreHost");

MODIFY
WalletWasabi.Fluent/Config.cs
WalletWasabi.Fluent/Config.cs
@@ -24,13 +24,17 @@ public class Config : ConfigBase
public const int DefaultJsonRpcServerPort = 37128;
public static readonly Money DefaultDustThreshold = Money.Coins(Constants.DefaultDustThreshold);
- private Uri _backendUri = null;
- private Uri _fallbackBackendUri;
+ private Uri? _backendUri = null;
+ private Uri? _fallbackBackendUri;
private int _minAnonScoreTarget;
private int _maxAnonScoreTarget;
+ /// <summary>
+ /// Constructor for config population using Newtonsoft.JSON.
+ /// </summary>
public Config() : base()
{
+ ServiceConfiguration = null!;
}
public Config(string filePath) : base(filePath)
@@ -44,39 +48,39 @@ public class Config : ConfigBase
[DefaultValue("http://wasabiukrxmkdgve5kynjztuovbg43uxcbcxn6y2okcrsg7gb6jdmbad.onion/")]
[JsonProperty(PropertyName = "MainNetBackendUriV3", DefaultValueHandling = DefaultValueHandling.Populate)]
- public string MainNetBackendUriV3 { get; private set; }
+ public string MainNetBackendUriV3 { get; private set; } = "http://wasabiukrxmkdgve5kynjztuovbg43uxcbcxn6y2okcrsg7gb6jdmbad.onion/";
[DefaultValue("http://testwnp3fugjln6vh5vpj7mvq3lkqqwjj3c2aafyu7laxz42kgwh2rad.onion/")]
[JsonProperty(PropertyName = "TestNetBackendUriV3", DefaultValueHandling = DefaultValueHandling.Populate)]
- public string TestNetBackendUriV3 { get; private set; }
+ public string TestNetBackendUriV3 { get; private set; } = "http://testwnp3fugjln6vh5vpj7mvq3lkqqwjj3c2aafyu7laxz42kgwh2rad.onion/";
[DefaultValue("https://wasabiwallet.io/")]
[JsonProperty(PropertyName = "MainNetFallbackBackendUri", DefaultValueHandling = DefaultValueHandling.Populate)]
- public string MainNetFallbackBackendUri { get; private set; }
+ public string MainNetFallbackBackendUri { get; private set; } = "https://wasabiwallet.io/";
[DefaultValue("https://wasabiwallet.co/")]
[JsonProperty(PropertyName = "TestNetFallbackBackendUri", DefaultValueHandling = DefaultValueHandling.Populate)]
- public string TestNetFallbackBackendUri { get; private set; }
+ public string TestNetFallbackBackendUri { get; private set; } = "https://wasabiwallet.co/";
[DefaultValue("http://localhost:37127/")]
[JsonProperty(PropertyName = "RegTestBackendUriV3", DefaultValueHandling = DefaultValueHandling.Populate)]
- public string RegTestBackendUriV3 { get; private set; }
+ public string RegTestBackendUriV3 { get; private set; } = "http://localhost:37127/";
[DefaultValue(true)]
[JsonProperty(PropertyName = "UseTor", DefaultValueHandling = DefaultValueHandling.Populate)]
- public bool UseTor { get; internal set; }
+ public bool UseTor { get; internal set; } = true;
[DefaultValue(false)]
[JsonProperty(PropertyName = "TerminateTorOnExit", DefaultValueHandling = DefaultValueHandling.Populate)]
- public bool TerminateTorOnExit { get; internal set; }
+ public bool TerminateTorOnExit { get; internal set; } = false;
[DefaultValue(false)]
[JsonProperty(PropertyName = "StartLocalBitcoinCoreOnStartup", DefaultValueHandling = DefaultValueHandling.Populate)]
- public bool StartLocalBitcoinCoreOnStartup { get; internal set; }
+ public bool StartLocalBitcoinCoreOnStartup { get; internal set; } = false;
[DefaultValue(true)]
[JsonProperty(PropertyName = "StopLocalBitcoinCoreOnShutdown", DefaultValueHandling = DefaultValueHandling.Populate)]
- public bool StopLocalBitcoinCoreOnShutdown { get; internal set; }
+ public bool StopLocalBitcoinCoreOnShutdown { get; internal set; } = true;
[JsonProperty(PropertyName = "LocalBitcoinCoreDataDir")]
public string LocalBitcoinCoreDataDir { get; internal set; } = EnvironmentHelpers.GetDefaultBitcoinCoreDataDirOrEmptyString();
@@ -99,11 +103,11 @@ public class Config : ConfigBase
[DefaultValue("")]
[JsonProperty(PropertyName = "JsonRpcUser", DefaultValueHandling = DefaultValueHandling.Populate)]
- public string JsonRpcUser { get; internal set; }
+ public string JsonRpcUser { get; internal set; } = "";
[DefaultValue("")]
[JsonProperty(PropertyName = "JsonRpcPassword", DefaultValueHandling = DefaultValueHandling.Populate)]
- public string JsonRpcPassword { get; internal set; }
+ public string JsonRpcPassword { get; internal set; } = "";
[JsonProperty(PropertyName = "JsonRpcServerPrefixes")]
public string[] JsonRpcServerPrefixes { get; internal set; } = new[]
@@ -269,6 +273,13 @@ public class Config : ConfigBase
try
{
var jsObject = JsonConvert.DeserializeObject<JObject>(jsonString);
+
+ if (jsObject is null)
+ {
+ Logger.LogWarning("Failed to parse config JSON.");
+ return false;
+ }
+
bool saveIt = false;
var torHost = jsObject.Value<string>("TorHost");

MODIFY
WalletWasabi/Bases/ConfigBase.cs
WalletWasabi/Bases/ConfigBase.cs
@@ -43,7 +43,7 @@ public abstract class ConfigBase : NotifyPropertyChangedBase, IConfig
string jsonString = File.ReadAllText(FilePath, Encoding.UTF8);
- var newConfigObject = Activator.CreateInstance(GetType());
+ var newConfigObject = Activator.CreateInstance(GetType())!;
JsonConvert.PopulateObject(jsonString, newConfigObject);
return !AreDeepEqual(newConfigObject);

Fix a few nullability warnings in config classes.