1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #include "primitives/block.h"
9 #include "tinyformat.h"
10 #include "utilstrencodings.h"
11 #include "crypto/common.h"
13 uint256
CBlockHeader::GetHash() const
15 return SerializeHash(*this);
18 std::string
CBlock::ToString() const
21 s
<< strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
24 hashPrevBlock
.ToString(),
25 hashMerkleRoot
.ToString(),
28 for (unsigned int i
= 0; i
< vtx
.size(); i
++)
30 s
<< " " << vtx
[i
].ToString() << "\n";
35 int64_t GetBlockCost(const CBlock
& block
)
37 // This implements the cost = (stripped_size * 4) + witness_size formula,
38 // using only serialization with and without witness data. As witness_size
39 // is equal to total_size - stripped_size, this formula is identical to:
40 // cost = (stripped_size * 3) + total_size.
41 return ::GetSerializeSize(block
, SER_NETWORK
, PROTOCOL_VERSION
| SERIALIZE_TRANSACTION_NO_WITNESS
) * (WITNESS_SCALE_FACTOR
- 1) + ::GetSerializeSize(block
, SER_NETWORK
, PROTOCOL_VERSION
);