Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Trivial] Order elements (CodeFactor) #8657

Merged
merged 1 commit into from Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions WalletWasabi.Fluent/Helpers/TimeSpanFormatter.cs
Expand Up @@ -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}");
}

Expand Down Expand Up @@ -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; }
}
}
}
Expand Up @@ -18,7 +18,6 @@ public partial class ShowQrCameraDialogViewModel : DialogViewModelBase<string?>
[AutoNotify] private Bitmap? _qrImage;
[AutoNotify] private string _message = "";

private CancellationTokenSource CancellationTokenSource { get; } = new();
private WebcamQrReader _qrReader;

public ShowQrCameraDialogViewModel(Network network)
Expand All @@ -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);
Expand Down
40 changes: 25 additions & 15 deletions WalletWasabi.Tests/UnitTests/Wallet/SmartCoinSelectorTests.cs
Expand Up @@ -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()
{
Expand All @@ -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);
Expand All @@ -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));

Expand All @@ -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));

Expand All @@ -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))
Expand All @@ -113,15 +121,17 @@ 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<Coin>(), Money.Coins(0.3m)).Cast<Coin>().ToList();

Assert.Equal(2, coinsToSpend.Count);
Assert.Equal(0.4m, coinsToSpend.Sum(x => x.Amount.ToUnit(MoneyUnit.BTC)));
}
}
}
3 changes: 2 additions & 1 deletion WalletWasabi/Backend/Models/FilterModel.cs
Expand Up @@ -8,6 +8,8 @@ namespace WalletWasabi.Backend.Models;

public class FilterModel
{
private Lazy<GolombRiceFilter> _filter;

public FilterModel(SmartHeader header, GolombRiceFilter filter)
{
Header = header;
Expand All @@ -22,7 +24,6 @@ public FilterModel(SmartHeader header, Lazy<GolombRiceFilter> filter)

public SmartHeader Header { get; }

private Lazy<GolombRiceFilter> _filter;
public GolombRiceFilter Filter => _filter.Value;

// https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki
Expand Down
12 changes: 6 additions & 6 deletions WalletWasabi/WabiSabi/Backend/Models/WrongPhaseException.cs
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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; }
}
Expand Up @@ -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<uint256>(), string.Empty)
{
Expand All @@ -22,6 +19,9 @@ public CoinJoinIdStore(IEnumerable<uint256> 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))
Expand Down
Expand Up @@ -27,6 +27,8 @@ public CoinJoinFeeRateStatStore(WabiSabiConfig config, IRPCClient rpc)
{
}

public event EventHandler<CoinJoinFeeRateStat>? NewStat;

private static TimeSpan[] TimeFrames { get; } = Constants.CoinJoinFeeRateMedianTimeFrames.Select(tf => TimeSpan.FromHours(tf)).ToArray();

private static TimeSpan MaximumTimeToStore { get; } = TimeFrames.Max();
Expand All @@ -38,8 +40,6 @@ public CoinJoinFeeRateStatStore(WabiSabiConfig config, IRPCClient rpc)
private WabiSabiConfig Config { get; }
private IRPCClient Rpc { get; }

public event EventHandler<CoinJoinFeeRateStat>? NewStat;

protected override async Task ActionAsync(CancellationToken cancel)
{
var feeRate = (await Rpc.EstimateSmartFeeAsync((int)Config.ConfirmationTarget, EstimateSmartFeeMode.Conservative, simulateIfRegTest: true, cancel).ConfigureAwait(false)).FeeRate;
Expand Down