git / moonbite-core / src/primitives/block.cpp · raw
// Copyright (c) 2009-2010 Satoshi Nakamoto// Copyright (c) 2009-2019 The Bitcoin Core developers// Distributed under the MIT software license, see the accompanying// file COPYING or http://www.opensource.org/licenses/mit-license.php.#include <primitives/block.h>#include <hash.h>#include <tinyformat.h>#include <util/strencodings.h>#include <crypto/common.h>#include <crypto/randomx_hasher.h>uint256 CBlockHeader::GetHash() const{ return SerializeHash(*this);}uint256 CBlockHeader::GetPoWHash() const{ // MoonBite (ADR-001): RandomX over the 80-byte serialized header. The cache // is keyed by the 32-byte MBITE_RX_SEED (SHA-256 of "MBITE-RX-1"); per-epoch seed rotation is a // documented follow-up (see crypto/randomx_hasher.h). Header layout is // nVersion(4) + hashPrevBlock(32) + hashMerkleRoot(32) + nTime(4) + // nBits(4) + nNonce(4) = 80 contiguous bytes starting at &nVersion. uint256 thash; RandomXHashBytes(BEGIN(nVersion), 80, (unsigned char*)BEGIN(thash)); return thash;}std::string CBlock::ToString() const{ std::stringstream s; s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n", GetHash().ToString(), nVersion, hashPrevBlock.ToString(), hashMerkleRoot.ToString(), nTime, nBits, nNonce, vtx.size()); for (const auto& tx : vtx) { s << " " << tx->ToString() << "\n"; } return s.str();}CTransactionRef CBlock::GetHogEx() const noexcept{ if (vtx.size() >= 2 && vtx.back()->IsHogEx()) { assert(!vtx.back()->vout.empty()); return vtx.back(); } return nullptr;}