Bring together txstore file operations.
RENAME
WalletWasabi.Tests/UnitTests/TransactionStore/TransactionStoreMock.cs
WalletWasabi.Tests/UnitTests/Transactions/TransactionStoreMock.cs
@@ -6,10 +6,11 @@ using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using WalletWasabi.Stores;
+using WalletWasabi.Transactions;
-namespace WalletWasabi.Tests.UnitTests.TransactionStore
+namespace WalletWasabi.Tests.UnitTests.Transactions
{
- public class TransactionStoreMock : Stores.TransactionStore
+ public class TransactionStoreMock : TransactionStore
{
public TransactionStoreMock([CallerMemberName] string caller = null)
{

RENAME
WalletWasabi.Tests/UnitTests/TransactionStore/TransactionStoreTests.cs
WalletWasabi.Tests/UnitTests/Transactions/TransactionStoreTests.cs
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
using WalletWasabi.Models;
using Xunit;
-namespace WalletWasabi.Tests.UnitTests.TransactionStore
+namespace WalletWasabi.Tests.UnitTests.Transactions
{
public class TransactionStoreTests
{

ADD
WalletWasabi/Stores/TxStoreOperation.cs
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WalletWasabi.Stores
+{
+ public enum TxStoreOperation
+ {
+ Add,
+ Remove
+ }
+}

ADD
WalletWasabi/Transactions/Append.cs
+using System;
+using System.Collections.Generic;
+using System.Text;
+using WalletWasabi.Models;
+
+namespace WalletWasabi.Transactions
+{
+ public class Append : ITxStoreOperation
+ {
+ public IEnumerable<SmartTransaction> Transactions { get; }
+
+ public Append(IEnumerable<SmartTransaction> transactions)
+ {
+ Transactions = transactions;
+ }
+ }
+}

ADD
WalletWasabi/Transactions/ITxStoreOperation.cs
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WalletWasabi.Transactions
+{
+ public interface ITxStoreOperation
+ {
+ }
+}

ADD
WalletWasabi/Transactions/Remove.cs
+using NBitcoin;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WalletWasabi.Transactions
+{
+ public class Remove : ITxStoreOperation
+ {
+ public IEnumerable<uint256> Transactions { get; }
+
+ public Remove(IEnumerable<uint256> transactions)
+ {
+ Transactions = transactions;
+ }
+ }
+}

RENAME
WalletWasabi/Stores/TransactionStore.cs
WalletWasabi/Transactions/TransactionStore.cs
@@ -10,7 +10,7 @@ using WalletWasabi.Io;
using WalletWasabi.Logging;
using WalletWasabi.Models;
-namespace WalletWasabi.Stores
+namespace WalletWasabi.Transactions
{
public class TransactionStore
{
@@ -231,18 +231,35 @@ namespace WalletWasabi.Stores
await TransactionsFileManager.WriteAllLinesAsync(transactionsClone.ToBlockchainOrderedLines()).ConfigureAwait(false);
}
- private async Task TryAppendToFileAsync(params SmartTransaction[] stxs)
- => await TryAppendToFileAsync(stxs as IEnumerable<SmartTransaction>).ConfigureAwait(false);
+ private async Task TryAppendToFileAsync(params SmartTransaction[] transactions)
+ => await TryAppendToFileAsync(transactions as IEnumerable<SmartTransaction>).ConfigureAwait(false);
private async Task TryAppendToFileAsync(IEnumerable<SmartTransaction> transactions)
+ => await TryCommitToFileAsync(new Append(transactions)).ConfigureAwait(false);
+
+ private async Task TryRemoveFromFileAsync(params uint256[] transactionIds)
+ => await TryRemoveFromFileAsync(transactionIds as IEnumerable<uint256>).ConfigureAwait(false);
+
+ private async Task TryRemoveFromFileAsync(IEnumerable<uint256> transactionIds)
+ => await TryCommitToFileAsync(new Remove(transactionIds)).ConfigureAwait(false);
+
+ private async Task TryCommitToFileAsync(ITxStoreOperation operation)
{
try
{
+ if (operation is Append appendOperation)
+ {
+ IEnumerable<SmartTransaction> toAppends = appendOperation.Transactions;
+ if (toAppends is null || !toAppends.Any())
+ {
+ return;
+ }
+
using (await TransactionsFileManager.Mutex.LockAsync().ConfigureAwait(false))
{
try
{
- await TransactionsFileManager.AppendAllLinesAsync(transactions.ToBlockchainOrderedLines()).ConfigureAwait(false);
+ await TransactionsFileManager.AppendAllLinesAsync(toAppends.ToBlockchainOrderedLines()).ConfigureAwait(false);
}
catch
{
@@ -250,16 +267,9 @@ namespace WalletWasabi.Stores
}
}
}
- catch (Exception ex)
- {
- Logger.LogError(ex);
- }
- }
-
- private async Task TryRemoveFromFileAsync(params uint256[] toRemoves)
- {
- try
+ else if (operation is Remove removeOperation)
{
+ IEnumerable<uint256> toRemoves = removeOperation.Transactions;
if (toRemoves is null || !toRemoves.Any())
{
return;
@@ -293,6 +303,11 @@ namespace WalletWasabi.Stores
}
}
}
+ else
+ {
+ throw new ArgumentException(nameof(operation));
+ }
+ }
catch (Exception ex)
{
Logger.LogError(ex);

Bring together txstore file operations.