Use asp.net serializer
MODIFY
WalletWasabi.Backend/Filters/ExceptionTranslateFilter.cs
WalletWasabi.Backend/Filters/ExceptionTranslateFilter.cs
@@ -21,7 +21,7 @@ public class ExceptionTranslateAttribute : ExceptionFilterAttribute
Type: ProtocolConstants.ProtocolViolationType,
ErrorCode: e.ErrorCode.ToString(),
Description: e.Message,
- Data: JsonConvert.SerializeObject(e.ExceptionData, Formatting.None)))
+ ExceptionData: e.ExceptionData))
{
StatusCode = (int)HttpStatusCode.InternalServerError
},
@@ -29,7 +29,7 @@ public class ExceptionTranslateAttribute : ExceptionFilterAttribute
Type: ProtocolConstants.ProtocolViolationType,
ErrorCode: WabiSabiProtocolErrorCode.CryptoException.ToString(),
Description: e.Message,
- Data: string.Empty))
+ ExceptionData: null))
{
StatusCode = (int)HttpStatusCode.InternalServerError
},

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/RegisterInputFailureTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/RegisterInputFailureTests.cs
@@ -131,6 +131,34 @@ public class RegisterInputFailureTests
async () => await arenaClient.RegisterInputAsync(round.Id, outpoint, ownershipProof, CancellationToken.None));
Assert.Equal(WabiSabiProtocolErrorCode.InputBanned, ex.ErrorCode);
+ Assert.IsAssignableFrom<InputBannedExceptionData>(ex.ExceptionData);
+
+ await arena.StopAsync(CancellationToken.None);
+ }
+
+ [Fact]
+ public async Task InputLongBannedAsync()
+ {
+ using Key key = new();
+ var outpoint = BitcoinFactory.CreateOutPoint();
+
+ WabiSabiConfig cfg = new();
+ var round = WabiSabiFactory.CreateRound(cfg);
+
+ Prison prison = new();
+ using Arena arena = await ArenaBuilder.From(cfg, prison).CreateAndStartAsync(round);
+
+ prison.Punish(outpoint, Punishment.LongBanned, uint256.One);
+
+ var ownershipProof = WabiSabiFactory.CreateOwnershipProof(key);
+
+ var arenaClient = WabiSabiFactory.CreateArenaClient(arena);
+
+ var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(
+ async () => await arenaClient.RegisterInputAsync(round.Id, outpoint, ownershipProof, CancellationToken.None));
+
+ Assert.Equal(WabiSabiProtocolErrorCode.InputLongBanned, ex.ErrorCode);
+ Assert.IsAssignableFrom<InputBannedExceptionData>(ex.ExceptionData);
await arena.StopAsync(CancellationToken.None);
}

MODIFY
WalletWasabi/Tor/Http/Extensions/HttpResponseMessageExtensions.cs
WalletWasabi/Tor/Http/Extensions/HttpResponseMessageExtensions.cs
@@ -72,7 +72,7 @@ public static class HttpResponseMessageExtensions
var innerException = error switch
{
{ Type: ProtocolConstants.ProtocolViolationType } => Enum.TryParse<WabiSabiProtocolErrorCode>(error.ErrorCode, out var code)
- ? new WabiSabiProtocolException(code, error.Description, exceptionData: GetExceptionData(code, error.Data))
+ ? new WabiSabiProtocolException(code, error.Description, exceptionData: error.ExceptionData)
: new NotSupportedException($"Received WabiSabi protocol exception with unknown '{error.ErrorCode}' error code.\n\tDescription: '{error.Description}'."),
{ Type: "unknown" } => new Exception(error.Description),
_ => null
@@ -97,14 +97,4 @@ public static class HttpResponseMessageExtensions
throw new HttpRequestException($"{me.StatusCode.ToReasonString()}{errorMessage}");
}
-
- private static ExceptionData? GetExceptionData(WabiSabiProtocolErrorCode errorCode, string data)
- {
- return errorCode switch
- {
- WabiSabiProtocolErrorCode.InputBanned or WabiSabiProtocolErrorCode.InputLongBanned => JsonConvert.DeserializeObject<InputBannedExceptionData>(data),
- _ => null
- };
-
- }
}

MODIFY
WalletWasabi/WabiSabi/Backend/Models/InputBannedExceptionData.cs
WalletWasabi/WabiSabi/Backend/Models/InputBannedExceptionData.cs
@@ -2,4 +2,4 @@ using Newtonsoft.Json;
namespace WalletWasabi.WabiSabi.Backend.Models;
-public record InputBannedExceptionData([JsonProperty(PropertyName = "BannedUntil")] DateTimeOffset BannedUntil) : ExceptionData;
+public record InputBannedExceptionData(DateTimeOffset BannedUntil) : ExceptionData;

MODIFY
WalletWasabi/WabiSabi/Models/Error.cs
WalletWasabi/WabiSabi/Models/Error.cs
+using WalletWasabi.WabiSabi.Backend.Models;
+
namespace WalletWasabi.WabiSabi.Models;
public record Error(
string Type,
string ErrorCode,
string Description,
- string Data
+ ExceptionData? ExceptionData
);

Use asp.net serializer