Skip to content

Instantly share code, notes, and snippets.

@lontivero
Last active January 29, 2019 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lontivero/0ee229c81f9c48c42b84697b780cdf4d to your computer and use it in GitHub Desktop.
Save lontivero/0ee229c81f9c48c42b84697b780cdf4d to your computer and use it in GitHub Desktop.
Convert Wasabi client-side filters to binary
<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>
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