Permalink
Browse files

Merge pull request #737 from davex25/DontLogHexFilenameExceptions

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 8b304be1f26765b6a713e025e28097f66f2394ca
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 8b304be

Please sign in to comment.