Do not serialize redundant properties
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Models/SerializationTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Models/SerializationTests.cs
@@ -142,6 +142,23 @@ public class SerializationTests
AssertSerialization(RoundState.FromRound(round));
}
+ [Fact]
+ public void CoinSerialization()
+ {
+ var coin = new Coin(
+ new OutPoint(
+ uint256.One,
+ 1234),
+ new TxOut(
+ Money.Coins(1),
+ new Script("0 bf3593d140d512eb607b3ddb5c5ee085f1e3a210")));
+ AssertSerialization(coin);
+
+ var serializedCoin = JsonConvert.SerializeObject(coin, JsonSerializationOptions.Default.Settings);
+ var expectedJson = "{\"Outpoint\":\"0100000000000000000000000000000000000000000000000000000000000000D2040000\",\"TxOut\":{\"ScriptPubKey\":\"0 bf3593d140d512eb607b3ddb5c5ee085f1e3a210\",\"Value\":100000000}}";
+ Assert.Equal(expectedJson, serializedCoin);
+ }
+
private static void AssertSerialization<T>(T message)
{
var serializedMessage = JsonConvert.SerializeObject(message, JsonSerializationOptions.Default.Settings);

ADD
WalletWasabi/JsonConverters/Bitcoin/CoinJsonConverter.cs.cs
+using NBitcoin;
+using Newtonsoft.Json;
+
+namespace WalletWasabi.JsonConverters.Bitcoin;
+
+public class CoinJsonConverter : JsonConverter<Coin>
+{
+ /// <inheritdoc />
+ public override Coin? ReadJson(JsonReader reader, Type objectType, Coin? existingValue, bool hasExistingValue, JsonSerializer serializer)
+ {
+ var coin = serializer.Deserialize<SerializableCoin>(reader);
+ return new Coin(coin.Outpoint, coin.TxOut);
+ }
+
+ /// <inheritdoc />
+ public override void WriteJson(JsonWriter writer, Coin? coin, JsonSerializer serializer)
+ {
+ if (coin is null)
+ {
+ throw new ArgumentNullException(nameof(coin));
+ }
+
+ var newCoin = new SerializableCoin(coin.Outpoint, coin.TxOut);
+ serializer.Serialize(writer, newCoin);
+ }
+
+ private class SerializableCoin
+ {
+ [JsonConstructor]
+ public SerializableCoin(OutPoint outpoint, TxOut txOut)
+ {
+ Outpoint = outpoint;
+ TxOut = txOut;
+ }
+ public OutPoint Outpoint { get; }
+ public TxOut TxOut { get; }
+ }
+}

MODIFY
WalletWasabi/WabiSabi/Models/Serialization/JsonSerializationOptions.cs
WalletWasabi/WabiSabi/Models/Serialization/JsonSerializationOptions.cs
@@ -26,6 +26,7 @@ public class JsonSerializationOptions
new MultipartyTransactionStateJsonConverter(),
new ExtPubKeyJsonConverter(),
new TimeSpanJsonConverter(),
+ new CoinJsonConverter()
}
};
public static readonly JsonSerializationOptions Default = new();

Do not serialize redundant properties