Make sure only existing things modify keys
MODIFY
WalletWasabi/Blockchain/TransactionOutputs/CoinsRegistry.cs
WalletWasabi/Blockchain/TransactionOutputs/CoinsRegistry.cs
@@ -84,6 +84,7 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
if (!SpentCoins.Contains(coin))
{
added = Coins.Add(coin);
+ coin.RegisterToHdPubKey();
if (added)
{
if (ClustersByScriptPubKey.TryGetValue(coin.ScriptPubKey, out var cluster))
@@ -141,6 +142,7 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
{
SpentCoins.Remove(toRemove);
}
+ toRemove.UnregisterFromHdPubKey();
var removedCoinOutPoint = toRemove.OutPoint;

MODIFY
WalletWasabi/Blockchain/TransactionOutputs/SmartCoin.cs
WalletWasabi/Blockchain/TransactionOutputs/SmartCoin.cs
@@ -54,7 +54,6 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
_cluster = new Cluster(this);
- HdPubKey.Coins.Add(this);
Transaction.WalletOutputs.Add(this);
}
@@ -99,6 +98,12 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
}
}
+ public bool RegisterToHdPubKey()
+ => HdPubKey.Coins.Add(this);
+
+ public bool UnregisterFromHdPubKey()
+ => HdPubKey.Coins.Remove(this);
+
public bool CoinJoinInProgress
{
get => _coinJoinInProgress;

Make sure only existing things modify keys