Last active
January 29, 2019 07:56
-
-
Save lontivero/0ee229c81f9c48c42b84697b780cdf4d to your computer and use it in GitHub Desktop.
Convert Wasabi client-side filters to binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp2.2</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="NBitcoin" Version="4.1.1.73" /> | |
</ItemGroup> | |
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Linq; | |
using NBitcoin.DataEncoders; | |
namespace BinaryFilters | |
{ | |
class Program | |
{ | |
private static byte[] EmptyByteArray = new byte[0]; | |
static void Main(string[] args) | |
{ | |
using(var binaryFile = File.Open("/home/lontivero/.walletwasabi/client/IndexMain.bin", FileMode.Truncate)) | |
using(var writer = new BinaryWriter(binaryFile)) | |
using(var textFile = File.OpenRead("/home/lontivero/.walletwasabi/client/IndexMain.dat")) | |
using(var reader = new StreamReader(textFile)) | |
{ | |
string line; | |
while((line = reader.ReadLine()) != null) | |
{ | |
var parts = line.Split(":", StringSplitOptions.RemoveEmptyEntries); | |
var blockId = Encoders.Hex.DecodeData(parts[0]).Reverse().ToArray(); | |
var filter = parts.Length == 2 ? Encoders.Hex.DecodeData(parts[1]) : EmptyByteArray; | |
writer.Write(blockId); | |
writer.Write(BitConverter.GetBytes(filter.Length)); | |
writer.Write(filter); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment