Change Backend/Config according to new conventions
MODIFY
WalletWasabi.Backend/Config.cs
WalletWasabi.Backend/Config.cs
@@ -23,34 +23,35 @@ namespace WalletWasabi.Backend
[JsonProperty(PropertyName = "Network")]
[JsonConverter(typeof(NetworkJsonConverter))]
- public Network Network { get; private set; }
+ public Network Network { get; private set; } = Network.Main;
- [JsonProperty(PropertyName = "BitcoinRpcConnectionString")]
+ [DefaultValue("user:password")]
+ [JsonProperty(PropertyName = "BitcoinRpcConnectionString", DefaultValueHandling = DefaultValueHandling.Populate)]
public string BitcoinRpcConnectionString { get; private set; }
[JsonProperty(PropertyName = "MainNetBitcoinP2pEndPoint")]
[JsonConverter(typeof(EndPointJsonConverter), Constants.DefaultMainNetBitcoinP2pPort)]
- public EndPoint MainNetBitcoinP2pEndPoint { get; internal set; }
+ public EndPoint MainNetBitcoinP2pEndPoint { get; internal set; } = new IPEndPoint(IPAddress.Loopback, Constants.DefaultMainNetBitcoinP2pPort);
[JsonProperty(PropertyName = "TestNetBitcoinP2pEndPoint")]
[JsonConverter(typeof(EndPointJsonConverter), Constants.DefaultTestNetBitcoinP2pPort)]
- public EndPoint TestNetBitcoinP2pEndPoint { get; internal set; }
+ public EndPoint TestNetBitcoinP2pEndPoint { get; internal set; } = new IPEndPoint(IPAddress.Loopback, Constants.DefaultTestNetBitcoinP2pPort);
[JsonProperty(PropertyName = "RegTestBitcoinP2pEndPoint")]
[JsonConverter(typeof(EndPointJsonConverter), Constants.DefaultRegTestBitcoinP2pPort)]
- public EndPoint RegTestBitcoinP2pEndPoint { get; internal set; }
+ public EndPoint RegTestBitcoinP2pEndPoint { get; internal set; } = new IPEndPoint(IPAddress.Loopback, Constants.DefaultRegTestBitcoinP2pPort);
[JsonProperty(PropertyName = "MainNetBitcoinCoreRpcEndPoint")]
[JsonConverter(typeof(EndPointJsonConverter), Constants.DefaultMainNetBitcoinCoreRpcPort)]
- public EndPoint MainNetBitcoinCoreRpcEndPoint { get; internal set; }
+ public EndPoint MainNetBitcoinCoreRpcEndPoint { get; internal set; } = new IPEndPoint(IPAddress.Loopback, Constants.DefaultMainNetBitcoinCoreRpcPort);
[JsonProperty(PropertyName = "TestNetBitcoinCoreRpcEndPoint")]
[JsonConverter(typeof(EndPointJsonConverter), Constants.DefaultTestNetBitcoinCoreRpcPort)]
- public EndPoint TestNetBitcoinCoreRpcEndPoint { get; internal set; }
+ public EndPoint TestNetBitcoinCoreRpcEndPoint { get; internal set; } = new IPEndPoint(IPAddress.Loopback, Constants.DefaultTestNetBitcoinCoreRpcPort);
[JsonProperty(PropertyName = "RegTestBitcoinCoreRpcEndPoint")]
[JsonConverter(typeof(EndPointJsonConverter), Constants.DefaultRegTestBitcoinCoreRpcPort)]
- public EndPoint RegTestBitcoinCoreRpcEndPoint { get; internal set; }
+ public EndPoint RegTestBitcoinCoreRpcEndPoint { get; internal set; } = new IPEndPoint(IPAddress.Loopback, Constants.DefaultRegTestBitcoinCoreRpcPort);
public EndPoint GetBitcoinP2pEndPoint()
{
@@ -128,26 +129,14 @@ namespace WalletWasabi.Backend
AssertFilePathSet();
string jsonString = JsonConvert.SerializeObject(this, Formatting.Indented);
- await File.WriteAllTextAsync(FilePath,
- jsonString,
- Encoding.UTF8);
+ await File.WriteAllTextAsync(FilePath, jsonString, Encoding.UTF8);
}
/// <inheritdoc />
public async Task LoadOrCreateDefaultFileAsync()
{
AssertFilePathSet();
-
- Network = Network.Main;
- BitcoinRpcConnectionString = "user:password";
-
- MainNetBitcoinP2pEndPoint = new IPEndPoint(IPAddress.Loopback, Constants.DefaultMainNetBitcoinP2pPort);
- TestNetBitcoinP2pEndPoint = new IPEndPoint(IPAddress.Loopback, Constants.DefaultTestNetBitcoinP2pPort);
- RegTestBitcoinP2pEndPoint = new IPEndPoint(IPAddress.Loopback, Constants.DefaultRegTestBitcoinP2pPort);
-
- MainNetBitcoinCoreRpcEndPoint = new IPEndPoint(IPAddress.Loopback, Constants.DefaultMainNetBitcoinCoreRpcPort);
- TestNetBitcoinCoreRpcEndPoint = new IPEndPoint(IPAddress.Loopback, Constants.DefaultTestNetBitcoinCoreRpcPort);
- RegTestBitcoinCoreRpcEndPoint = new IPEndPoint(IPAddress.Loopback, Constants.DefaultRegTestBitcoinCoreRpcPort);
+ JsonConvert.PopulateObject("{}", this);
if (!File.Exists(FilePath))
{
@@ -156,18 +145,7 @@ namespace WalletWasabi.Backend
else
{
string jsonString = await File.ReadAllTextAsync(FilePath, Encoding.UTF8);
- var config = JsonConvert.DeserializeObject<Config>(jsonString);
-
- Network = config?.Network ?? Network;
- BitcoinRpcConnectionString = config?.BitcoinRpcConnectionString ?? BitcoinRpcConnectionString;
-
- MainNetBitcoinP2pEndPoint = config?.MainNetBitcoinP2pEndPoint ?? MainNetBitcoinP2pEndPoint;
- TestNetBitcoinP2pEndPoint = config?.TestNetBitcoinP2pEndPoint ?? TestNetBitcoinP2pEndPoint;
- RegTestBitcoinP2pEndPoint = config?.RegTestBitcoinP2pEndPoint ?? RegTestBitcoinP2pEndPoint;
-
- MainNetBitcoinCoreRpcEndPoint = config?.MainNetBitcoinCoreRpcEndPoint ?? MainNetBitcoinCoreRpcEndPoint;
- TestNetBitcoinCoreRpcEndPoint = config?.TestNetBitcoinCoreRpcEndPoint ?? TestNetBitcoinCoreRpcEndPoint;
- RegTestBitcoinCoreRpcEndPoint = config?.RegTestBitcoinCoreRpcEndPoint ?? RegTestBitcoinCoreRpcEndPoint;
+ JsonConvert.PopulateObject(jsonString, this);
if (TryEnsureBackwardsCompatibility(jsonString))
{

Change Backend/Config according to new conventions