Dispose txstore
MODIFY
WalletWasabi.Tests/UnitTests/Transactions/TransactionStoreTests.cs
WalletWasabi.Tests/UnitTests/Transactions/TransactionStoreTests.cs
@@ -11,7 +11,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public async Task CanInitializeAsync()
{
- var txStore = new TransactionStoreMock();
+ await using var txStore = new TransactionStoreMock();
var network = Network.Main;
await txStore.InitializeAsync(network);
@@ -28,7 +28,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
[Fact]
public async Task CanDoOperationsAsync()
{
- var txStore = new TransactionStoreMock();
+ await using var txStore = new TransactionStoreMock();
var network = Network.Main;
await txStore.InitializeAsync(network);

MODIFY
WalletWasabi/Blockchain/Transactions/AllTransactionStore.cs
WalletWasabi/Blockchain/Transactions/AllTransactionStore.cs
@@ -12,7 +12,7 @@ using WalletWasabi.Logging;
namespace WalletWasabi.Blockchain.Transactions
{
- public class AllTransactionStore
+ public class AllTransactionStore : IAsyncDisposable
{
public AllTransactionStore(string workFolderPath, Network network)
{
@@ -261,6 +261,19 @@ namespace WalletWasabi.Blockchain.Transactions
public IEnumerable<SmartLabel> GetLabels() => GetTransactions().Select(x => x.Label);
+ public async ValueTask DisposeAsync()
+ {
+ if (MempoolStore is { } mempoolStore)
+ {
+ await mempoolStore.DisposeAsync().ConfigureAwait(false);
+ }
+
+ if (ConfirmedStore is { } confirmedStore)
+ {
+ await confirmedStore.DisposeAsync().ConfigureAwait(false);
+ }
+ }
+
#endregion Accessors
}
}

MODIFY
WalletWasabi/Blockchain/Transactions/TransactionStore.cs
WalletWasabi/Blockchain/Transactions/TransactionStore.cs
+using Microsoft.AspNetCore.JsonPatch;
using NBitcoin;
using Nito.AsyncEx;
using System;
@@ -12,7 +13,7 @@ using WalletWasabi.Logging;
namespace WalletWasabi.Blockchain.Transactions
{
- public class TransactionStore
+ public class TransactionStore : IAsyncDisposable
{
public string WorkFolderPath { get; private set; }
public Network Network { get; private set; }
@@ -308,6 +309,7 @@ namespace WalletWasabi.Blockchain.Transactions
}
}
+ ThrowIfDisposed();
using (await TransactionsAsyncLock.LockAsync().ConfigureAwait(false))
{
foreach (ITxStoreOperation op in operationsToExecute)
@@ -395,5 +397,30 @@ namespace WalletWasabi.Blockchain.Transactions
}
#endregion Serialization
+
+ private void ThrowIfDisposed()
+ {
+ if (_disposed)
+ {
+ throw new ObjectDisposedException(nameof(TransactionStore));
+ }
+ }
+
+ private bool _disposed;
+
+ public async ValueTask DisposeAsync()
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ // Indicate that the object is disposed.
+ _disposed = true;
+
+ using (await TransactionsAsyncLock.LockAsync().ConfigureAwait(false))
+ {
+ }
+ }
}
}

Dispose txstore