public static void Write(Stream channel, StoredBlock block)
{
using (var buf = ByteBuffer.Allocate(Size))
{
buf.PutInt((int) block.Height);
var chainWorkBytes = block.ChainWork.ToByteArray();
Debug.Assert(chainWorkBytes.Length <= _chainWorkBytes, "Ran out of space to store chain work!");
if (chainWorkBytes.Length < _chainWorkBytes)
{
// Pad to the right size.
buf.Put(_emptyBytes, 0, _chainWorkBytes - chainWorkBytes.Length);
}
buf.Put(chainWorkBytes);
buf.Put(block.Header.BitcoinSerialize());
buf.Position = 0;
channel.Position = channel.Length;
channel.Write(buf.ToArray());
channel.Position = channel.Length - Size;
}
}