Add bool update to smarttransaction
MODIFY
WalletWasabi.Tests/UnitTests/Transactions/TransactionStoreTests.cs
WalletWasabi.Tests/UnitTests/Transactions/TransactionStoreTests.cs
@@ -40,16 +40,35 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
Assert.True(txStore.IsEmpty());
var stx = Global.GenerateRandomSmartTransaction();
- var isAdded = txStore.TryAdd(stx);
- Assert.True(isAdded);
+ var operation = txStore.TryAdd(stx);
+ Assert.True(operation.isAdded);
+ Assert.False(operation.isUpdated);
var isRemoved = txStore.TryRemove(stx.GetHash(), out SmartTransaction removed);
Assert.True(isRemoved);
Assert.Equal(stx, removed);
- isAdded = txStore.TryAdd(stx);
- Assert.True(isAdded);
- isAdded = txStore.TryAdd(stx);
- Assert.False(isAdded);
- Assert.False(txStore.TryAdd(stx));
+ operation = txStore.TryAdd(stx);
+ Assert.True(operation.isAdded);
+ Assert.False(operation.isUpdated);
+ operation = txStore.TryAdd(stx);
+ Assert.False(operation.isAdded);
+ Assert.False(operation.isUpdated);
+
+ operation = txStore.TryAdd(
+ new SmartTransaction(
+ stx.Transaction,
+ height: stx.Height,
+ stx.BlockHash,
+ stx.BlockIndex,
+ new SmartLabel("totally random new label"),
+ stx.IsReplacement,
+ stx.FirstSeen));
+ Assert.False(operation.isAdded);
+ Assert.True(operation.isUpdated);
+
+ operation = txStore.TryAdd(stx);
+ Assert.False(operation.isAdded);
+ Assert.False(operation.isUpdated);
+
Assert.False(txStore.IsEmpty());
Assert.True(txStore.TryGetTransaction(stx.GetHash(), out SmartTransaction sameStx));
Assert.True(txStore.Contains(stx.GetHash()));

MODIFY
WalletWasabi/Transactions/TransactionStore.cs
WalletWasabi/Transactions/TransactionStore.cs
@@ -66,7 +66,7 @@ namespace WalletWasabi.Transactions
{
foreach (var tx in allTransactions)
{
- TryAddNoLockNoSerialization(tx);
+ TryAddOrUpdateNoLockNoSerialization(tx);
}
}
@@ -92,35 +92,41 @@ namespace WalletWasabi.Transactions
#region Modifiers
- public bool TryAdd(SmartTransaction tx)
+ public (bool isAdded, bool isUpdated) TryAdd(SmartTransaction tx)
{
- bool isAdded;
+ (bool isAdded, bool isUpdated) ret;
lock (TransactionsLock)
{
- isAdded = TryAddNoLockNoSerialization(tx);
+ ret = TryAddOrUpdateNoLockNoSerialization(tx);
}
- if (isAdded)
+ if (ret.isAdded)
{
_ = TryAppendToFileAsync(tx);
}
- return isAdded;
+ return ret;
}
- private bool TryAddNoLockNoSerialization(SmartTransaction tx)
+ private (bool isAdded, bool isUpdated) TryAddOrUpdateNoLockNoSerialization(SmartTransaction tx)
{
var hash = tx.GetHash();
if (Transactions.TryAdd(hash, tx))
{
- return true;
+ return (true, false);
}
else
{
- Transactions[hash].TryUpdate(tx);
- return false;
+ if (Transactions[hash].TryUpdate(tx))
+ {
+ return (false, true);
+ }
+ else
+ {
+ return (false, false);
+ }
}
}

Add bool update to smarttransaction