Make MixUntilAnonymitySet an enum
MODIFY
WalletWasabi.Gui/CommandLine/Daemon.cs
WalletWasabi.Gui/CommandLine/Daemon.cs
@@ -100,7 +100,7 @@ namespace WalletWasabi.Gui.CommandLine
if (isDifferentDestinationSpecified && !AnyCoinsQueued())
{
Wallet.ChaumianClient.DestinationKeyManager = destinationKeyManager;
- await TryQueueCoinsToMixAsync(password, minAnonset: Wallet.ServiceConfiguration.MixUntilAnonymitySet);
+ await TryQueueCoinsToMixAsync(password, minAnonset: Wallet.ServiceConfiguration.GetMixUntilAnonymitySetValue());
}
if (Global.KillRequested)
@@ -112,7 +112,7 @@ namespace WalletWasabi.Gui.CommandLine
if (!AnyCoinsQueued())
{
Wallet.ChaumianClient.DestinationKeyManager = Wallet.ChaumianClient.KeyManager;
- await TryQueueCoinsToMixAsync(password, maxAnonset: Wallet.ServiceConfiguration.MixUntilAnonymitySet - 1);
+ await TryQueueCoinsToMixAsync(password, maxAnonset: Wallet.ServiceConfiguration.GetMixUntilAnonymitySetValue() - 1);
}
if (Global.KillRequested)

MODIFY
WalletWasabi.Gui/Config.cs
WalletWasabi.Gui/Config.cs
@@ -26,7 +26,6 @@ namespace WalletWasabi.Gui
public const int DefaultPrivacyLevelSome = 2;
public const int DefaultPrivacyLevelFine = 21;
public const int DefaultPrivacyLevelStrong = 50;
- public const int DefaultMixUntilAnonymitySet = 50;
public const int DefaultTorSock5Port = 9050;
public const int DefaultJsonRpcServerPort = 37128;
public static readonly Money DefaultDustThreshold = Money.Coins(Constants.DefaultDustThreshold);
@@ -34,7 +33,7 @@ namespace WalletWasabi.Gui
private Uri _backendUri = null;
private Uri _fallbackBackendUri;
- private int _mixUntilAnonymitySet;
+ private string _mixUntilAnonymitySet = WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelStrong.ToString();
private int _privacyLevelSome;
private int _privacyLevelFine;
private int _privacyLevelStrong;
@@ -122,9 +121,9 @@ namespace WalletWasabi.Gui
"http://localhost:37128/"
};
- [DefaultValue(DefaultMixUntilAnonymitySet)]
+ [DefaultValue(nameof(WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelStrong))]
[JsonProperty(PropertyName = "MixUntilAnonymitySet", DefaultValueHandling = DefaultValueHandling.Populate)]
- public int MixUntilAnonymitySet
+ public string MixUntilAnonymitySet
{
get => _mixUntilAnonymitySet;
internal set
@@ -329,79 +328,105 @@ namespace WalletWasabi.Gui
}
}
- public static Config LoadOrCreateDefaultFile(string path)
+ private int CorrectMixUntilAnonymitySetValue()
{
- var config = new Config(path);
- config.LoadOrCreateDefaultFile();
-
- // MixUntilAnonymitySet sanity check.
- if (config.MixUntilAnonymitySet != config.PrivacyLevelFine &&
- config.MixUntilAnonymitySet != config.PrivacyLevelSome &&
- config.MixUntilAnonymitySet != config.PrivacyLevelStrong)
+ if (int.TryParse(MixUntilAnonymitySet, out int mixUntilAnonymitySetValue))
{
- if (config.MixUntilAnonymitySet < config.PrivacyLevelSome)
+ if (mixUntilAnonymitySetValue <= PrivacyLevelSome)
{
- config.MixUntilAnonymitySet = config.PrivacyLevelSome;
+ MixUntilAnonymitySet = WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelSome.ToString();
+ ToFile();
+ return PrivacyLevelSome;
}
- else if (config.MixUntilAnonymitySet < config.PrivacyLevelFine)
+ else if (mixUntilAnonymitySetValue <= PrivacyLevelFine)
{
- config.MixUntilAnonymitySet = config.PrivacyLevelFine;
+ MixUntilAnonymitySet = WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelFine.ToString();
+ ToFile();
+ return PrivacyLevelFine;
}
else
{
- config.MixUntilAnonymitySet = config.PrivacyLevelStrong;
+ MixUntilAnonymitySet = WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelStrong.ToString();
+ ToFile();
+ return PrivacyLevelStrong;
}
}
-
- return config;
+ else
+ {
+ MixUntilAnonymitySet = WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelStrong.ToString();
+ ToFile();
+ return PrivacyLevelStrong;
+ }
}
public TargetPrivacy GetTargetPrivacy()
{
- if (MixUntilAnonymitySet == PrivacyLevelSome)
+ if (MixUntilAnonymitySet == WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelSome.ToString())
{
return TargetPrivacy.Some;
}
- if (MixUntilAnonymitySet == PrivacyLevelFine)
+ if (MixUntilAnonymitySet == WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelFine.ToString())
{
return TargetPrivacy.Fine;
}
- if (MixUntilAnonymitySet == PrivacyLevelStrong)
- {
return TargetPrivacy.Strong;
}
- //the levels changed in the config file, adjust
- if (MixUntilAnonymitySet < PrivacyLevelSome)
+ public string GetTargetLevel(TargetPrivacy target)
+ {
+ return target switch
{
- return TargetPrivacy.None; //choose the lower
+ TargetPrivacy.Some => WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelSome.ToString(),
+ TargetPrivacy.Fine => WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelFine.ToString(),
+ _ => WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelStrong.ToString()
+ };
}
- if (MixUntilAnonymitySet < PrivacyLevelFine)
+ public int GetMixUntilAnonymitySetValue()
{
- return TargetPrivacy.Some;
+ return GetMixUntilAnonymitySetValue(MixUntilAnonymitySet);
}
- if (MixUntilAnonymitySet < PrivacyLevelStrong)
+ public int GetMixUntilAnonymitySetValue(string mixUntilAnonymitySet)
{
- return TargetPrivacy.Fine;
+ if (mixUntilAnonymitySet == WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelSome.ToString())
+ {
+ return PrivacyLevelSome;
+ }
+ else if (mixUntilAnonymitySet == WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelFine.ToString())
+ {
+ return PrivacyLevelFine;
+ }
+ else if (mixUntilAnonymitySet == WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelStrong.ToString())
+ {
+ return PrivacyLevelStrong;
+ }
+ else
+ {
+ return CorrectMixUntilAnonymitySetValue();
}
-
- return TargetPrivacy.Strong;
}
- public int GetTargetLevel(TargetPrivacy target)
+ public void CorrectMixUntilAnonymitySet()
{
- return target switch
+ if (MixUntilAnonymitySet == WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelSome.ToString())
{
- TargetPrivacy.None => 0,
- TargetPrivacy.Some => PrivacyLevelSome,
- TargetPrivacy.Fine => PrivacyLevelFine,
- TargetPrivacy.Strong => PrivacyLevelStrong,
- _ => 0
- };
+ return;
+ }
+ else if (MixUntilAnonymitySet == WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelFine.ToString())
+ {
+ return;
+ }
+ else if (MixUntilAnonymitySet == WalletWasabi.Models.MixUntilAnonymitySet.PrivacyLevelStrong.ToString())
+ {
+ return;
+ }
+ else
+ {
+ CorrectMixUntilAnonymitySetValue();
+ }
}
protected override bool TryEnsureBackwardsCompatibility(string jsonString)

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinJoinTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinJoinTabViewModel.cs
@@ -45,7 +45,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
private string _dequeueButtonText;
private const string DequeueButtonTextString = "Dequeue Selected Coins";
private const string DequeuingButtonTextString = "Dequeuing coins...";
- private int _coinJoinUntilAnonymitySet;
+ private string _coinJoinUntilAnonymitySet;
private TargetPrivacy _targetPrivacy;
public CoinJoinTabViewModel(Wallet wallet)
@@ -81,10 +81,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
switch (TargetPrivacy)
{
- case TargetPrivacy.None:
- TargetPrivacy = TargetPrivacy.Some;
- break;
-
case TargetPrivacy.Some:
TargetPrivacy = TargetPrivacy.Fine;
break;
@@ -223,7 +219,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
set => this.RaiseAndSetIfChanged(ref _dequeueButtonText, value);
}
- public int CoinJoinUntilAnonymitySet
+ public string CoinJoinUntilAnonymitySet
{
get => _coinJoinUntilAnonymitySet;
set => this.RaiseAndSetIfChanged(ref _coinJoinUntilAnonymitySet, value);

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinListViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinListViewModel.cs
@@ -153,7 +153,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
switch (SelectPrivateCheckBoxState)
{
case true:
- SelectCoins(x => x.AnonymitySet >= Global.Config.MixUntilAnonymitySet);
+ SelectCoins(x => x.AnonymitySet >= Global.Config.GetMixUntilAnonymitySetValue());
break;
case null:
@@ -169,7 +169,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
switch (SelectNonPrivateCheckBoxState)
{
case true:
- SelectCoins(x => x.AnonymitySet < Global.Config.MixUntilAnonymitySet);
+ SelectCoins(x => x.AnonymitySet < Global.Config.GetMixUntilAnonymitySetValue());
break;
case false:
@@ -402,8 +402,8 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
private void RefreshSelectionCheckBoxes(CoinViewModel[] coins)
{
SelectAllCheckBoxState = GetCheckBoxesSelectedState(coins, x => true);
- SelectPrivateCheckBoxState = GetCheckBoxesSelectedState(coins, x => x.AnonymitySet >= Global.Config.MixUntilAnonymitySet);
- SelectNonPrivateCheckBoxState = GetCheckBoxesSelectedState(coins, x => x.AnonymitySet < Global.Config.MixUntilAnonymitySet);
+ SelectPrivateCheckBoxState = GetCheckBoxesSelectedState(coins, x => x.AnonymitySet >= Global.Config.GetMixUntilAnonymitySetValue());
+ SelectNonPrivateCheckBoxState = GetCheckBoxesSelectedState(coins, x => x.AnonymitySet < Global.Config.GetMixUntilAnonymitySetValue());
}
private void RefreshStatusColumnWidth(CoinViewModel[] coins)
@@ -477,7 +477,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
try
{
- RefreshSelectCheckBoxesShields(x);
+ RefreshSelectCheckBoxesShields(Global.Config.GetMixUntilAnonymitySetValue(x));
RefreshSelectionCheckBoxes(RootList.Items.ToArray());
}
catch (Exception ex)

MODIFY
WalletWasabi.Gui/Converters/PrivacyLevelValueConverter.cs
WalletWasabi.Gui/Converters/PrivacyLevelValueConverter.cs
@@ -35,12 +35,14 @@ namespace WalletWasabi.Gui.Converters
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (value is int integer)
{
var config = Locator.Current.GetService<Global>().Config;
string shield;
string toolTip = null;
+ int integer = value is int
+ ? (int)value
+ : config.GetMixUntilAnonymitySetValue(value.ToString());
+
if (integer < config.PrivacyLevelSome)
{
shield = "Critical";
@@ -67,11 +69,6 @@ namespace WalletWasabi.Gui.Converters
var icon = GetIconByName($"Privacy{shield}");
return new { Icon = icon, ToolTip = toolTip };
}
- else
- {
- throw new TypeArgumentException(value, typeof(int), nameof(value));
- }
- }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{

MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -89,6 +89,7 @@ namespace WalletWasabi.Gui
UiConfig.LoadOrCreateDefaultFile();
Config = new Config(Path.Combine(DataDir, "Config.json"));
Config.LoadOrCreateDefaultFile();
+ Config.CorrectMixUntilAnonymitySet();
HostedServices = new HostedServices();
WalletManager = new WalletManager(Network, new WalletDirectories(DataDir));

MODIFY
WalletWasabi.Gui/Models/TargetPrivacy.cs
WalletWasabi.Gui/Models/TargetPrivacy.cs
@@ -6,7 +6,6 @@ namespace WalletWasabi.Gui.Models
{
public enum TargetPrivacy
{
- None,
Some,
Fine,
Strong

MODIFY
WalletWasabi.Gui/Tabs/SettingsViewModel.cs
WalletWasabi.Gui/Tabs/SettingsViewModel.cs
@@ -56,7 +56,7 @@ namespace WalletWasabi.Gui.Tabs
CustomFee = Global.UiConfig.IsCustomFee;
CustomChangeAddress = Global.UiConfig.IsCustomChangeAddress;
- var config = Config.LoadOrCreateDefaultFile(Global.Config.FilePath);
+ var config = Global.Config;
Network = config.Network;
TorSocks5EndPoint = config.TorSocks5EndPoint.ToString(-1);
@@ -187,6 +187,7 @@ namespace WalletWasabi.Gui.Tabs
get => _network;
set => this.RaiseAndSetIfChanged(ref _network, value);
}
+
public string TorSocks5EndPoint
{
get => _torSocks5EndPoint;

MODIFY
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
@@ -94,7 +94,7 @@ namespace WalletWasabi.Tests.IntegrationTests
KeyManager keyManager = KeyManager.CreateNew(out _, "password");
WasabiSynchronizer syncer = new WasabiSynchronizer(network, bitcoinStore, new Uri("http://localhost:12345"), Global.Instance.TorSocks5Endpoint);
- ServiceConfiguration serviceConfig = new ServiceConfiguration(50, 2, 21, 50, new IPEndPoint(IPAddress.Loopback, network.DefaultPort), Money.Coins(Constants.DefaultDustThreshold));
+ ServiceConfiguration serviceConfig = new ServiceConfiguration(MixUntilAnonymitySet.PrivacyLevelStrong.ToString(), 2, 21, 50, new IPEndPoint(IPAddress.Loopback, network.DefaultPort), Money.Coins(Constants.DefaultDustThreshold));
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, syncer, serviceConfig, network),
new FileSystemBlockRepository(blocksFolderPath, network));
@@ -106,7 +106,7 @@ namespace WalletWasabi.Tests.IntegrationTests
syncer,
nodes,
dataDir,
- new ServiceConfiguration(50, 2, 21, 50, new IPEndPoint(IPAddress.Loopback, network.DefaultPort), Money.Coins(Constants.DefaultDustThreshold)),
+ new ServiceConfiguration(MixUntilAnonymitySet.PrivacyLevelStrong.ToString(), 2, 21, 50, new IPEndPoint(IPAddress.Loopback, network.DefaultPort), Money.Coins(Constants.DefaultDustThreshold)),
syncer,
blockProvider);
Assert.True(Directory.Exists(blocksFolderPath));

MODIFY
WalletWasabi.Tests/RegressionTests/Common.cs
WalletWasabi.Tests/RegressionTests/Common.cs
@@ -84,7 +84,7 @@ namespace WalletWasabi.Tests.RegressionTests
global.Coordinator.UtxoReferee.Clear();
var network = global.RpcClient.Network;
- var serviceConfiguration = new ServiceConfiguration(2, 2, 21, 50, regTestFixture.BackendRegTestNode.P2pEndPoint, Money.Coins(Constants.DefaultDustThreshold));
+ var serviceConfiguration = new ServiceConfiguration(MixUntilAnonymitySet.PrivacyLevelSome.ToString(), 2, 21, 50, regTestFixture.BackendRegTestNode.P2pEndPoint, Money.Coins(Constants.DefaultDustThreshold));
var bitcoinStore = new BitcoinStore();
var dir = GetWorkDir(callerFilePath, callerMemberName);
await bitcoinStore.InitializeAsync(dir, network);

ADD
WalletWasabi/Models/MixUntilAnonymitySet.cs
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WalletWasabi.Models
+{
+ public enum MixUntilAnonymitySet
+ {
+ PrivacyLevelSome,
+ PrivacyLevelFine,
+ PrivacyLevelStrong
+ }
+}

MODIFY
WalletWasabi/Models/ServiceConfiguration.cs
WalletWasabi/Models/ServiceConfiguration.cs
@@ -10,7 +10,7 @@ namespace WalletWasabi.Models
public class ServiceConfiguration
{
public ServiceConfiguration(
- int mixUntilAnonymitySet,
+ string mixUntilAnonymitySet,
int privacyLevelSome,
int privacyLevelFine,
int privacyLevelStrong,
@@ -25,11 +25,27 @@ namespace WalletWasabi.Models
DustThreshold = Guard.NotNull(nameof(dustThreshold), dustThreshold);
}
- public int MixUntilAnonymitySet { get; set; }
+ public string MixUntilAnonymitySet { get; set; }
public int PrivacyLevelSome { get; set; }
public int PrivacyLevelFine { get; set; }
public int PrivacyLevelStrong { get; set; }
public EndPoint BitcoinCoreEndPoint { get; set; }
public Money DustThreshold { get; set; }
+
+ public int GetMixUntilAnonymitySetValue()
+ {
+ if (MixUntilAnonymitySet == Models.MixUntilAnonymitySet.PrivacyLevelSome.ToString())
+ {
+ return PrivacyLevelSome;
+ }
+ else if (MixUntilAnonymitySet == Models.MixUntilAnonymitySet.PrivacyLevelFine.ToString())
+ {
+ return PrivacyLevelFine;
+ }
+ else
+ {
+ return PrivacyLevelStrong;
+ }
+ }
}
}

MODIFY
WalletWasabi/Wallets/Wallet.cs
WalletWasabi/Wallets/Wallet.cs
@@ -339,7 +339,7 @@ namespace WalletWasabi.Wallets
{
// If it's being mixed and anonset is not sufficient, then queue it.
if (newCoin.Unspent && ChaumianClient.HasIngredients
- && newCoin.AnonymitySet < ServiceConfiguration.MixUntilAnonymitySet)
+ && newCoin.AnonymitySet < ServiceConfiguration.GetMixUntilAnonymitySetValue())
{
coinsToQueue.Add(newCoin);
}

Make MixUntilAnonymitySet an enum