Skip to content

Commit

Permalink
Merge pull request #737 from davex25/DontLogHexFilenameExceptions
Browse files Browse the repository at this point in the history
Check if fileName is a valid hex string to avoid unneeded exceptions
  • Loading branch information
nopara73 committed Oct 17, 2018
2 parents 4d5afbb + 4d2bd0e commit 8b304be
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions WalletWasabi/Services/WalletService.cs
Expand Up @@ -20,6 +20,7 @@
using WalletWasabi.WebClients.Wasabi;
using Newtonsoft.Json;
using System.Collections.Concurrent;
using NBitcoin.DataEncoders;

namespace WalletWasabi.Services
{
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 8b304be

Please sign in to comment.