/// </summary>
public class CBlock
{
+ /// <summary>
+ /// Maximum block size is 1Mb.
+ /// </summary>
+ public const uint nMaxBlockSize = 1000000;
+
+ /// <summary>
+ /// Sanity threshold for amount of sigops.
+ /// </summary>
+ public const uint nMaxSigOps = 20000;
+
/// <summary>
/// Block header.
/// </summary>
{
try
{
- ByteQueue wBytes = new ByteQueue(ref blockBytes);
+ var stream = new MemoryStream(blockBytes);
+ var reader = new BinaryReader(stream);
// Fill the block header fields
- header = new CBlockHeader(wBytes.Get(80));
+ header = new CBlockHeader(ref reader);
// Parse transactions list
- vtx = CTransaction.ReadTransactionsList(ref wBytes);
+ vtx = CTransaction.ReadTransactionsList(ref reader);
// Read block signature
- signature = wBytes.Get((int)wBytes.GetVarInt());
+ signature = reader.ReadBytes((int)VarInt.ReadVarInt(ref reader));
+
+ reader.Close();
}
catch (Exception e)
{
uint nSigOps = 0; // total sigops
// Basic sanity checkings
- if (vtx.Length == 0 || Size > 1000000)
+ if (vtx.Length == 0 || Size > nMaxBlockSize)
{
return false;
}
}
// Reject block if validation would consume too much resources.
- if (nSigOps > 50000)
+ if (nSigOps > nMaxSigOps)
{
return false;
}