using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
namespace Novacoin
{
///
/// Block header
///
public class CBlockHeader
{
///
/// Version of block schema.
///
public uint nVersion = 6;
///
/// Previous block hash.
///
public Hash256 prevHash = new Hash256();
///
/// Merkle root hash.
///
public Hash256 merkleRoot = new Hash256();
///
/// Block timestamp.
///
public uint nTime = 0;
///
/// Compressed difficulty representation.
///
public uint nBits = 0;
///
/// Nonce counter.
///
public uint nNonce = 0;
///
/// Initialize an empty instance
///
public CBlockHeader ()
{
}
public CBlockHeader(CBlockHeader h)
{
nVersion = h.nVersion;
prevHash = new Hash256(h.prevHash);
merkleRoot = new Hash256(h.merkleRoot);
nTime = h.nTime;
nBits = h.nBits;
nNonce = h.nNonce;
}
public CBlockHeader(byte[] bytes)
{
nVersion = BitConverter.ToUInt32(bytes, 0);
prevHash = new Hash256(bytes, 4);
merkleRoot = new Hash256(bytes, 36);
nTime = BitConverter.ToUInt32(bytes, 68);
nBits = BitConverter.ToUInt32(bytes, 72);
nNonce = BitConverter.ToUInt32(bytes, 76);
}
///
/// Convert current block header instance into sequence of bytes
///
/// Byte sequence
public IList Bytes
{
get
{
List r = new List();
r.AddRange(BitConverter.GetBytes(nVersion));
r.AddRange(prevHash.hashBytes);
r.AddRange(merkleRoot.hashBytes);
r.AddRange(BitConverter.GetBytes(nTime));
r.AddRange(BitConverter.GetBytes(nBits));
r.AddRange(BitConverter.GetBytes(nNonce));
return r;
}
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("CBlockHeader(nVersion={0}, prevHash={1}, merkleRoot={2}, nTime={3}, nBits={4}, nNonce={5})", nVersion, prevHash.ToString(), merkleRoot.ToString(), nTime, nBits, nNonce);
return sb.ToString();
}
}
}