Use Label type for SmartTransaction
MODIFY
WalletWasabi.Tests/UnitTests/SmartTransactionTests.cs
WalletWasabi.Tests/UnitTests/SmartTransactionTests.cs
@@ -43,7 +43,7 @@ namespace WalletWasabi.Tests.UnitTests
var tx3 = Transaction.Parse("02000000040aa8d0af84518df6e3a60c5bb19d9c3fcc3dc6e26b2f2449e8d7bf8d3fe84b87010000006a473044022018dfe9216c1209dd6c2b6c1607dbac4e499c1fce4878bc7d5d83fccbf3e24c9402202cac351c9c6a2b5eef338cbf0ec000d8de1c05e96a904cbba2b9e6ffc2d4e19501210364cc39da1091b1a9c12ec905a14a9e8478f951f7a1accdabeb40180533f2eaa5feffffff112c07d0f5e0617d720534f0b2b84dc0d5b7314b358c3ab338823b9e5bfbddf5010000006b483045022100ec155e7141e74661ee511ae980150a6c89261f31070999858738369afc28f2b6022006230d2aa24fac110b74ef15b84371486cf76c539b335a253c14462447912a300121020c2f41390f031d471b22abdb856e6cdbe0f4d74e72c197469bfd54e5a08f7e67feffffff38e799b8f6cf04fd021a9b135cdcd347da7aac4fd8bb8d0da9316a9fb228bb6e000000006b483045022100fc1944544a3f96edd8c8a9795c691e2725612b5ab2e1c999be11a2a4e3f841f1022077b2e088877829edeada0c707a9bb577aa79f26dafacba3d1d2d047f52524296012102e6015963dff9826836400cf8f45597c0705757d5dcdc6bf734f661c7dab89e69feffffff64c3f0377e86625123f2f1ee229319ed238e8ca8b7dda5bc080a2c5ecb984629000000006a47304402204233a90d6296182914424fd2901e16e6f5b13b451b67b0eec25a5eaacc5033c902203d8a13ef0b494c12009663475458e51da6bd55cc67688264230ece81d3eeca24012102f806d7152da2b52c1d9ad928e4a6253ccba080a5b9ab9efdd80e37274ac67f9bfeffffff0290406900000000001976a91491ac4e49b66f845180d98d8f8be6121588be6e3b88ac52371600000000001976a9142f44ed6749e8c84fd476e4440741f7e6f55542fa88acadd30700", Network.RegTest);
var height = Height.Mempool;
- string label = "foo";
+ var label = new Label("foo");
var smartTx = new SmartTransaction(tx, height, label: label);
var smartTx2 = new SmartTransaction(tx2, height);
var smartTx3 = new SmartTransaction(tx3, height);
@@ -71,7 +71,7 @@ namespace WalletWasabi.Tests.UnitTests
var serializedWithoutLabel = "{\"Transaction\":\"02000000040aa8d0af84518df6e3a60c5bb19d9c3fcc3dc6e26b2f2449e8d7bf8d3fe84b87010000006a473044022018dfe9216c1209dd6c2b6c1607dbac4e499c1fce4878bc7d5d83fccbf3e24c9402202cac351c9c6a2b5eef338cbf0ec000d8de1c05e96a904cbba2b9e6ffc2d4e19501210364cc39da1091b1a9c12ec905a14a9e8478f951f7a1accdabeb40180533f2eaa5feffffff112c07d0f5e0617d720534f0b2b84dc0d5b7314b358c3ab338823b9e5bfbddf5010000006b483045022100ec155e7141e74661ee511ae980150a6c89261f31070999858738369afc28f2b6022006230d2aa24fac110b74ef15b84371486cf76c539b335a253c14462447912a300121020c2f41390f031d471b22abdb856e6cdbe0f4d74e72c197469bfd54e5a08f7e67feffffff38e799b8f6cf04fd021a9b135cdcd347da7aac4fd8bb8d0da9316a9fb228bb6e000000006b483045022100fc1944544a3f96edd8c8a9795c691e2725612b5ab2e1c999be11a2a4e3f841f1022077b2e088877829edeada0c707a9bb577aa79f26dafacba3d1d2d047f52524296012102e6015963dff9826836400cf8f45597c0705757d5dcdc6bf734f661c7dab89e69feffffff64c3f0377e86625123f2f1ee229319ed238e8ca8b7dda5bc080a2c5ecb984629000000006a47304402204233a90d6296182914424fd2901e16e6f5b13b451b67b0eec25a5eaacc5033c902203d8a13ef0b494c12009663475458e51da6bd55cc67688264230ece81d3eeca24012102f806d7152da2b52c1d9ad928e4a6253ccba080a5b9ab9efdd80e37274ac67f9bfeffffff0290406900000000001976a91491ac4e49b66f845180d98d8f8be6121588be6e3b88ac52371600000000001976a9142f44ed6749e8c84fd476e4440741f7e6f55542fa88acadd30700\",\"Height\":\"2147483646\"}";
var deserializedWithoutLabel = JsonConvert.DeserializeObject<SmartTransaction>(serializedWithoutLabel);
- Assert.Empty(deserializedWithoutLabel.Label);
+ Assert.True(deserializedWithoutLabel.Label.IsEmpty);
}
}
}

MODIFY
WalletWasabi/Extensions/NBitcoinExtensions.cs
WalletWasabi/Extensions/NBitcoinExtensions.cs
@@ -253,7 +253,7 @@ namespace NBitcoin
return psbt.ExtractSmartTransaction(Height.Unknown);
}
- public static SmartTransaction ExtractSmartTransaction(this PSBT psbt, Height height, uint256 blockHash = null, int blockIndex = 0, string label = "", DateTimeOffset? firstSeenIfMempoolTime = null, bool isReplacement = false)
+ public static SmartTransaction ExtractSmartTransaction(this PSBT psbt, Height height, uint256 blockHash = null, int blockIndex = 0, Label label = null, DateTimeOffset? firstSeenIfMempoolTime = null, bool isReplacement = false)
{
var extractedTx = psbt.ExtractTransaction();
return new SmartTransaction(extractedTx, height, blockHash, blockIndex, label, firstSeenIfMempoolTime, isReplacement);

ADD
WalletWasabi/JsonConverters/LabelJsonConverter.cs
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using WalletWasabi.Models;
+
+namespace WalletWasabi.JsonConverters
+{
+ public class LabelJsonConverter : JsonConverter
+ {
+ public override bool CanConvert(Type objectType)
+ {
+ return objectType == typeof(Label);
+ }
+
+ /// <inheritdoc />
+ public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+ {
+ var s = reader.Value as string;
+ return new Label(s);
+ }
+
+ /// <inheritdoc />
+ public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+ {
+ var label = value as Label;
+ writer.WriteValue(label?.ToString() ?? "");
+ }
+ }
+}

MODIFY
WalletWasabi/Models/SmartTransaction.cs
WalletWasabi/Models/SmartTransaction.cs
@@ -28,7 +28,8 @@ namespace WalletWasabi.Models
public int BlockIndex { get; private set; }
[JsonProperty]
- public string Label { get; set; }
+ [JsonConverter(typeof(LabelJsonConverter))]
+ public Label Label { get; set; }
public bool Confirmed => Height.Type == HeightType.Chain;
@@ -60,10 +61,10 @@ namespace WalletWasabi.Models
#region Constructors
[JsonConstructor]
- public SmartTransaction(Transaction transaction, Height height, uint256 blockHash = null, int blockIndex = 0, string label = "", DateTimeOffset? firstSeenIfMempoolTime = null, bool isReplacement = false)
+ public SmartTransaction(Transaction transaction, Height height, uint256 blockHash = null, int blockIndex = 0, Label label = null, DateTimeOffset? firstSeenIfMempoolTime = null, bool isReplacement = false)
{
Transaction = transaction;
- Label = Guard.Correct(label);
+ Label = label ?? Label.Empty;
SetHeight(height, blockHash, blockIndex);
if (firstSeenIfMempoolTime != null)
@@ -96,8 +97,6 @@ namespace WalletWasabi.Models
IsReplacement = true;
}
- public bool HasLabel() => !string.IsNullOrWhiteSpace(Label);
-
/// <summary>
/// First looks at height, then block index, then mempool firstseen.
/// </summary>

Use Label type for SmartTransaction