[DI] Improve `BitcoinStore` class wrt dependency injection
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -99,9 +99,12 @@ namespace WalletWasabi.Gui
WalletManager.OnDequeue += WalletManager_OnDequeue;
WalletManager.WalletRelevantTransactionProcessed += WalletManager_WalletRelevantTransactionProcessed;
+
+ var indexStore = new IndexStore(Network, new SmartHeaderChain());
+
BitcoinStore = new BitcoinStore(
Path.Combine(DataDir, "BitcoinStore"), Network,
- new IndexStore(), new AllTransactionStore(), new SmartHeaderChain(), new MempoolService()
+ indexStore, new AllTransactionStore(), new MempoolService()
);
SingleInstanceChecker = new SingleInstanceChecker(Network);

MODIFY
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
@@ -58,7 +58,7 @@ namespace WalletWasabi.Tests.IntegrationTests
var dataDir = Path.Combine(Global.Instance.DataDir, EnvironmentHelpers.GetCallerFileName());
BitcoinStore bitcoinStore = new BitcoinStore(Path.Combine(dataDir, EnvironmentHelpers.GetMethodName()), network,
- new IndexStore(), new AllTransactionStore(), new SmartHeaderChain(), new MempoolService());
+ new IndexStore(network, new SmartHeaderChain()), new AllTransactionStore(), new MempoolService());
await bitcoinStore.InitializeAsync();
var addressManagerFolderPath = Path.Combine(dataDir, "AddressManager");

MODIFY
WalletWasabi.Tests/RegressionTests/Common.cs
WalletWasabi.Tests/RegressionTests/Common.cs
@@ -90,7 +90,7 @@ namespace WalletWasabi.Tests.RegressionTests
var serviceConfiguration = new ServiceConfiguration(MixUntilAnonymitySet.PrivacyLevelSome.ToString(), 2, 21, 50, regTestFixture.BackendRegTestNode.P2pEndPoint, Money.Coins(Constants.DefaultDustThreshold));
var dir = GetWorkDir(callerFilePath, callerMemberName);
- var bitcoinStore = new BitcoinStore(dir, network, new IndexStore(), new AllTransactionStore(), new SmartHeaderChain(), new MempoolService());
+ var bitcoinStore = new BitcoinStore(dir, network, new IndexStore(network, new SmartHeaderChain()), new AllTransactionStore(), new MempoolService());
await bitcoinStore.InitializeAsync();
return ("password", global.RpcClient, network, global.Coordinator, serviceConfiguration, bitcoinStore, global);
}

MODIFY
WalletWasabi.Tests/UnitTests/BitcoinCore/P2pBasedTests.cs
WalletWasabi.Tests/UnitTests/BitcoinCore/P2pBasedTests.cs
@@ -32,7 +32,7 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
var network = coreNode.Network;
var rpc = coreNode.RpcClient;
var dir = Path.Combine(Global.Instance.DataDir, EnvironmentHelpers.GetCallerFileName(), EnvironmentHelpers.GetMethodName());
- var bitcoinStore = new BitcoinStore(dir, network, new IndexStore(), new AllTransactionStore(), new SmartHeaderChain(), new MempoolService());
+ var bitcoinStore = new BitcoinStore(dir, network, new IndexStore(network, new SmartHeaderChain()), new AllTransactionStore(), new MempoolService());
await bitcoinStore.InitializeAsync();
await rpc.GenerateAsync(101);

MODIFY
WalletWasabi.Tests/UnitTests/Filters/IndexStoreTests.cs
WalletWasabi.Tests/UnitTests/Filters/IndexStoreTests.cs
@@ -21,15 +21,15 @@ namespace WalletWasabi.Tests.UnitTests.Filters
[Fact]
public async Task IndexStoreTestsAsync()
{
- var indexStore = new IndexStore();
+ var network = Network.Main;
+ var indexStore = new IndexStore(network, new SmartHeaderChain());
var dir = (await GetIndexStorePathsAsync()).dir;
if (Directory.Exists(dir))
{
Directory.Delete(dir, true);
}
- var network = Network.Main;
- await indexStore.InitializeAsync(dir, network, new SmartHeaderChain());
+ await indexStore.InitializeAsync(dir);
}
[Fact]
@@ -37,11 +37,10 @@ namespace WalletWasabi.Tests.UnitTests.Filters
{
var (dir, matureFilters, _) = await GetIndexStorePathsAsync();
- var indexStore = new IndexStore();
-
var network = Network.Main;
var headersChain = new SmartHeaderChain();
+ var indexStore = new IndexStore(network, headersChain);
var dummyFilter = GolombRiceFilter.Parse("00");
static DateTimeOffset MinutesAgo(int mins) => DateTimeOffset.UtcNow.Subtract(TimeSpan.FromMinutes(mins));
@@ -53,7 +52,7 @@ namespace WalletWasabi.Tests.UnitTests.Filters
};
await File.WriteAllLinesAsync(matureFilters, matureIndexStoreContent.Select(x => x.ToLine()));
- await Assert.ThrowsAsync<InvalidOperationException>(async () => await indexStore.InitializeAsync(dir, network, headersChain));
+ await Assert.ThrowsAsync<InvalidOperationException>(async () => await indexStore.InitializeAsync(dir));
Assert.Equal(new uint256(3), headersChain.TipHash);
Assert.Equal(2u, headersChain.TipHeight);
@@ -66,10 +65,9 @@ namespace WalletWasabi.Tests.UnitTests.Filters
{
var (dir, _, immatureFilters) = await GetIndexStorePathsAsync();
- var indexStore = new IndexStore();
-
var network = Network.Main;
var headersChain = new SmartHeaderChain();
+ var indexStore = new IndexStore(network, headersChain);
var dummyFilter = GolombRiceFilter.Parse("00");
@@ -84,7 +82,7 @@ namespace WalletWasabi.Tests.UnitTests.Filters
};
await File.WriteAllLinesAsync(immatureFilters, immatureIndexStoreContent.Select(x => x.ToLine()));
- await Assert.ThrowsAsync<InvalidOperationException>(async () => await indexStore.InitializeAsync(dir, network, headersChain));
+ await Assert.ThrowsAsync<InvalidOperationException>(async () => await indexStore.InitializeAsync(dir));
Assert.Equal(new uint256(3), headersChain.TipHash);
Assert.Equal(startingFilter.Header.Height + 2u, headersChain.TipHeight);
@@ -97,10 +95,9 @@ namespace WalletWasabi.Tests.UnitTests.Filters
{
var (dir, matureFilters, immatureFilters) = await GetIndexStorePathsAsync();
- var indexStore = new IndexStore();
-
var network = Network.Main;
var headersChain = new SmartHeaderChain();
+ var indexStore = new IndexStore(network, headersChain);
var dummyFilter = GolombRiceFilter.Parse("00");
@@ -118,7 +115,7 @@ namespace WalletWasabi.Tests.UnitTests.Filters
};
await File.WriteAllLinesAsync(immatureFilters, immatureIndexStoreContent.Select(x => x.ToLine()));
- await Assert.ThrowsAsync<InvalidOperationException>(async () => await indexStore.InitializeAsync(dir, network, headersChain));
+ await Assert.ThrowsAsync<InvalidOperationException>(async () => await indexStore.InitializeAsync(dir));
Assert.Equal(new uint256(3), headersChain.TipHash);
Assert.Equal(2u, headersChain.TipHeight);
@@ -131,10 +128,9 @@ namespace WalletWasabi.Tests.UnitTests.Filters
{
var (dir, matureFilters, immatureFilters) = await GetIndexStorePathsAsync();
- var indexStore = new IndexStore();
-
var network = Network.Main;
var headersChain = new SmartHeaderChain();
+ var indexStore = new IndexStore(network, headersChain);
var dummyFilter = GolombRiceFilter.Parse("00");
@@ -146,7 +142,7 @@ namespace WalletWasabi.Tests.UnitTests.Filters
};
await File.WriteAllLinesAsync(matureFilters, matureIndexStoreContent.Select(x => x.ToLine()));
- await indexStore.InitializeAsync(dir, network, headersChain);
+ await indexStore.InitializeAsync(dir);
Assert.Equal(new uint256(3), headersChain.TipHash);
Assert.Equal(2u, headersChain.TipHeight);

MODIFY
WalletWasabi/Stores/BitcoinStore.cs
WalletWasabi/Stores/BitcoinStore.cs
@@ -24,7 +24,6 @@ namespace WalletWasabi.Stores
Network network,
IndexStore indexStore,
AllTransactionStore transactionStore,
- SmartHeaderChain smartHeaderChain,
MempoolService mempoolService)
{
WorkFolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true);
@@ -33,7 +32,6 @@ namespace WalletWasabi.Stores
Network = Guard.NotNull(nameof(network), network);
IndexStore = indexStore;
TransactionStore = transactionStore;
- SmartHeaderChain = smartHeaderChain;
MempoolService = mempoolService;
}
@@ -43,7 +41,7 @@ namespace WalletWasabi.Stores
public IndexStore IndexStore { get; }
public AllTransactionStore TransactionStore { get; }
- public SmartHeaderChain SmartHeaderChain { get; }
+ public SmartHeaderChain SmartHeaderChain => IndexStore.SmartHeaderChain;
public MempoolService MempoolService { get; }
/// <summary>
@@ -61,7 +59,7 @@ namespace WalletWasabi.Stores
var initTasks = new[]
{
- IndexStore.InitializeAsync(indexStoreFolderPath, Network, SmartHeaderChain),
+ IndexStore.InitializeAsync(indexStoreFolderPath),
TransactionStore.InitializeAsync(networkWorkFolderPath, Network)
};

MODIFY
WalletWasabi/Stores/IndexStore.cs
WalletWasabi/Stores/IndexStore.cs
@@ -23,6 +23,12 @@ namespace WalletWasabi.Stores
/// </summary>
public class IndexStore
{
+ public IndexStore(Network network, SmartHeaderChain hashChain)
+ {
+ Network = Guard.NotNull(nameof(network), network);
+ SmartHeaderChain = Guard.NotNull(nameof(hashChain), hashChain);
+ }
+
private int _throttleId;
public event EventHandler<FilterModel> Reorged;
@@ -30,23 +36,21 @@ namespace WalletWasabi.Stores
public event EventHandler<FilterModel> NewFilter;
private string WorkFolderPath { get; set; }
- private Network Network { get; set; }
+ private Network Network { get; }
private DigestableSafeMutexIoManager MatureIndexFileManager { get; set; }
private DigestableSafeMutexIoManager ImmatureIndexFileManager { get; set; }
- public SmartHeaderChain SmartHeaderChain { get; private set; }
+ public SmartHeaderChain SmartHeaderChain { get; }
private FilterModel StartingFilter { get; set; }
private uint StartingHeight { get; set; }
private List<FilterModel> ImmatureFilters { get; set; }
private AsyncLock IndexLock { get; set; }
- public async Task InitializeAsync(string workFolderPath, Network network, SmartHeaderChain hashChain)
+ public async Task InitializeAsync(string workFolderPath)
{
using (BenchmarkLogger.Measure())
{
WorkFolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true);
- Network = Guard.NotNull(nameof(network), network);
- SmartHeaderChain = Guard.NotNull(nameof(hashChain), hashChain);
var indexFilePath = Path.Combine(WorkFolderPath, "MatureIndex.dat");
MatureIndexFileManager = new DigestableSafeMutexIoManager(indexFilePath, digestRandomIndex: -1);
var immatureIndexFilePath = Path.Combine(WorkFolderPath, "ImmatureIndex.dat");

[DI] Improve `BitcoinStore` class wrt dependency injection