Optimize directory structure
MODIFY
MagicalCryptoWallet.Backend/Global.cs
MagicalCryptoWallet.Backend/Global.cs
@@ -50,8 +50,9 @@ namespace MagicalCryptoWallet.Backend
await AssertRpcNodeFullyInitializedAsync();
- var indexFilePath = Path.Combine(DataDir, $"Index{RpcClient.Network}.dat");
- var utxoSetFilePath = Path.Combine(DataDir, $"UtxoSet{RpcClient.Network}.dat");
+ var indexBuilderServiceDir = Path.Combine(DataDir, nameof(IndexBuilderService));
+ var indexFilePath = Path.Combine(indexBuilderServiceDir, $"Index{RpcClient.Network}.dat");
+ var utxoSetFilePath = Path.Combine(indexBuilderServiceDir, $"UtxoSet{RpcClient.Network}.dat");
IndexBuilderService = new IndexBuilderService(RpcClient, indexFilePath, utxoSetFilePath);
IndexBuilderService.Syncronize();
}

MODIFY
MagicalCryptoWallet.Tests/WalletTests.cs
MagicalCryptoWallet.Tests/WalletTests.cs
@@ -52,7 +52,8 @@ namespace MagicalCryptoWallet.Tests
var dataFolder = Path.Combine(SharedFixture.DataDir, nameof(TestServicesAsync));
Directory.CreateDirectory(SharedFixture.DataDir);
- var addressManagerFilePath = Path.Combine(SharedFixture.DataDir, $"AddressManager{network}.dat");
+ var addressManagerFolderPath = Path.Combine(SharedFixture.DataDir, "AddressManager");
+ var addressManagerFilePath = Path.Combine(addressManagerFolderPath, $"AddressManager{network}.dat");
var blocksFolderPath = Path.Combine(SharedFixture.DataDir, $"Blocks{network}");
var connectionParameters = new NodeConnectionParameters();
AddressManager addressManager = null;
@@ -64,6 +65,12 @@ namespace MagicalCryptoWallet.Tests
addressManager = AddressManager.LoadPeerFile(addressManagerFilePath);
Logger.LogInfo<WalletService>($"Loaded {nameof(AddressManager)} from `{addressManagerFilePath}`.");
}
+ catch(DirectoryNotFoundException ex)
+ {
+ Logger.LogInfo<WalletService>($"{nameof(AddressManager)} did not exist at `{addressManagerFilePath}`. Initializing new one.");
+ Logger.LogTrace<WalletService>(ex);
+ addressManager = new AddressManager();
+ }
catch (FileNotFoundException ex)
{
Logger.LogInfo<WalletService>($"{nameof(AddressManager)} did not exist at `{addressManagerFilePath}`. Initializing new one.");
@@ -152,10 +159,14 @@ namespace MagicalCryptoWallet.Tests
// So next test will download the block.
foreach (var hash in blocksToDownload)
{
- downloader.TryRemove(hash);
+ downloader?.TryRemove(hash);
}
+ if (Directory.Exists(blocksFolderPath))
+ {
Directory.Delete(blocksFolderPath, recursive: true);
+ }
+ Directory.CreateDirectory(Path.GetDirectoryName(addressManagerFilePath));
addressManager?.SavePeerFile(addressManagerFilePath, network);
Logger.LogInfo<WalletTests>($"Saved {nameof(AddressManager)} to `{addressManagerFilePath}`.");
}

MODIFY
MagicalCryptoWallet/Services/IndexBuilderService.cs
MagicalCryptoWallet/Services/IndexBuilderService.cs
@@ -149,6 +149,7 @@ namespace MagicalCryptoWallet.Services
// ToDo: IMPORTANT! The Bech32UtxoSet MUST be recovered to its previous state, too!
if (prevHash != block.Header.HashPrevBlock) // reorg
{
+ Logger.LogInfo<IndexBuilderService>($"REORG Invalid Block: {prevHash}");
using (await IndexLock.LockAsync())
{
Index.RemoveAt(Index.Count - 1);

Optimize directory structure