diff --git a/WalletWasabi.Fluent/Helpers/TimeSpanFormatter.cs b/WalletWasabi.Fluent/Helpers/TimeSpanFormatter.cs index 278f8eac730..4275b64d6e2 100644 --- a/WalletWasabi.Fluent/Helpers/TimeSpanFormatter.cs +++ b/WalletWasabi.Fluent/Helpers/TimeSpanFormatter.cs @@ -15,7 +15,7 @@ public static string Format(TimeSpan timeSpan, Configuration configuration) GetHours(reduced, configuration), GetMinutes(reduced, configuration) }; - + return parts.First(s => s is not null) ?? throw new InvalidOperationException($"Invalid timeSpan: {timeSpan}"); } @@ -51,15 +51,15 @@ public static string Format(TimeSpan timeSpan, Configuration configuration) public class Configuration { - public string DaysLabel { get; } - public string HoursLabel { get; } - public string MinutesLabel { get; } - public Configuration(string daysLabel, string hoursLabel, string minutesLabel) { DaysLabel = daysLabel; HoursLabel = hoursLabel; MinutesLabel = minutesLabel; } + + public string DaysLabel { get; } + public string HoursLabel { get; } + public string MinutesLabel { get; } } -} \ No newline at end of file +} diff --git a/WalletWasabi.Fluent/ViewModels/Dialogs/ShowQrCameraDialogViewModel.cs b/WalletWasabi.Fluent/ViewModels/Dialogs/ShowQrCameraDialogViewModel.cs index f231e00c2ee..a4db2bad819 100644 --- a/WalletWasabi.Fluent/ViewModels/Dialogs/ShowQrCameraDialogViewModel.cs +++ b/WalletWasabi.Fluent/ViewModels/Dialogs/ShowQrCameraDialogViewModel.cs @@ -18,7 +18,6 @@ public partial class ShowQrCameraDialogViewModel : DialogViewModelBase [AutoNotify] private Bitmap? _qrImage; [AutoNotify] private string _message = ""; - private CancellationTokenSource CancellationTokenSource { get; } = new(); private WebcamQrReader _qrReader; public ShowQrCameraDialogViewModel(Network network) @@ -27,6 +26,8 @@ public ShowQrCameraDialogViewModel(Network network) SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: true); } + private CancellationTokenSource CancellationTokenSource { get; } = new(); + protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disposables) { base.OnNavigatedTo(isInHistory, disposables); diff --git a/WalletWasabi.Tests/UnitTests/Wallet/SmartCoinSelectorTests.cs b/WalletWasabi.Tests/UnitTests/Wallet/SmartCoinSelectorTests.cs index 98ed2f93cc6..abd34e6c697 100644 --- a/WalletWasabi.Tests/UnitTests/Wallet/SmartCoinSelectorTests.cs +++ b/WalletWasabi.Tests/UnitTests/Wallet/SmartCoinSelectorTests.cs @@ -10,13 +10,13 @@ namespace WalletWasabi.Tests.UnitTests.Wallet; public class SmartCoinSelectorTests { - private KeyManager KeyManager { get; } - public SmartCoinSelectorTests() { KeyManager = KeyManager.Recover(new Mnemonic("all all all all all all all all all all all all"), "", Network.Main, KeyManager.GetAccountKeyPath(Network.Main)); } + private KeyManager KeyManager { get; } + [Fact] public void SelectsOnlyOneCoinWhenPossible() { @@ -26,10 +26,12 @@ public void SelectsOnlyOneCoinWhenPossible() var cluster = new Cluster(keys); var smartCoins = keys - .Select((key, i) => { - var coin =BitcoinFactory.CreateSmartCoin(key, 0.1m * (i+1)); + .Select((key, i) => + { + var coin = BitcoinFactory.CreateSmartCoin(key, 0.1m * (i + 1)); coin.HdPubKey.Cluster = cluster; - return coin; }) + return coin; + }) .ToList(); var selector = new SmartCoinSelector(smartCoins); @@ -49,10 +51,12 @@ public void PreferLessCoinsOverExactAmount() var cluster = new Cluster(keys); var smartCoins = keys - .Select((key, i) => { - var coin = BitcoinFactory.CreateSmartCoin(key, 0.1m * (i+1)); + .Select((key, i) => + { + var coin = BitcoinFactory.CreateSmartCoin(key, 0.1m * (i + 1)); coin.HdPubKey.Cluster = cluster; - return coin; }) + return coin; + }) .ToList(); smartCoins.Add(BitcoinFactory.CreateSmartCoin(keys[0], 0.11m)); @@ -75,10 +79,12 @@ public void PreferSameScript() var cluster = new Cluster(keys); var smartCoins = keys - .ConvertAll(key => { + .ConvertAll(key => + { var coin = BitcoinFactory.CreateSmartCoin(key, 0.2m); coin.HdPubKey.Cluster = cluster; - return coin; }); + return coin; + }); smartCoins.Add(BitcoinFactory.CreateSmartCoin(keys[0], 0.11m)); @@ -101,10 +107,12 @@ public void PreferMorePrivateClusterScript() var juanCluster = new Cluster(keys1); var coinsKnownByJuan = keys1 - .ConvertAll(key => { + .ConvertAll(key => + { var coin = BitcoinFactory.CreateSmartCoin(key, 0.2m); coin.HdPubKey.Cluster = juanCluster; - return coin; }); + return coin; + }); var keys2 = Enumerable.Range(0, 2) .Select(_ => KeyManager.GenerateNewKey(new SmartLabel("Juan"), KeyState.Clean, false)) @@ -113,10 +121,12 @@ public void PreferMorePrivateClusterScript() var betoCluster = new Cluster(keys2); var coinsKnownByBeto = keys2 - .ConvertAll(key => { + .ConvertAll(key => + { var coin = BitcoinFactory.CreateSmartCoin(key, 0.2m); coin.HdPubKey.Cluster = betoCluster; - return coin; }); + return coin; + }); var selector = new SmartCoinSelector(coinsKnownByJuan.Concat(coinsKnownByBeto).ToList()); var coinsToSpend = selector.Select(Enumerable.Empty(), Money.Coins(0.3m)).Cast().ToList(); @@ -124,4 +134,4 @@ public void PreferMorePrivateClusterScript() Assert.Equal(2, coinsToSpend.Count); Assert.Equal(0.4m, coinsToSpend.Sum(x => x.Amount.ToUnit(MoneyUnit.BTC))); } -} \ No newline at end of file +} diff --git a/WalletWasabi/Backend/Models/FilterModel.cs b/WalletWasabi/Backend/Models/FilterModel.cs index bf9b2cb2a91..b83129bd6aa 100644 --- a/WalletWasabi/Backend/Models/FilterModel.cs +++ b/WalletWasabi/Backend/Models/FilterModel.cs @@ -8,6 +8,8 @@ namespace WalletWasabi.Backend.Models; public class FilterModel { + private Lazy _filter; + public FilterModel(SmartHeader header, GolombRiceFilter filter) { Header = header; @@ -22,7 +24,6 @@ public FilterModel(SmartHeader header, Lazy filter) public SmartHeader Header { get; } - private Lazy _filter; public GolombRiceFilter Filter => _filter.Value; // https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki diff --git a/WalletWasabi/WabiSabi/Backend/Models/WrongPhaseException.cs b/WalletWasabi/WabiSabi/Backend/Models/WrongPhaseException.cs index 97152f478ea..ee09c73f2fd 100644 --- a/WalletWasabi/WabiSabi/Backend/Models/WrongPhaseException.cs +++ b/WalletWasabi/WabiSabi/Backend/Models/WrongPhaseException.cs @@ -10,12 +10,6 @@ namespace WalletWasabi.WabiSabi.Backend.Models; public class WrongPhaseException : WabiSabiProtocolException { - public TimeSpan Late { get; } - public TimeSpan PhaseTimeout { get; } - public Phase CurrentPhase { get; } - public Phase[] ExpectedPhases { get; } - public uint256 RoundId { get; } - public WrongPhaseException(Round round, params Phase[] expectedPhases) : base(WabiSabiProtocolErrorCode.WrongPhase, $"Round ({round.Id}): Wrong phase ({round.Phase}).", exceptionData: new WrongPhaseExceptionData(round.Phase)) { @@ -48,4 +42,10 @@ public WrongPhaseException(Round round, params Phase[] expectedPhases) RoundId = round.Id; ExpectedPhases = expectedPhases; } + + public TimeSpan Late { get; } + public TimeSpan PhaseTimeout { get; } + public Phase CurrentPhase { get; } + public Phase[] ExpectedPhases { get; } + public uint256 RoundId { get; } } diff --git a/WalletWasabi/WabiSabi/Backend/Rounds/CoinJoinStorage/CoinJoinIdStore.cs b/WalletWasabi/WabiSabi/Backend/Rounds/CoinJoinStorage/CoinJoinIdStore.cs index eeb49b2f6e4..12889e2a034 100644 --- a/WalletWasabi/WabiSabi/Backend/Rounds/CoinJoinStorage/CoinJoinIdStore.cs +++ b/WalletWasabi/WabiSabi/Backend/Rounds/CoinJoinStorage/CoinJoinIdStore.cs @@ -9,9 +9,6 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds.CoinJoinStorage; public class CoinJoinIdStore : InMemoryCoinJoinIdStore { - private string CoinJoinIdStoreFilePath { get; set; } - private object FileWriteLock { get; set; } = new(); - // Only for testing purposes. internal CoinJoinIdStore() : this(Enumerable.Empty(), string.Empty) { @@ -22,6 +19,9 @@ public CoinJoinIdStore(IEnumerable coinjoinIds, string coinJoinIdStoreF CoinJoinIdStoreFilePath = coinJoinIdStoreFilePath; } + private string CoinJoinIdStoreFilePath { get; set; } + private object FileWriteLock { get; set; } = new(); + public override bool TryAdd(uint256 id) { if (base.TryAdd(id)) diff --git a/WalletWasabi/WabiSabi/Backend/Statistics/CoinJoinFeeRateStatStore.cs b/WalletWasabi/WabiSabi/Backend/Statistics/CoinJoinFeeRateStatStore.cs index 3b8d4903d85..4ce6507a928 100644 --- a/WalletWasabi/WabiSabi/Backend/Statistics/CoinJoinFeeRateStatStore.cs +++ b/WalletWasabi/WabiSabi/Backend/Statistics/CoinJoinFeeRateStatStore.cs @@ -27,6 +27,8 @@ public CoinJoinFeeRateStatStore(WabiSabiConfig config, IRPCClient rpc) { } + public event EventHandler? NewStat; + private static TimeSpan[] TimeFrames { get; } = Constants.CoinJoinFeeRateMedianTimeFrames.Select(tf => TimeSpan.FromHours(tf)).ToArray(); private static TimeSpan MaximumTimeToStore { get; } = TimeFrames.Max(); @@ -38,8 +40,6 @@ public CoinJoinFeeRateStatStore(WabiSabiConfig config, IRPCClient rpc) private WabiSabiConfig Config { get; } private IRPCClient Rpc { get; } - public event EventHandler? NewStat; - protected override async Task ActionAsync(CancellationToken cancel) { var feeRate = (await Rpc.EstimateSmartFeeAsync((int)Config.ConfirmationTarget, EstimateSmartFeeMode.Conservative, simulateIfRegTest: true, cancel).ConfigureAwait(false)).FeeRate;