Implement updateoperations
MODIFY
WalletWasabi.Tests/UnitTests/Transactions/AllTransactionStoreTests.cs
WalletWasabi.Tests/UnitTests/Transactions/AllTransactionStoreTests.cs
@@ -294,7 +294,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
await txStore.InitializeAsync(PrepareWorkDir(), network, ensureBackwardsCompatibility: false);
var tx = Global.GenerateRandomSmartTransaction();
- Assert.False(txStore.TryUpdate(tx, out _));
+ Assert.False(txStore.TryUpdate(tx));
// Assert TryUpdate didn't modify anything.

MODIFY
WalletWasabi/Models/SmartTransaction.cs
WalletWasabi/Models/SmartTransaction.cs
@@ -111,13 +111,10 @@ namespace WalletWasabi.Models
Height = tx.Height;
updated = true;
}
- if (BlockHash != tx.BlockHash)
+
+ if (tx.BlockHash != null && BlockHash != tx.BlockHash)
{
BlockHash = tx.BlockHash;
- updated = true;
- }
- if (BlockIndex != tx.BlockIndex)
- {
BlockIndex = tx.BlockIndex;
updated = true;
}

MODIFY
WalletWasabi/Transactions/AllTransactionStore.cs
WalletWasabi/Transactions/AllTransactionStore.cs
@@ -128,11 +128,7 @@ namespace WalletWasabi.Transactions
}
else
{
- if (ConfirmedStore.TryGetTransaction(hash, out SmartTransaction found))
- {
- found.TryUpdate(tx);
- }
- else
+ if (!ConfirmedStore.TryUpdate(tx))
{
MempoolStore.TryAddOrUpdate(tx);
}
@@ -147,32 +143,28 @@ namespace WalletWasabi.Transactions
}
}
- public bool TryUpdate(SmartTransaction tx, out SmartTransaction originalTx)
+ public bool TryUpdate(SmartTransaction tx)
{
var hash = tx.GetHash();
lock (Lock)
{
// Do Contains first, because it's fast.
- if (ConfirmedStore.Contains(hash) && ConfirmedStore.TryGetTransaction(hash, out originalTx))
+ if (ConfirmedStore.TryUpdate(tx))
{
- originalTx.TryUpdate(tx);
return true;
}
- else if (MempoolStore.Contains(hash) && MempoolStore.TryGetTransaction(hash, out originalTx))
+ else if (tx.Confirmed && MempoolStore.TryRemove(hash, out SmartTransaction originalTx))
{
originalTx.TryUpdate(tx);
-
- // If confirmed update the height.
- if (originalTx.Confirmed && MempoolStore.TryRemove(hash, out originalTx))
- {
ConfirmedStore.TryAddOrUpdate(originalTx);
+ return true;
}
-
+ else if (MempoolStore.TryUpdate(tx))
+ {
return true;
}
}
- originalTx = null;
return false;
}
@@ -185,10 +177,9 @@ namespace WalletWasabi.Transactions
{
// Contains is fast, so do this first.
if (ConfirmedStore.Contains(hash)
- && MempoolStore.TryRemove(hash, out SmartTransaction uTx)
- && ConfirmedStore.TryGetTransaction(hash, out SmartTransaction cTx))
+ && MempoolStore.TryRemove(hash, out SmartTransaction uTx))
{
- cTx.TryUpdate(uTx);
+ ConfirmedStore.TryAddOrUpdate(uTx);
}
}
}

MODIFY
WalletWasabi/Transactions/TransactionStore.cs
WalletWasabi/Transactions/TransactionStore.cs
@@ -146,6 +146,34 @@ namespace WalletWasabi.Transactions
}
}
+ public bool TryUpdate(SmartTransaction tx)
+ {
+ bool ret;
+ lock (TransactionsLock)
+ {
+ ret = TryUpdateNoLockNoSerialization(tx);
+ }
+
+ if (ret)
+ {
+ _ = TryUpdateFileAsync(tx);
+ }
+
+ return ret;
+ }
+
+ private bool TryUpdateNoLockNoSerialization(SmartTransaction tx)
+ {
+ var hash = tx.GetHash();
+
+ if (Transactions.TryGetValue(hash, out SmartTransaction found))
+ {
+ return found.TryUpdate(tx);
+ }
+
+ return false;
+ }
+
public bool TryRemove(uint256 hash, out SmartTransaction stx)
{
bool isRemoved;

Implement updateoperations