Remove label property of SmartCoin
MODIFY
WalletWasabi.Gui/Rpc/WasabiJsonRpcService.cs
WalletWasabi.Gui/Rpc/WasabiJsonRpcService.cs
@@ -39,7 +39,7 @@ namespace WalletWasabi.Gui.Rpc
anonymitySet = x.AnonymitySet,
confirmed = x.Confirmed,
confirmations = x.Confirmed ? serverTipHeight - (uint)x.Height.Value + 1 : 0,
- label = x.Label.ToString(),
+ label = x.HdPubKey.Label.ToString(),
keyPath = x.HdPubKey.FullKeyPath.ToString(),
address = x.HdPubKey.GetP2wpkhAddress(Global.Network).ToString()
}).ToArray();

MODIFY
WalletWasabi.Tests/Common.cs
WalletWasabi.Tests/Common.cs
using NBitcoin;
using System;
+using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using WalletWasabi.Blockchain.Analysis.Clustering;
@@ -30,7 +32,7 @@ namespace WalletWasabi.Tests
public static string DataDir => EnvironmentHelpers.GetDataDir(Path.Combine("WalletWasabi", "Tests"));
- public static SmartTransaction GetRandomSmartTransaction()
+ public static SmartTransaction RandomSmartTransaction()
{
var tx = Transaction.Create(Network.Main);
tx.Outputs.Add(Money.Coins(1), new Key());
@@ -38,16 +40,57 @@ namespace WalletWasabi.Tests
return stx;
}
- public static SmartCoin GetRandomSmartCoin(string label, HdPubKey pubKey, decimal amount, bool confirmed = true, int anonymitySet = 1)
+ public static SmartCoin RandomSmartCoin(HdPubKey pubKey, decimal amount, bool confirmed = true, int anonymitySet = 1)
{
var height = confirmed ? new Height(new Random().Next(0, 200)) : Height.Mempool;
- SmartLabel slabel = label;
- pubKey.SetLabel(slabel);
pubKey.SetKeyState(KeyState.Used);
var tx = Transaction.Create(Network.Main);
tx.Outputs.Add(new TxOut(Money.Coins(amount), pubKey.P2wpkhScript));
var stx = new SmartTransaction(tx, height);
- return new SmartCoin(stx, 0, pubKey, anonymitySet, slabel);
+ return new SmartCoin(stx, 0, pubKey, anonymitySet);
+ }
+
+ public static TransactionFactory CreateTransactionFactory(
+ IEnumerable<(string Label, int KeyIndex, decimal Amount, bool Confirmed, int AnonymitySet)> coins,
+ bool allowUnconfirmed = true,
+ bool watchOnly = false)
+ {
+ var (password, keyManager) = watchOnly ? RandomWatchOnlyKeyManager() : RandomKeyManager();
+
+ keyManager.AssertCleanKeysIndexed();
+
+ var coinArray = coins.ToArray();
+ var keys = keyManager.GetKeys().Take(coinArray.Length).ToArray();
+ for (int i = 0; i < coinArray.Length; i++)
+ {
+ var k = keys[i];
+ var c = coinArray[i];
+ k.SetLabel(c.Label);
+ }
+
+ var scoins = coins.Select(x => RandomSmartCoin(keys[x.KeyIndex], x.Amount, x.Confirmed, x.AnonymitySet)).ToArray();
+ foreach (var coin in scoins)
+ {
+ foreach (var sameLabelCoin in scoins.Where(c => !c.HdPubKey.Label.IsEmpty && c.HdPubKey.Label == coin.HdPubKey.Label))
+ {
+ sameLabelCoin.Cluster = coin.Cluster;
+ }
+ }
+ var coinsView = new CoinsView(scoins);
+ var transactionStore = new AllTransactionStoreMock(workFolderPath: ".", Network.Main);
+ return new TransactionFactory(Network.Main, keyManager, coinsView, transactionStore, password, allowUnconfirmed);
+ }
+
+ public static (string, KeyManager) RandomKeyManager()
+ {
+ var password = "blahblahblah";
+ return (password, KeyManager.CreateNew(out var _, password));
+ }
+
+ public static (string, KeyManager) RandomWatchOnlyKeyManager()
+ {
+ var (password, keyManager) = RandomKeyManager();
+ return (password, KeyManager.CreateNewWatchOnly(keyManager.ExtPubKey));
}
public static string GetWorkDir([CallerFilePath] string callerFilePath = "", [CallerMemberName] string callerMemberName = "")

MODIFY
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
@@ -264,7 +264,7 @@ namespace WalletWasabi.Tests.RegressionTests
ClientRoundRegistration first = null;
var randomKey = KeyManager.CreateNew(out _, "").GenerateNewKey(SmartLabel.Empty, KeyState.Clean, false);
var second = new ClientRoundRegistration(aliceClient,
- new[] { Tests.Common.GetRandomSmartCoin(SmartLabel.Empty, randomKey, 0m, false, 2) },
+ new[] { Tests.Common.RandomSmartCoin(randomKey, 0m, false, 2) },
BitcoinAddress.Create("12Rty3c8j3QiZSwLVaBtch6XUMZaja3RC7", Network.Main));
first = second;
second = null;
@@ -1470,7 +1470,7 @@ namespace WalletWasabi.Tests.RegressionTests
}
var times = 0;
- while (wallet.Coins.FirstOrDefault(x => x.Label.IsEmpty) is null)
+ while (wallet.Coins.FirstOrDefault(x => x.HdPubKey.Label.IsEmpty) is null)
{
await Task.Delay(1000);
times++;
@@ -1504,12 +1504,12 @@ namespace WalletWasabi.Tests.RegressionTests
var allCoins = wallet.TransactionProcessor.Coins.AsAllCoinsView().ToArray();
var allCoins2 = wallet2.TransactionProcessor.Coins.AsAllCoinsView().ToArray();
- Assert.Equal(4, allCoins.Count(x => x.Label.IsEmpty && x.IsAvailable()));
- Assert.Equal(3, allCoins2.Count(x => x.Label.IsEmpty && x.IsAvailable()));
- Assert.Equal(2, allCoins.Count(x => x.Label.IsEmpty && x.IsSpent()));
- Assert.Equal(0, allCoins2.Count(x => x.Label.IsEmpty && x.IsSpent()));
- Assert.Equal(3, allCoins2.Count(x => x.Label.IsEmpty));
- Assert.Equal(4, allCoins.Count(x => x.Label.IsEmpty && !x.IsSpent()));
+ Assert.Equal(4, allCoins.Count(x => x.HdPubKey.Label.IsEmpty && x.IsAvailable()));
+ Assert.Equal(3, allCoins2.Count(x => x.HdPubKey.Label.IsEmpty && x.IsAvailable()));
+ Assert.Equal(2, allCoins.Count(x => x.HdPubKey.Label.IsEmpty && x.IsSpent()));
+ Assert.Equal(0, allCoins2.Count(x => x.HdPubKey.Label.IsEmpty && x.IsSpent()));
+ Assert.Equal(3, allCoins2.Count(x => x.HdPubKey.Label.IsEmpty));
+ Assert.Equal(4, allCoins.Count(x => x.HdPubKey.Label.IsEmpty && !x.IsSpent()));
}
finally
{

MODIFY
WalletWasabi.Tests/RegressionTests/SendTests.cs
WalletWasabi.Tests/RegressionTests/SendTests.cs
@@ -374,7 +374,7 @@ namespace WalletWasabi.Tests.RegressionTests
res = wallet.BuildTransaction(password, new PaymentIntent(receive2, MoneyRequest.CreateAllRemaining(), "my label"), FeeStrategy.SevenDaysConfirmationTargetStrategy, allowUnconfirmed: true);
Assert.Single(res.InnerWalletOutputs);
- Assert.Equal("foo, my label", res.InnerWalletOutputs.Single().Label);
+ Assert.Equal("foo, my label", res.InnerWalletOutputs.Single().HdPubKey.Label);
amountToSend = wallet.Coins.Where(x => x.IsAvailable()).Sum(x => x.Amount) / 3;
res = wallet.BuildTransaction(
@@ -387,14 +387,14 @@ namespace WalletWasabi.Tests.RegressionTests
Assert.Single(res.InnerWalletOutputs);
Assert.Equal(2, res.OuterWalletOutputs.Count());
- IEnumerable<string> change = res.InnerWalletOutputs.Single().Label.Labels;
+ IEnumerable<string> change = res.InnerWalletOutputs.Single().HdPubKey.Label.Labels;
Assert.Contains("outgoing", change);
Assert.Contains("outgoing2", change);
await broadcaster.SendTransactionAsync(res.Transaction);
IEnumerable<SmartCoin> unconfirmedCoins = wallet.Coins.Where(x => x.Height == Height.Mempool).ToArray();
- IEnumerable<string> unconfirmedCoinLabels = unconfirmedCoins.SelectMany(x => x.Label.Labels).ToArray();
+ IEnumerable<string> unconfirmedCoinLabels = unconfirmedCoins.SelectMany(x => x.HdPubKey.Label.Labels).ToArray();
Assert.Contains("outgoing", unconfirmedCoinLabels);
Assert.Contains("outgoing2", unconfirmedCoinLabels);
IEnumerable<string> allKeyLabels = keyManager.GetKeys().SelectMany(x => x.Label.Labels);
@@ -406,7 +406,7 @@ namespace WalletWasabi.Tests.RegressionTests
await Common.WaitForFiltersToBeProcessedAsync(TimeSpan.FromSeconds(120), 1);
var bestHeight = new Height(bitcoinStore.SmartHeaderChain.TipHeight);
- IEnumerable<string> confirmedCoinLabels = wallet.Coins.Where(x => x.Height == bestHeight).SelectMany(x => x.Label.Labels);
+ IEnumerable<string> confirmedCoinLabels = wallet.Coins.Where(x => x.Height == bestHeight).SelectMany(x => x.HdPubKey.Label.Labels);
Assert.Contains("outgoing", confirmedCoinLabels);
Assert.Contains("outgoing2", confirmedCoinLabels);
allKeyLabels = keyManager.GetKeys().SelectMany(x => x.Label.Labels);
@@ -492,7 +492,7 @@ namespace WalletWasabi.Tests.RegressionTests
Assert.Single(res.InnerWalletOutputs);
SmartCoin changeRes = res.InnerWalletOutputs.Single();
Assert.Equal(newChangeK.P2wpkhScript, changeRes.ScriptPubKey);
- Assert.Equal(newChangeK.Label, changeRes.Label);
+ Assert.Equal(newChangeK.Label, changeRes.HdPubKey.Label);
Assert.Equal(KeyState.Clean, newChangeK.KeyState); // Still clean, because the tx wasn't yet propagated.
#endregion FeePcHigh

MODIFY
WalletWasabi.Tests/RegressionTests/WalletTests.cs
WalletWasabi.Tests/RegressionTests/WalletTests.cs
@@ -287,7 +287,7 @@ namespace WalletWasabi.Tests.RegressionTests
Assert.Equal(new Height((int)bitcoinStore.SmartHeaderChain.TipHeight), firstCoin.Height);
Assert.InRange(firstCoin.Index, 0U, 1U);
Assert.True(firstCoin.IsAvailable());
- Assert.Equal("foo label", firstCoin.Label);
+ Assert.Equal("foo label", firstCoin.HdPubKey.Label);
Assert.Equal(key.P2wpkhScript, firstCoin.ScriptPubKey);
Assert.Null(firstCoin.SpenderTransaction);
Assert.Equal(txId, firstCoin.TransactionId);
@@ -315,9 +315,9 @@ namespace WalletWasabi.Tests.RegressionTests
Assert.Equal(new Height(bitcoinStore.SmartHeaderChain.TipHeight).Value - 1, secondCoin.Height.Value);
Assert.Equal(new Height(bitcoinStore.SmartHeaderChain.TipHeight), thirdCoin.Height);
Assert.True(thirdCoin.IsAvailable());
- Assert.Equal("foo label", firstCoin.Label);
- Assert.Equal("bar label", secondCoin.Label);
- Assert.Equal("bar label", thirdCoin.Label);
+ Assert.Equal("foo label", firstCoin.HdPubKey.Label);
+ Assert.Equal("bar label", secondCoin.HdPubKey.Label);
+ Assert.Equal("bar label", thirdCoin.HdPubKey.Label);
Assert.Equal(key.P2wpkhScript, firstCoin.ScriptPubKey);
Assert.Equal(key2.P2wpkhScript, secondCoin.ScriptPubKey);
Assert.Equal(key2.P2wpkhScript, thirdCoin.ScriptPubKey);
@@ -365,7 +365,7 @@ namespace WalletWasabi.Tests.RegressionTests
Assert.Equal(Money.Coins(0.03m), rbfCoin.Amount);
Assert.Equal(new Height(bitcoinStore.SmartHeaderChain.TipHeight).Value - 2, rbfCoin.Height.Value);
Assert.True(rbfCoin.IsAvailable());
- Assert.Equal("bar label", rbfCoin.Label);
+ Assert.Equal("bar label", rbfCoin.HdPubKey.Label);
Assert.Equal(key2.P2wpkhScript, rbfCoin.ScriptPubKey);
Assert.Null(rbfCoin.SpenderTransaction);
Assert.Equal(tx4bumpRes.TransactionId, rbfCoin.TransactionId);

MODIFY
WalletWasabi.Tests/UnitTests/SmartCoinTests.cs
WalletWasabi.Tests/UnitTests/SmartCoinTests.cs
@@ -26,13 +26,13 @@ namespace WalletWasabi.Tests.UnitTests
var stx = new SmartTransaction(tx, height);
var label = "foo";
- var coin = new SmartCoin(stx, index, hdpk1, tx.GetAnonymitySet(index), label);
+ var coin = new SmartCoin(stx, index, hdpk1, tx.GetAnonymitySet(index));
// If the txId or the index differ, equality should think it's a different coin.
- var differentCoin = new SmartCoin(stx, index + 1, hdpk2, tx.GetAnonymitySet(index + 1), label);
+ var differentCoin = new SmartCoin(stx, index + 1, hdpk2, tx.GetAnonymitySet(index + 1));
// If the txId and the index are the same, equality should think it's the same coin.
- var sameCoin = new SmartCoin(stx, index, hdpk1, tx.GetAnonymitySet(index), "boo");
+ var sameCoin = new SmartCoin(stx, index, hdpk1, tx.GetAnonymitySet(index));
Assert.Equal(coin, sameCoin);
Assert.NotEqual(coin, differentCoin);

MODIFY
WalletWasabi.Tests/UnitTests/Transactions/AllTransactionStoreTests.cs
WalletWasabi.Tests/UnitTests/Transactions/AllTransactionStoreTests.cs
@@ -88,7 +88,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
Assert.Empty(txStore.ConfirmedStore.GetTransactions());
Assert.Empty(txStore.ConfirmedStore.GetTransactionHashes());
- uint256 txHash = Common.GetRandomSmartTransaction().GetHash();
+ uint256 txHash = Common.RandomSmartTransaction().GetHash();
Assert.False(txStore.Contains(txHash));
Assert.True(txStore.IsEmpty());
Assert.False(txStore.TryGetTransaction(txHash, out _));
@@ -147,7 +147,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
Assert.Equal(3, txStore.ConfirmedStore.GetTransactionHashes().Count());
Assert.False(txStore.IsEmpty());
- uint256 doesntContainTxHash = Common.GetRandomSmartTransaction().GetHash();
+ uint256 doesntContainTxHash = Common.RandomSmartTransaction().GetHash();
Assert.False(txStore.Contains(doesntContainTxHash));
Assert.False(txStore.TryGetTransaction(doesntContainTxHash, out _));
@@ -350,7 +350,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
var txStore = new AllTransactionStore(PrepareWorkDir(), network);
await txStore.InitializeAsync(ensureBackwardsCompatibility: false);
- var tx = Common.GetRandomSmartTransaction();
+ var tx = Common.RandomSmartTransaction();
Assert.False(txStore.TryUpdate(tx));
// Assert TryUpdate didn't modify anything.
@@ -364,7 +364,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
Assert.Empty(txStore.ConfirmedStore.GetTransactions());
Assert.Empty(txStore.ConfirmedStore.GetTransactionHashes());
- uint256 txHash = Common.GetRandomSmartTransaction().GetHash();
+ uint256 txHash = Common.RandomSmartTransaction().GetHash();
Assert.False(txStore.Contains(txHash));
Assert.True(txStore.IsEmpty());
Assert.False(txStore.TryGetTransaction(txHash, out _));

MODIFY
WalletWasabi.Tests/UnitTests/Transactions/OperationMergerTests.cs
WalletWasabi.Tests/UnitTests/Transactions/OperationMergerTests.cs
@@ -9,7 +9,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void CanMergeSingleOperations()
{
- var tx = Common.GetRandomSmartTransaction();
+ var tx = Common.RandomSmartTransaction();
var append = new Append(tx);
var unmergedAppendOperations = new[] { append };
@@ -39,14 +39,14 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void CanMergeComplexOperations()
{
- var tx1 = Common.GetRandomSmartTransaction();
- var tx2 = Common.GetRandomSmartTransaction();
- var tx3 = Common.GetRandomSmartTransaction();
- var tx4 = Common.GetRandomSmartTransaction();
- var tx5 = Common.GetRandomSmartTransaction();
- var tx6 = Common.GetRandomSmartTransaction();
- var tx7 = Common.GetRandomSmartTransaction();
- var tx8 = Common.GetRandomSmartTransaction();
+ var tx1 = Common.RandomSmartTransaction();
+ var tx2 = Common.RandomSmartTransaction();
+ var tx3 = Common.RandomSmartTransaction();
+ var tx4 = Common.RandomSmartTransaction();
+ var tx5 = Common.RandomSmartTransaction();
+ var tx6 = Common.RandomSmartTransaction();
+ var tx7 = Common.RandomSmartTransaction();
+ var tx8 = Common.RandomSmartTransaction();
var a1 = new Append(tx1, tx2);
var a2 = new Append(tx3, tx4, tx5);

MODIFY
WalletWasabi.Tests/UnitTests/Transactions/PayjoinTests.cs
WalletWasabi.Tests/UnitTests/Transactions/PayjoinTests.cs
@@ -21,18 +21,6 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
{
public class PayjoinTests
{
- private static (string, KeyManager) DefaultKeyManager()
- {
- var password = "blahblahblah";
- return (password, KeyManager.CreateNew(out var _, password));
- }
-
- private static (string, KeyManager) WatchOnlyKeyManager()
- {
- var (password, keyManager) = DefaultKeyManager();
- return (password, KeyManager.CreateNewWatchOnly(keyManager.ExtPubKey));
- }
-
public static PSBT GenerateRandomTransaction()
{
var key = new Key();
@@ -99,7 +87,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
OnSendAsync = PayjoinServerOk(psbt => psbt)
};
var payjoinClient = new PayjoinClient(httpClient);
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Pablo", 0, 0.1m, confirmed: true, anonymitySet: 1)
});
@@ -146,7 +134,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
})
};
var payjoinClient = new PayjoinClient(httpClient);
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Pablo", 0, 0.1m, confirmed: true, anonymitySet: 1)
});
@@ -166,7 +154,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
Assert.Equal(0.346m, outerOutput.Amount.ToUnit(MoneyUnit.BTC));
Assert.Equal(0.09899718m, innerOutput.Amount.ToUnit(MoneyUnit.BTC));
- transactionFactory = CreateTransactionFactory(
+ transactionFactory = Common.CreateTransactionFactory(
new[]
{
("Pablo", 0, 0.1m, confirmed: true, anonymitySet: 1)
@@ -206,7 +194,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
})
};
- var transactionFactory = CreateTransactionFactory(walletCoins);
+ var transactionFactory = Common.CreateTransactionFactory(walletCoins);
var tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
///////
@@ -253,7 +241,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
})
};
- var transactionFactory = CreateTransactionFactory(walletCoins);
+ var transactionFactory = Common.CreateTransactionFactory(walletCoins);
var tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
////////
@@ -400,7 +388,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
})
};
- var transactionFactory = CreateTransactionFactory(walletCoins);
+ var transactionFactory = Common.CreateTransactionFactory(walletCoins);
var tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
}
@@ -420,33 +408,9 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
OnSendAsync = PayjoinServerError(statusCode: HttpStatusCode.InternalServerError, "Internal Server Error")
};
- var transactionFactory = CreateTransactionFactory(walletCoins);
+ var transactionFactory = Common.CreateTransactionFactory(walletCoins);
var tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
}
-
- private TransactionFactory CreateTransactionFactory(
- IEnumerable<(string Label, int KeyIndex, decimal Amount, bool Confirmed, int AnonymitySet)> coins,
- bool allowUnconfirmed = true,
- bool watchOnly = false)
- {
- var (password, keyManager) = watchOnly ? WatchOnlyKeyManager() : DefaultKeyManager();
-
- keyManager.AssertCleanKeysIndexed();
-
- var keys = keyManager.GetKeys().Take(10).ToArray();
- var scoins = coins.Select(x => Common.GetRandomSmartCoin(x.Label, keys[x.KeyIndex], x.Amount, x.Confirmed, x.AnonymitySet)).ToArray();
- foreach (var coin in scoins)
- {
- foreach (var sameLabelCoin in scoins.Where(c => !c.Label.IsEmpty && c.Label == coin.Label))
- {
- sameLabelCoin.Cluster = coin.Cluster;
- }
- }
- var coinsView = new CoinsView(scoins);
- var transactionStore = new AllTransactionStoreMock(workFolderPath: ".", Network.Main);
-
- return new TransactionFactory(Network.Main, keyManager, coinsView, transactionStore, password, allowUnconfirmed);
- }
}
}

MODIFY
WalletWasabi.Tests/UnitTests/Transactions/TransactionFactoryTests.cs
WalletWasabi.Tests/UnitTests/Transactions/TransactionFactoryTests.cs
@@ -19,7 +19,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void InsufficientBalance()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Martin", 0, 0.01m, confirmed: true, anonymitySet: 1),
("Jean", 1, 0.02m, confirmed: true, anonymitySet: 1)
@@ -38,7 +38,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void TooMuchFeePaid()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Pablo", 0, 0.0001m, confirmed: true, anonymitySet: 1)
});
@@ -57,7 +57,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void SelectMostPrivateIndependentlyOfCluster()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("", 0, 0.08m, confirmed: true, anonymitySet: 50),
("", 1, 0.16m, confirmed: true, anonymitySet: 200)
@@ -79,13 +79,13 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
var changeCoin = Assert.Single(result.InnerWalletOutputs);
Assert.True(changeCoin.HdPubKey.IsInternal);
- Assert.Equal("Sophie", changeCoin.Label);
+ Assert.Equal("Sophie", changeCoin.HdPubKey.Label);
}
[Fact]
public void SelectMostPrivateCoin()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Maria", 0, 0.08m, confirmed: true, anonymitySet: 50),
("Joseph", 1, 0.16m, confirmed: true, anonymitySet: 200)
@@ -107,13 +107,13 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
var changeCoin = Assert.Single(result.InnerWalletOutputs);
Assert.True(changeCoin.HdPubKey.IsInternal);
- Assert.Equal("Joseph, Sophie", changeCoin.Label);
+ Assert.Equal("Joseph, Sophie", changeCoin.HdPubKey.Label);
}
[Fact]
public void SelectMostPrivateCoins()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Pablo", 0, 0.01m, confirmed: true, anonymitySet: 1),
("Jean", 1, 0.02m, confirmed: true, anonymitySet: 1),
@@ -144,7 +144,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void SelectSameScriptPubKeyCoins()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Pablo", 0, 0.01m, confirmed: false, anonymitySet: 10),
("Daniel", 1, 0.02m, confirmed: false, anonymitySet: 1),
@@ -163,7 +163,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
Assert.Equal(Money.Coins(0.14m), result.SpentCoins.Select(x => x.Amount).Sum());
var changeCoin = Assert.Single(result.InnerWalletOutputs);
- Assert.Equal("Daniel, Maria, Sophie", changeCoin.Label);
+ Assert.Equal("Daniel, Maria, Sophie", changeCoin.HdPubKey.Label);
var tx = result.Transaction.Transaction;
@@ -175,25 +175,25 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void SelectSameClusterCoins()
{
- var (password, keyManager) = DefaultKeyManager();
+ var (password, keyManager) = Common.RandomKeyManager();
keyManager.AssertCleanKeysIndexed();
- HdPubKey NewKey() => keyManager.GenerateNewKey("", KeyState.Used, true, false);
+ HdPubKey NewKey(string label) => keyManager.GenerateNewKey(label, KeyState.Used, true, false);
var scoins = new[]
{
- Common.GetRandomSmartCoin("Pablo", NewKey(), 0.9m),
- Common.GetRandomSmartCoin("Daniel", NewKey(), 0.9m),
- Common.GetRandomSmartCoin("Adolf", NewKey(), 0.9m),
- Common.GetRandomSmartCoin("Maria", NewKey(), 0.9m),
- Common.GetRandomSmartCoin("Ding", NewKey(), 0.9m),
- Common.GetRandomSmartCoin("Joseph", NewKey(), 0.9m),
- Common.GetRandomSmartCoin("Eve", NewKey(), 0.9m),
- Common.GetRandomSmartCoin("Julio", NewKey(), 0.9m),
- Common.GetRandomSmartCoin("Donald, Jean, Lee, Onur", NewKey(), 0.9m),
- Common.GetRandomSmartCoin("Satoshi", NewKey(), 0.9m)
+ Common.RandomSmartCoin(NewKey("Pablo"), 0.9m),
+ Common.RandomSmartCoin(NewKey("Daniel"), 0.9m),
+ Common.RandomSmartCoin(NewKey("Adolf"), 0.9m),
+ Common.RandomSmartCoin(NewKey("Maria"), 0.9m),
+ Common.RandomSmartCoin(NewKey("Ding"), 0.9m),
+ Common.RandomSmartCoin(NewKey("Joseph"), 0.9m),
+ Common.RandomSmartCoin(NewKey("Eve"), 0.9m),
+ Common.RandomSmartCoin(NewKey("Julio"), 0.9m),
+ Common.RandomSmartCoin(NewKey("Donald, Jean, Lee, Onur"), 0.9m),
+ Common.RandomSmartCoin(NewKey("Satoshi"), 0.9m)
};
- var coinsByLabel = scoins.ToDictionary(x => x.Label);
+ var coinsByLabel = scoins.ToDictionary(x => x.HdPubKey.Label);
// cluster 1 is known by 7 people: Pablo, Daniel, Adolf, Maria, Ding, Joseph and Eve
var coinsCluster1 = new[] { scoins[0], scoins[1], scoins[2], scoins[3], scoins[4], scoins[5], scoins[6] };
@@ -261,7 +261,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void CustomChangeScript()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Maria", 0, 1m, confirmed: true, anonymitySet: 100)
});
@@ -291,7 +291,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void SubtractFeeFromSpecificOutput()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Maria", 0, 1m, confirmed: true, anonymitySet: 100)
});
@@ -325,7 +325,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void SubtractFeeFromTooSmallOutput()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Maria", 0, 1m, confirmed: true, anonymitySet: 100)
});
@@ -348,7 +348,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void MultiplePaymentsToSameAddress()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Maria", 0, 1m, confirmed: true, anonymitySet: 100)
});
@@ -381,7 +381,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void SendAbsolutelyAllCoins()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Maria", 0, 0.5m, confirmed: false, anonymitySet: 1),
("Joseph", 1, 0.4m, confirmed: true, anonymitySet: 10),
@@ -407,7 +407,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void SpendOnlyAllowedCoins()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Pablo", 0, 0.01m, confirmed: false, anonymitySet: 50),
("Daniel", 1, 0.02m, confirmed: false, anonymitySet: 1),
@@ -421,8 +421,8 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
var coins = transactionFactory.Coins;
var allowedCoins = new[]
{
- coins.Single(x => x.Label == "Maria"),
- coins.Single(x => x.Label == "Suyin")
+ coins.Single(x => x.HdPubKey.Label == "Maria"),
+ coins.Single(x => x.HdPubKey.Label == "Suyin")
}.ToArray();
var result = transactionFactory.BuildTransaction(payment, feeRate, allowedCoins.Select(x => x.OutPoint));
@@ -436,7 +436,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void SpendWholeAllowedCoins()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Pablo", 0, 0.01m, confirmed: false, anonymitySet: 50),
("Daniel", 1, 0.02m, confirmed: false, anonymitySet: 1),
@@ -450,9 +450,9 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
var coins = transactionFactory.Coins;
var allowedCoins = new[]
{
- coins.Single(x => x.Label == "Pablo"),
- coins.Single(x => x.Label == "Maria"),
- coins.Single(x => x.Label == "Suyin")
+ coins.Single(x => x.HdPubKey.Label == "Pablo"),
+ coins.Single(x => x.HdPubKey.Label == "Maria"),
+ coins.Single(x => x.HdPubKey.Label == "Suyin")
}.ToArray();
var result = transactionFactory.BuildTransaction(payment, feeRate, allowedCoins.Select(x => x.OutPoint));
@@ -472,7 +472,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void InsufficientAllowedCoins()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Pablo", 0, 0.01m, confirmed: true, anonymitySet: 1),
("Jean", 1, 0.08m, confirmed: true, anonymitySet: 1)
@@ -480,7 +480,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
var allowedCoins = new[]
{
- transactionFactory.Coins.Single(x => x.Label == "Pablo")
+ transactionFactory.Coins.Single(x => x.HdPubKey.Label == "Pablo")
}.ToArray();
var amount = Money.Coins(0.5m); // it is not enough
@@ -496,7 +496,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void SpendWholeCoinsEvenWhenNotAllowed()
{
- var transactionFactory = CreateTransactionFactory(new[]
+ var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Pablo", 0, 0.01m, confirmed: false, anonymitySet: 50),
("Daniel", 1, 0.02m, confirmed: false, anonymitySet: 1),
@@ -522,7 +522,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
Assert.True(result.Signed);
Assert.Equal(Money.Coins(0.14m), result.SpentCoins.Select(x => x.Amount).Sum());
Assert.Equal(3, result.SpentCoins.Count());
- var danielCoin = coins.Where(x => x.Label == "Daniel").ToArray();
+ var danielCoin = coins.Where(x => x.HdPubKey.Label == "Daniel").ToArray();
Assert.Contains(danielCoin[0], result.SpentCoins);
Assert.Contains(danielCoin[1], result.SpentCoins);
}
@@ -530,7 +530,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public void DoNotSignWatchOnly()
{
- var transactionFactory = CreateTransactionFactory(
+ var transactionFactory = Common.CreateTransactionFactory(
new[]
{
("Pablo", 0, 1m, confirmed: true, anonymitySet: 1)
@@ -570,40 +570,5 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
var rest = dict.Where(x => x.Key < 0).Select(x => x.Value);
Assert.DoesNotContain(rest, x => x > samplingSize * 0.001);
}
-
- private static (string, KeyManager) DefaultKeyManager()
- {
- var password = "blahblahblah";
- return (password, KeyManager.CreateNew(out var _, password));
- }
-
- private static (string, KeyManager) WatchOnlyKeyManager()
- {
- var (password, keyManager) = DefaultKeyManager();
- return (password, KeyManager.CreateNewWatchOnly(keyManager.ExtPubKey));
- }
-
- private TransactionFactory CreateTransactionFactory(
- IEnumerable<(string Label, int KeyIndex, decimal Amount, bool Confirmed, int AnonymitySet)> coins,
- bool allowUnconfirmed = true,
- bool watchOnly = false)
- {
- var (password, keyManager) = watchOnly ? WatchOnlyKeyManager() : DefaultKeyManager();
-
- keyManager.AssertCleanKeysIndexed();
-
- var keys = keyManager.GetKeys().Take(10).ToArray();
- var scoins = coins.Select(x => Common.GetRandomSmartCoin(x.Label, keys[x.KeyIndex], x.Amount, x.Confirmed, x.AnonymitySet)).ToArray();
- foreach (var coin in scoins)
- {
- foreach (var sameLabelCoin in scoins.Where(c => !c.Label.IsEmpty && c.Label == coin.Label))
- {
- sameLabelCoin.Cluster = coin.Cluster;
- }
- }
- var coinsView = new CoinsView(scoins);
- var transactionStore = new AllTransactionStoreMock(workFolderPath: ".", Network.Main);
- return new TransactionFactory(Network.Main, keyManager, coinsView, transactionStore, password, allowUnconfirmed);
- }
}
}

MODIFY
WalletWasabi.Tests/UnitTests/Transactions/TransactionStoreTests.cs
WalletWasabi.Tests/UnitTests/Transactions/TransactionStoreTests.cs
@@ -34,7 +34,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
Assert.True(txStore.IsEmpty());
- var stx = Common.GetRandomSmartTransaction();
+ var stx = Common.RandomSmartTransaction();
var operation = txStore.TryAddOrUpdate(stx);
Assert.True(operation.isAdded);
Assert.False(operation.isUpdated);

MODIFY
WalletWasabi/Blockchain/Analysis/Clustering/Cluster.cs
WalletWasabi/Blockchain/Analysis/Clustering/Cluster.cs
@@ -20,7 +20,7 @@ namespace WalletWasabi.Blockchain.Analysis.Clustering
Lock = new object();
Coins = coins.ToList();
CoinsSet = Coins.ToHashSet();
- _labels = SmartLabel.Merge(Coins.Select(x => x.Label));
+ _labels = SmartLabel.Merge(Coins.Select(x => x.HdPubKey.Label));
}
public SmartLabel Labels
@@ -52,7 +52,7 @@ namespace WalletWasabi.Blockchain.Analysis.Clustering
}
if (insertPosition > 0) // at least one element was inserted
{
- Labels = SmartLabel.Merge(Coins.Select(x => x.Label));
+ Labels = SmartLabel.Merge(Coins.Select(x => x.HdPubKey.Label));
}
}
}

MODIFY
WalletWasabi/Blockchain/TransactionOutputs/SmartCoin.cs
WalletWasabi/Blockchain/TransactionOutputs/SmartCoin.cs
@@ -18,7 +18,6 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
#region Fields
private Height _height;
- private SmartLabel _label;
private int _anonymitySet;
private SmartTransaction? _spenderTransaction;
private bool _coinJoinInProgress;
@@ -36,7 +35,7 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
#region Constructors
- public SmartCoin(SmartTransaction transaction, uint outputIndex, HdPubKey pubKey, int anonymitySet, SmartLabel label = null, bool coinJoinInProgress = false, DateTimeOffset? bannedUntilUtc = null, bool spentAccordingToBackend = false)
+ public SmartCoin(SmartTransaction transaction, uint outputIndex, HdPubKey pubKey, int anonymitySet, bool coinJoinInProgress = false, DateTimeOffset? bannedUntilUtc = null, bool spentAccordingToBackend = false)
{
Transaction = transaction;
Coin = new Coin(transaction.Transaction, outputIndex);
@@ -51,8 +50,6 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
HdPubKey = pubKey;
- Label = SmartLabel.Merge(HdPubKey.Label, label);
-
Cluster = new Cluster(this);
SetIsBanned();
@@ -89,15 +86,6 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
}
}
- /// <summary>
- /// Always set it before the Amount!
- /// </summary>
- public SmartLabel Label
- {
- get => _label;
- set => RaiseAndSetIfChanged(ref _label, value);
- }
-
public bool WasReplaceable { get; }
public int AnonymitySet

MODIFY
WalletWasabi/Blockchain/TransactionProcessing/TransactionProcessor.cs
WalletWasabi/Blockchain/TransactionProcessing/TransactionProcessor.cs
@@ -201,7 +201,7 @@ namespace WalletWasabi.Blockchain.TransactionProcessing
anonset += spentOwnCoins.Min(x => x.AnonymitySet) - 1;
}
- SmartCoin newCoin = new SmartCoin(tx, i, foundKey, anonset, foundKey.Label, false); // Do not inherit locked status from key, that's different.
+ SmartCoin newCoin = new SmartCoin(tx, i, foundKey, anonset, false); // Do not inherit locked status from key, that's different.
result.ReceivedCoins.Add(newCoin);
// If we did not have it.

MODIFY
WalletWasabi/Blockchain/Transactions/TransactionFactory.cs
WalletWasabi/Blockchain/Transactions/TransactionFactory.cs
@@ -268,7 +268,7 @@ namespace WalletWasabi.Blockchain.Transactions
}
}
- var label = SmartLabel.Merge(payments.Requests.Select(x => x.Label).Concat(spentCoins.Select(x => x.Label)));
+ var label = SmartLabel.Merge(payments.Requests.Select(x => x.Label).Concat(spentCoins.Select(x => x.HdPubKey.Label)));
var outerWalletOutputs = new List<Coin>();
var innerWalletOutputs = new List<SmartCoin>();
var smartTransaction = new SmartTransaction(tx, Height.Unknown, label: SmartLabel.Merge(payments.Requests.Select(x => x.Label)));
@@ -280,7 +280,7 @@ namespace WalletWasabi.Blockchain.Transactions
{
var anonset = tx.GetAnonymitySet(i) + spentCoins.Min(x => x.AnonymitySet) - 1; // Minus 1, because count own only once.
var smartCoin = new SmartCoin(smartTransaction, i, foundKey, anonset);
- label = SmartLabel.Merge(label, smartCoin.Label); // foundKey's label is already added to the coinlabel.
+ label = SmartLabel.Merge(label, smartCoin.HdPubKey.Label); // foundKey's label is already added to the coinlabel.
innerWalletOutputs.Add(smartCoin);
}
else
@@ -295,16 +295,15 @@ namespace WalletWasabi.Blockchain.Transactions
var foundPaymentRequest = payments.Requests.FirstOrDefault(x => x.Destination.ScriptPubKey == coin.ScriptPubKey);
// If change then we concatenate all the labels.
+ // The foundkeylabel has already been added previously, so no need to concatenate.
if (foundPaymentRequest is null) // Then it's autochange.
{
- coin.Label = label;
+ coin.HdPubKey.SetLabel(label);
}
else
{
- coin.Label = SmartLabel.Merge(coin.Label, foundPaymentRequest.Label);
+ coin.HdPubKey.SetLabel(SmartLabel.Merge(coin.HdPubKey.Label, foundPaymentRequest.Label));
}
-
- coin.HdPubKey.SetLabel(coin.Label); // The foundkeylabel has already been added previously, so no need to concatenate.
}
Logger.LogInfo($"Transaction is successfully built: {tx.GetHash()}.");

Remove label property of SmartCoin