Permalink
Browse files

Check if fileName is a valid hex string to avoid unneeded exceptions

Still should log files that aren't a hash.
  • Loading branch information...
nelsnelsnelson committed Oct 16, 2018
1 parent 65eed16 commit 4d2bd0e60aac9b69c579f0676e6c913d85db7f4c
Showing with 9 additions and 8 deletions.
  1. +9 −8 WalletWasabi/Services/WalletService.cs
@@ -20,6 +20,7 @@
using WalletWasabi.WebClients.Wasabi;
using Newtonsoft.Json;
using System.Collections.Concurrent;
using NBitcoin.DataEncoders;
namespace WalletWasabi.Services
{
@@ -543,20 +544,20 @@ public async Task<Block> GetOrDownloadBlockAsync(uint256 hash, CancellationToken
// Try get the block
using (await BlockFolderLock.LockAsync())
{
var encoder = new HexEncoder();
foreach (var filePath in Directory.EnumerateFiles(BlocksFolderPath))
{
var fileName = Path.GetFileName(filePath);
try
if (!encoder.IsValid(fileName))
{
if (hash == new uint256(fileName))
{
var blockBytes = await File.ReadAllBytesAsync(filePath);
return Block.Load(blockBytes, IndexDownloader.Network);
}
Logger.LogTrace<WalletService>($"Filename is not a hash: {fileName}.");
continue;
}
catch (FormatException)
if (hash == new uint256(fileName))
{
Logger.LogTrace<WalletService>($"Filename is not a hash: {fileName}.");
var blockBytes = await File.ReadAllBytesAsync(filePath);
return Block.Load(blockBytes, IndexDownloader.Network);
}
}
}

0 comments on commit 4d2bd0e

Please sign in to comment.