diff --git a/WalletWasabi/Services/WalletService.cs b/WalletWasabi/Services/WalletService.cs index 1186a7bec49..d9ae9d44573 100644 --- a/WalletWasabi/Services/WalletService.cs +++ b/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 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($"Filename is not a hash: {fileName}."); + continue; } - catch (FormatException) + + if (hash == new uint256(fileName)) { - Logger.LogTrace($"Filename is not a hash: {fileName}."); + var blockBytes = await File.ReadAllBytesAsync(filePath); + return Block.Load(blockBytes, IndexDownloader.Network); } } }