Reduce property duplication.
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -511,7 +511,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
private void SetFeesAndTexts()
{
- AllFeeEstimate allFeeEstimate = Global.FeeProviders?.AllFeeEstimate;
+ AllFeeEstimate allFeeEstimate = Global.FeeProviders?.Status;
int feeTarget = -1; // 1 => 10 minutes
if (IsSliderFeeUsed)
@@ -687,7 +687,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
private void SetFeeTargetLimits()
{
- var allFeeEstimate = Global.FeeProviders?.AllFeeEstimate;
+ var allFeeEstimate = Global.FeeProviders?.Status;
if (allFeeEstimate != null)
{
@@ -1018,7 +1018,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
Disposables = Disposables is null ? new CompositeDisposable() : throw new NotSupportedException($"Cannot open {GetType().Name} before closing it.");
- Global.FeeProviders.WhenAnyValue(x => x.AllFeeEstimate).Subscribe(_ =>
+ Global.FeeProviders.WhenAnyValue(x => x.Status).Subscribe(_ =>
{
SetFeeTargetLimits();

MODIFY
WalletWasabi/Bases/PeriodicRunner.cs
WalletWasabi/Bases/PeriodicRunner.cs
@@ -14,7 +14,7 @@ namespace WalletWasabi.Bases
public T Status
{
get => _status;
- private set => RaiseAndSetIfChanged(ref _status, value);
+ protected set => RaiseAndSetIfChanged(ref _status, value);
}
private CancellationTokenSource Stop { get; set; }

MODIFY
WalletWasabi/BitcoinCore/Monitoring/RpcFeeProvider.cs
WalletWasabi/BitcoinCore/Monitoring/RpcFeeProvider.cs
@@ -13,14 +13,6 @@ namespace WalletWasabi.BitcoinCore.Monitoring
{
public class RpcFeeProvider : PeriodicRunner<AllFeeEstimate>, IFeeProvider
{
- private AllFeeEstimate _allFeeEstimate;
-
- public AllFeeEstimate AllFeeEstimate
- {
- get => _allFeeEstimate;
- private set => RaiseAndSetIfChanged(ref _allFeeEstimate, value);
- }
-
public RPCClient RpcClient { get; set; }
public RpcFeeProvider(TimeSpan period, RPCClient rpcClient) : base(period, null)
@@ -32,14 +24,11 @@ namespace WalletWasabi.BitcoinCore.Monitoring
{
try
{
- var afs = await RpcClient.EstimateAllFeeAsync(EstimateSmartFeeMode.Conservative, true, true).ConfigureAwait(false);
-
- AllFeeEstimate = afs;
- return afs;
+ return await RpcClient.EstimateAllFeeAsync(EstimateSmartFeeMode.Conservative, true, true).ConfigureAwait(false);
}
catch
{
- AllFeeEstimate = null;
+ Status = new AllFeeEstimate(Status, false);
throw;
}
}

MODIFY
WalletWasabi/BlockchainAnalysis/FeesEstimation/AllFeeEstimate.cs
WalletWasabi/BlockchainAnalysis/FeesEstimation/AllFeeEstimate.cs
@@ -13,22 +13,32 @@ namespace WalletWasabi.BlockchainAnalysis.FeesEstimation
public class AllFeeEstimate : IEquatable<AllFeeEstimate>
{
[JsonProperty]
- public EstimateSmartFeeMode Type { get; }
+ public EstimateSmartFeeMode Type { get; private set; }
/// <summary>
/// If it's been fetched from a fully synced node.
/// </summary>
[JsonProperty]
- public bool IsAccurate { get; }
+ public bool IsAccurate { get; private set; }
/// <summary>
/// int: fee target, decimal: satoshi/byte
/// </summary>
[JsonProperty]
- public Dictionary<int, int> Estimations { get; }
+ public Dictionary<int, int> Estimations { get; private set; }
[JsonConstructor]
public AllFeeEstimate(EstimateSmartFeeMode type, IDictionary<int, int> estimations, bool isAccurate)
+ {
+ Create(type, estimations, isAccurate);
+ }
+
+ public AllFeeEstimate(AllFeeEstimate other, bool isAccurate)
+ {
+ Create(other.Type, other.Estimations, isAccurate);
+ }
+
+ private void Create(EstimateSmartFeeMode type, IDictionary<int, int> estimations, bool isAccurate)
{
Type = type;
IsAccurate = isAccurate;
@@ -43,7 +53,6 @@ namespace WalletWasabi.BlockchainAnalysis.FeesEstimation
Estimations.TryAdd(estimation.Key, estimation.Value);
}
}
- _hashCode = null;
}
public FeeRate GetFeeRate(int feeTarget)
@@ -62,21 +71,16 @@ namespace WalletWasabi.BlockchainAnalysis.FeesEstimation
public bool Equals(AllFeeEstimate other) => this == other;
- private int? _hashCode;
-
public override int GetHashCode()
- {
- if (!_hashCode.HasValue)
{
int hash = Type.GetHashCode();
foreach (KeyValuePair<int, int> est in Estimations)
{
- hash = hash ^ est.Key.GetHashCode() ^ est.Value.GetHashCode();
- }
- _hashCode = hash;
+ hash ^= est.Key.GetHashCode() ^ est.Value.GetHashCode();
}
+ hash ^= IsAccurate.GetHashCode();
- return _hashCode.Value;
+ return hash;
}
public static bool operator ==(AllFeeEstimate x, AllFeeEstimate y)
@@ -96,6 +100,11 @@ namespace WalletWasabi.BlockchainAnalysis.FeesEstimation
return false;
}
+ if (x.IsAccurate != y.IsAccurate)
+ {
+ return false;
+ }
+
bool equal = false;
if (x.Estimations.Count == y.Estimations.Count) // Require equal count.
{

MODIFY
WalletWasabi/BlockchainAnalysis/FeesEstimation/FeeProviders.cs
WalletWasabi/BlockchainAnalysis/FeesEstimation/FeeProviders.cs
@@ -15,12 +15,12 @@ namespace WalletWasabi.BlockchainAnalysis.FeesEstimation
{
private IEnumerable<IFeeProvider> Providers { get; }
- private AllFeeEstimate _allFeeEstimate;
+ private AllFeeEstimate _status;
- public AllFeeEstimate AllFeeEstimate
+ public AllFeeEstimate Status
{
- get => _allFeeEstimate;
- private set => RaiseAndSetIfChanged(ref _allFeeEstimate, value);
+ get => _status;
+ private set => RaiseAndSetIfChanged(ref _status, value);
}
private object Lock { get; }
@@ -41,7 +41,7 @@ namespace WalletWasabi.BlockchainAnalysis.FeesEstimation
private void Provider_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
IFeeProvider feeProvider;
- if (e.PropertyName == nameof(feeProvider.AllFeeEstimate))
+ if (e.PropertyName == nameof(feeProvider.Status))
{
SetAllFeeEstimate();
}
@@ -55,15 +55,15 @@ namespace WalletWasabi.BlockchainAnalysis.FeesEstimation
for (int i = 0; i < providerArray.Length - 1; i++)
{
IFeeProvider provider = providerArray[i];
- var allFee = provider.AllFeeEstimate;
+ var allFee = provider.Status;
if (allFee != null && allFee.IsAccurate)
{
- AllFeeEstimate = allFee;
+ Status = allFee;
return;
}
}
- AllFeeEstimate = providerArray[providerArray.Length - 1].AllFeeEstimate;
+ Status = providerArray[providerArray.Length - 1].Status;
}
}

MODIFY
WalletWasabi/BlockchainAnalysis/FeesEstimation/IFeeProvider.cs
WalletWasabi/BlockchainAnalysis/FeesEstimation/IFeeProvider.cs
@@ -8,6 +8,6 @@ namespace WalletWasabi.BlockchainAnalysis.FeesEstimation
{
public interface IFeeProvider : INotifyPropertyChanged
{
- public AllFeeEstimate AllFeeEstimate { get; }
+ public AllFeeEstimate Status { get; }
}
}

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -740,7 +740,7 @@ namespace WalletWasabi.Services
{
if (feeStrategy.Type == FeeStrategyType.Target)
{
- return FeeProvider.AllFeeEstimate?.GetFeeRate(feeStrategy.Target) ?? throw new InvalidOperationException("Cannot get fee estimations.");
+ return FeeProvider.Status?.GetFeeRate(feeStrategy.Target) ?? throw new InvalidOperationException("Cannot get fee estimations.");
}
else if (feeStrategy.Type == FeeStrategyType.Rate)
{

MODIFY
WalletWasabi/Services/WasabiSynchronizer.cs
WalletWasabi/Services/WasabiSynchronizer.cs
@@ -45,12 +45,12 @@ namespace WalletWasabi.Services
private set => RaiseAndSetIfChanged(ref _usdExchangeRate, value);
}
- private AllFeeEstimate _allFeeEstimate;
+ private AllFeeEstimate _status;
- public AllFeeEstimate AllFeeEstimate
+ public AllFeeEstimate Status
{
- get => _allFeeEstimate;
- private set => RaiseAndSetIfChanged(ref _allFeeEstimate, value);
+ get => _status;
+ private set => RaiseAndSetIfChanged(ref _status, value);
}
private TorStatus _torStatus;
@@ -200,7 +200,7 @@ namespace WalletWasabi.Services
if (response.AllFeeEstimate != null && response.AllFeeEstimate.Estimations.Any())
{
lastFeeQueried = DateTimeOffset.UtcNow;
- AllFeeEstimate = response.AllFeeEstimate;
+ Status = response.AllFeeEstimate;
}
if (response.Filters.Count() == maxFiltersToSyncAtInitialization)

Reduce property duplication.