/* * This file is part of the Flowee project * Copyright (C) 2026 Tom Zander * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "BlockHeader.h" #include "Block.h" #include BlockHeader::BlockHeader(const Block &block) : nVersion(block.blockVersion()), hashPrevBlock(block.previousBlockId()), hashMerkleRoot(block.merkleRoot()), nTime(block.timestamp()), nBits(block.bits()), nNonce(block.nonce()) { } uint256 BlockHeader::createHash() const { uint8_t header[80]; *reinterpret_cast(header) = nVersion; memcpy(header + 4, hashPrevBlock.begin(), 32); memcpy(header + 36, hashMerkleRoot.begin(), 32); *reinterpret_cast(header + 68) = nTime; *reinterpret_cast(header + 72) = nBits; *reinterpret_cast(header + 76) = nNonce; CHash256 ctx; ctx.write(header, 80); uint256 result; ctx.finalize((unsigned char*)&result); return result; }