LCOV - code coverage report
Current view: top level - src/primitives - block.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 4 20 20.0 %
Date: 2025-02-23 09:33:43 Functions: 1 3 33.3 %

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2014 The Bitcoin developers
       3             : // Copyright (c) 2015-2021 The PIVX Core developers
       4             : // Distributed under the MIT/X11 software license, see the accompanying
       5             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       6             : 
       7             : #include "primitives/block.h"
       8             : 
       9             : #include "hash.h"
      10             : #include "script/standard.h"
      11             : #include "tinyformat.h"
      12             : #include "utilstrencodings.h"
      13             : #include "util/system.h"
      14             : 
      15     1155121 : uint256 CBlockHeader::GetHash() const
      16             : {
      17     1155121 :     if (nVersion < 4)  {
      18             : #if defined(WORDS_BIGENDIAN)
      19             :         uint8_t data[80];
      20             :         WriteLE32(&data[0], nVersion);
      21             :         memcpy(&data[4], hashPrevBlock.begin(), hashPrevBlock.size());
      22             :         memcpy(&data[36], hashMerkleRoot.begin(), hashMerkleRoot.size());
      23             :         WriteLE32(&data[68], nTime);
      24             :         WriteLE32(&data[72], nBits);
      25             :         WriteLE32(&data[76], nNonce);
      26             :         return HashQuark(data, data + 80);
      27             : #else // Can take shortcut for little endian
      28        6188 :         return HashQuark(BEGIN(nVersion), END(nNonce));
      29             : #endif
      30             :     }
      31             :     // version >= 4
      32     1148934 :     return SerializeHash(*this);
      33             : }
      34             : 
      35           0 : std::string CBlock::ToString() const
      36             : {
      37           0 :     std::stringstream s;
      38           0 :     s << strprintf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, hashFinalSaplingRoot=%s, vtx=%u)\n",
      39           0 :         GetHash().ToString(),
      40           0 :         nVersion,
      41           0 :         hashPrevBlock.ToString(),
      42           0 :         hashMerkleRoot.ToString(),
      43           0 :         nTime, nBits, nNonce,
      44           0 :         hashFinalSaplingRoot.ToString(),
      45           0 :         vtx.size());
      46           0 :     for (unsigned int i = 0; i < vtx.size(); i++)
      47             :     {
      48           0 :         s << "  " << vtx[i]->ToString() << "\n";
      49             :     }
      50           0 :     return s.str();
      51             : }
      52             : 
      53           0 : void CBlock::print() const
      54             : {
      55           0 :     LogPrintf("%s\n", ToString());
      56           0 : }

Generated by: LCOV version 1.14