Prefer ushort to string
MODIFY
WalletWasabi.Gui/Tabs/AboutViewModel.cs
WalletWasabi.Gui/Tabs/AboutViewModel.cs
@@ -30,7 +30,7 @@ namespace WalletWasabi.Gui.Tabs
UpdateChecker = hostedServices.FirstOrDefault<UpdateChecker>();
- CurrentBackendMajorVersion = UpdateChecker?.UpdateStatus?.CurrentBackendApiVersion ?? "";
+ CurrentBackendMajorVersion = UpdateChecker?.UpdateStatus?.CurrentBackendMajorVersion.ToString() ?? "";
OpenBrowserCommand = ReactiveCommand.CreateFromTask<string>(IoHelpers.OpenBrowserAsync);
@@ -78,7 +78,7 @@ namespace WalletWasabi.Gui.Tabs
{
Observable.FromEventPattern<UpdateStatus>(updateChecker, nameof(updateChecker.UpdateStatusChanged))
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(e => CurrentBackendMajorVersion = e.EventArgs.CurrentBackendApiVersion)
+ .Subscribe(e => CurrentBackendMajorVersion = e.EventArgs.CurrentBackendMajorVersion.ToString())
.DisposeWith(disposables);
}
}

MODIFY
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
@@ -133,12 +133,12 @@ namespace WalletWasabi.Tests.IntegrationTests
var updateStatus = await client.CheckUpdatesAsync(CancellationToken.None);
var expectedVersion = new Version(2, 0);
- var backendVersion = "3";
+ ushort backendVersion = 3;
Assert.Equal(new UpdateStatus(true, true, expectedVersion, backendVersion), updateStatus);
Assert.True(updateStatus.BackendCompatible);
Assert.True(updateStatus.ClientUpToDate);
Assert.Equal(expectedVersion, updateStatus.LegalDocumentsVersion);
- Assert.Equal(backendVersion, updateStatus.CurrentBackendApiVersion);
+ Assert.Equal(backendVersion, updateStatus.CurrentBackendMajorVersion);
var versions = await client.GetVersionsAsync(CancellationToken.None);
Assert.Equal(versions.LegalDocumentsVersion, updateStatus.LegalDocumentsVersion);

MODIFY
WalletWasabi.Tests/UnitTests/Clients/WasabiClientTests.cs
WalletWasabi.Tests/UnitTests/Clients/WasabiClientTests.cs
@@ -95,24 +95,24 @@ namespace WalletWasabi.Tests.UnitTests.Clients
[Fact]
public void UpdateStatusEqualityTests()
{
- var u1 = new UpdateStatus(true, true, new Version(1, 0), "3");
- var u2 = new UpdateStatus(true, true, new Version(1, 0), "3");
+ var u1 = new UpdateStatus(true, true, new Version(1, 0), 3);
+ var u2 = new UpdateStatus(true, true, new Version(1, 0), 3);
Assert.Equal(u1, u2);
Assert.Equal(u1.GetHashCode(), u2.GetHashCode());
- var u3 = new UpdateStatus(false, true, new Version(1, 0), "3");
+ var u3 = new UpdateStatus(false, true, new Version(1, 0), 3);
Assert.NotEqual(u1, u3);
Assert.NotEqual(u1.GetHashCode(), u3.GetHashCode());
- var u4 = new UpdateStatus(true, false, new Version(1, 0), "3");
+ var u4 = new UpdateStatus(true, false, new Version(1, 0), 3);
Assert.NotEqual(u1, u4);
Assert.NotEqual(u1.GetHashCode(), u4.GetHashCode());
- var u5 = new UpdateStatus(true, true, new Version(1, 0, 1), "3");
+ var u5 = new UpdateStatus(true, true, new Version(1, 0, 1), 3);
Assert.NotEqual(u1, u5);
Assert.NotEqual(u1.GetHashCode(), u5.GetHashCode());
- var u6 = new UpdateStatus(true, true, new Version(1, 0), "4");
+ var u6 = new UpdateStatus(true, true, new Version(1, 0), 4);
Assert.NotEqual(u1, u6);
Assert.NotEqual(u1.GetHashCode(), u6.GetHashCode());
}

MODIFY
WalletWasabi.Tests/UnitTests/UpdateStatusTests.cs
WalletWasabi.Tests/UnitTests/UpdateStatusTests.cs
@@ -6,8 +6,6 @@ using Xunit;
namespace WalletWasabi.Tests.UnitTests
{
- // IDEAS
- // test currentbackendversion to only accept numbers
public class UpdateStatusTests
{
[Fact]
@@ -16,7 +14,7 @@ namespace WalletWasabi.Tests.UnitTests
var backendCompatible = false;
var clientUpToDate = false;
var legalVersion = new Version(1, 1);
- var backendVersion = "1";
+ ushort backendVersion = 1;
var x = new UpdateStatus(backendCompatible, clientUpToDate, legalVersion, backendVersion);
var y = new UpdateStatus(backendCompatible, clientUpToDate, legalVersion, backendVersion);
@@ -31,7 +29,7 @@ namespace WalletWasabi.Tests.UnitTests
y = new UpdateStatus(backendCompatible, clientUpToDate, new Version(2, 2), backendVersion);
Assert.NotEqual(x, y);
- y = new UpdateStatus(backendCompatible, clientUpToDate, legalVersion, "2");
+ y = new UpdateStatus(backendCompatible, clientUpToDate, legalVersion, 2);
Assert.NotEqual(x, y);
}
}

MODIFY
WalletWasabi/JsonConverters/RoundStateResponseJsonConverter.cs
WalletWasabi/JsonConverters/RoundStateResponseJsonConverter.cs
@@ -7,14 +7,14 @@ namespace WalletWasabi.JsonConverters
{
public class RoundStateResponseJsonConverter : JsonConverter
{
- public RoundStateResponseJsonConverter(string protocolVersion)
+ public RoundStateResponseJsonConverter(ushort protocolVersion)
{
ProtocolVersion = protocolVersion;
}
public override bool CanWrite => false;
- public string ProtocolVersion { get; }
+ public ushort ProtocolVersion { get; }
public override bool CanConvert(Type objectType) => typeof(RoundStateResponseBase) == objectType;
@@ -29,8 +29,8 @@ namespace WalletWasabi.JsonConverters
var type = ProtocolVersion switch
{
- "3" => typeof(RoundStateResponse),
- "4" => typeof(RoundStateResponse4),
+ 3 => typeof(RoundStateResponse),
+ 4 => typeof(RoundStateResponse4),
_ => throw new InvalidOperationException($"Cannot deserialize message for unknown protocol version: {ProtocolVersion}")
};

MODIFY
WalletWasabi/Models/UpdateStatus.cs
WalletWasabi/Models/UpdateStatus.cs
@@ -6,19 +6,19 @@ namespace WalletWasabi.Models
{
public class UpdateStatus : IEquatable<UpdateStatus>
{
- public UpdateStatus(bool backendCompatible, bool clientUpToDate, Version legalDocumentsVersion, string currentBackendApiVersion)
+ public UpdateStatus(bool backendCompatible, bool clientUpToDate, Version legalDocumentsVersion, ushort currentBackendMajorVersion)
{
BackendCompatible = backendCompatible;
ClientUpToDate = clientUpToDate;
LegalDocumentsVersion = legalDocumentsVersion;
- CurrentBackendApiVersion = currentBackendApiVersion;
+ CurrentBackendMajorVersion = currentBackendMajorVersion;
}
public bool ClientUpToDate { get; private set; }
public bool BackendCompatible { get; private set; }
public Version LegalDocumentsVersion { get; private set; }
- public string CurrentBackendApiVersion { get; private set; }
+ public ushort CurrentBackendMajorVersion { get; private set; }
#region EqualityAndComparison
@@ -26,10 +26,10 @@ namespace WalletWasabi.Models
public bool Equals(UpdateStatus other) => this == other;
- public override int GetHashCode() => (ClientUpToDate, BackendCompatible, LegalDocumentsVersion, CurrentBackendApiVersion).GetHashCode();
+ public override int GetHashCode() => (ClientUpToDate, BackendCompatible, LegalDocumentsVersion, CurrentBackendMajorVersion).GetHashCode();
public static bool operator ==(UpdateStatus x, UpdateStatus y)
- => (x?.ClientUpToDate, x?.BackendCompatible, x?.LegalDocumentsVersion, x?.CurrentBackendApiVersion) == (y?.ClientUpToDate, y?.BackendCompatible, y?.LegalDocumentsVersion, y?.CurrentBackendApiVersion);
+ => (x?.ClientUpToDate, x?.BackendCompatible, x?.LegalDocumentsVersion, x?.CurrentBackendMajorVersion) == (y?.ClientUpToDate, y?.BackendCompatible, y?.LegalDocumentsVersion, y?.CurrentBackendMajorVersion);
public static bool operator !=(UpdateStatus x, UpdateStatus y) => !(x == y);

MODIFY
WalletWasabi/Services/UpdateChecker.cs
WalletWasabi/Services/UpdateChecker.cs
@@ -19,7 +19,7 @@ namespace WalletWasabi.Services
{
Synchronizer = Guard.NotNull(nameof(synchronizer), synchronizer);
WasabiClient = synchronizer.WasabiClient;
- UpdateStatus = new UpdateStatus(true, true, new Version(), null);
+ UpdateStatus = new UpdateStatus(true, true, new Version(), 0);
Synchronizer.PropertyChanged += Synchronizer_PropertyChanged;
}

MODIFY
WalletWasabi/Wallets/Wallet.cs
WalletWasabi/Wallets/Wallet.cs
@@ -127,7 +127,7 @@ namespace WalletWasabi.Wallets
ServiceConfiguration = Guard.NotNull(nameof(serviceConfiguration), serviceConfiguration);
FeeProvider = Guard.NotNull(nameof(feeProvider), feeProvider);
- if (WasabiClient.ApiVersion == "3")
+ if (WasabiClient.ApiVersion == 3)
{
ChaumianClient = new CoinJoinClient(Synchronizer, Network, KeyManager);
}

MODIFY
WalletWasabi/WebClients/Wasabi/WasabiClient.cs
WalletWasabi/WebClients/Wasabi/WasabiClient.cs
@@ -38,7 +38,7 @@ namespace WalletWasabi.WebClients.Wasabi
public static Dictionary<uint256, Transaction> TransactionCache { get; } = new Dictionary<uint256, Transaction>();
private static Queue<uint256> TransactionIdQueue { get; } = new Queue<uint256>();
public static object TransactionCacheLock { get; } = new object();
- public static string ApiVersion { get; private set; } = Constants.BackendMajorVersion;
+ public static ushort ApiVersion { get; private set; } = ushort.Parse(Constants.BackendMajorVersion);
#region batch
@@ -238,7 +238,7 @@ namespace WalletWasabi.WebClients.Wasabi
#region software
- public async Task<(Version ClientVersion, int BackendMajorVersion, Version LegalDocumentsVersion)> GetVersionsAsync(CancellationToken cancel)
+ public async Task<(Version ClientVersion, ushort BackendMajorVersion, Version LegalDocumentsVersion)> GetVersionsAsync(CancellationToken cancel)
{
using var response = await TorClient.SendAndRetryAsync(HttpMethod.Get, HttpStatusCode.OK, "/api/software/versions", cancel: cancel);
@@ -250,7 +250,7 @@ namespace WalletWasabi.WebClients.Wasabi
using HttpContent content = response.Content;
var resp = await content.ReadAsJsonAsync<VersionsResponse>();
- return (Version.Parse(resp.ClientVersion), int.Parse(resp.BackendMajorVersion), Version.Parse(resp.LegalDocumentsVersion));
+ return (Version.Parse(resp.ClientVersion), ushort.Parse(resp.BackendMajorVersion), Version.Parse(resp.LegalDocumentsVersion));
}
public async Task<UpdateStatus> CheckUpdatesAsync(CancellationToken cancel)
@@ -258,15 +258,15 @@ namespace WalletWasabi.WebClients.Wasabi
var versions = await GetVersionsAsync(cancel);
var clientUpToDate = Constants.ClientVersion >= versions.ClientVersion; // If the client version locally is greater than or equal to the backend's reported client version, then good.
var backendCompatible = int.Parse(Constants.ClientSupportBackendVersionMax) >= versions.BackendMajorVersion && versions.BackendMajorVersion >= int.Parse(Constants.ClientSupportBackendVersionMin); // If ClientSupportBackendVersionMin <= backend major <= ClientSupportBackendVersionMax, then our software is compatible.
- var currentApiVersion = versions.BackendMajorVersion.ToString();
+ var currentBackendMajorVersion = versions.BackendMajorVersion;
if (backendCompatible)
{
// Only refresh if compatible.
- ApiVersion = currentApiVersion;
+ ApiVersion = currentBackendMajorVersion;
}
- return new UpdateStatus(backendCompatible, clientUpToDate, versions.LegalDocumentsVersion, currentApiVersion);
+ return new UpdateStatus(backendCompatible, clientUpToDate, versions.LegalDocumentsVersion, currentBackendMajorVersion);
}
#endregion software

Prefer ushort to string