Skip to content

Instantly share code, notes, and snippets.

@andrewkkchan
Created June 23, 2021 14:44
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 andrewkkchan/d1eecff037628ea00ebd8b3f1db75178 to your computer and use it in GitHub Desktop.
Save andrewkkchan/d1eecff037628ea00ebd8b3f1db75178 to your computer and use it in GitHub Desktop.
BlockHeader of BitCoin Core
class CBlockHeader
{
public:
// header
int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
uint32_t nTime;
uint32_t nBits;
uint32_t nNonce;
CBlockHeader()
{
SetNull();
}
SERIALIZE_METHODS(CBlockHeader, obj) { READWRITE(obj.nVersion, obj.hashPrevBlock, obj.hashMerkleRoot, obj.nTime, obj.nBits, obj.nNonce); }
void SetNull()
{
nVersion = 0;
hashPrevBlock.SetNull();
hashMerkleRoot.SetNull();
nTime = 0;
nBits = 0;
nNonce = 0;
}
bool IsNull() const
{
return (nBits == 0);
}
uint256 GetHash() const;
int64_t GetBlockTime() const
{
return (int64_t)nTime;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment