Fix `RoundState` serialization
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Models/SerializationTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Models/SerializationTests.cs
@@ -12,6 +12,7 @@ using WalletWasabi.Tests.Helpers;
using WalletWasabi.WabiSabi.Crypto;
using WalletWasabi.WabiSabi.Crypto.CredentialRequesting;
using WalletWasabi.WabiSabi.Models;
+using WalletWasabi.WabiSabi.Models.MultipartyTransaction;
using WalletWasabi.WabiSabi.Models.Serialization;
using Xunit;
@@ -151,6 +152,10 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Models
{
var round = WabiSabiFactory.CreateRound(new WalletWasabi.WabiSabi.Backend.WabiSabiConfig());
AssertSerialization(RoundState.FromRound(round));
+
+ var state = round.Assert<ConstructionState>();
+ round.CoinjoinState = new SigningState(state.Parameters, state.Inputs, state.Outputs);
+ AssertSerialization(RoundState.FromRound(round));
}
private static void AssertSerialization<T>(T message)

MODIFY
WalletWasabi/WabiSabi/Models/MultipartyTransaction/ConstructionState.cs
WalletWasabi/WabiSabi/Models/MultipartyTransaction/ConstructionState.cs
@@ -109,7 +109,7 @@ namespace WalletWasabi.WabiSabi.Models.MultipartyTransaction
throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.InsufficientFees);
}
- return new SigningState(this);
+ return new SigningState(Parameters, Inputs, Outputs);
}
}
}

MODIFY
WalletWasabi/WabiSabi/Models/MultipartyTransaction/SigningState.cs
WalletWasabi/WabiSabi/Models/MultipartyTransaction/SigningState.cs
using NBitcoin;
+using Newtonsoft.Json;
+using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
@@ -8,17 +10,18 @@ namespace WalletWasabi.WabiSabi.Models.MultipartyTransaction
{
public record SigningState : MultipartyTransactionState
{
- public SigningState(ConstructionState state)
- : base(state.Parameters)
+ public SigningState(MultipartyTransactionParameters parameters, IEnumerable<Coin> inputs, IEnumerable<TxOut> outputs)
+ : base(parameters)
{
- Inputs = state.Inputs;
- Outputs = state.Outputs;
+ Inputs = inputs.ToImmutableList();
+ Outputs = outputs.ToImmutableList();
}
public ImmutableDictionary<int, WitScript> Witnesses { get; init; } = ImmutableDictionary<int, WitScript>.Empty;
public bool IsFullySigned => Witnesses.Count == Inputs.Count;
+ [JsonIgnore]
public IEnumerable<Coin> UnsignedInputs => Inputs.Where((_, i) => !IsInputSigned(i));
public bool IsInputSigned(int index) => Witnesses.ContainsKey(index);

MODIFY
WalletWasabi/WabiSabi/Models/RoundState.cs
WalletWasabi/WabiSabi/Models/RoundState.cs
+using System;
using NBitcoin;
using WalletWasabi.Crypto;
using WalletWasabi.WabiSabi.Backend.Rounds;
@@ -10,9 +11,17 @@ namespace WalletWasabi.WabiSabi.Models
CredentialIssuerParameters AmountCredentialIssuerParameters,
CredentialIssuerParameters VsizeCredentialIssuerParameters,
FeeRate FeeRate,
+ Phase Phase,
MultipartyTransactionState CoinjoinState)
{
public static RoundState FromRound(Round round) =>
- new RoundState(round.Id, round.AmountCredentialIssuerParameters, round.VsizeCredentialIssuerParameters, round.FeeRate, round.CoinjoinState);
+ new RoundState(round.Id, round.AmountCredentialIssuerParameters, round.VsizeCredentialIssuerParameters, round.FeeRate, round.Phase, round.CoinjoinState);
+
+ public TState Assert<TState>() where TState : MultipartyTransactionState =>
+ CoinjoinState switch
+ {
+ TState s => s,
+ _ => throw new InvalidOperationException($"{typeof(TState).Name} state was expected but {CoinjoinState.GetType().Name} state was received.")
+ };
}
}

Fix `RoundState` serialization