dogecoin/src/primitives/block.cpp

43 lines
1.4 KiB
C++
Raw Normal View History

// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2016 The Bitcoin Core developers
2014-12-13 05:09:33 +01:00
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2014-11-18 22:03:02 +01:00
#include "primitives/block.h"
#include "hash.h"
#include "tinyformat.h"
#include "utilstrencodings.h"
#include "crypto/common.h"
2013-06-25 03:03:03 +02:00
uint256 CBlockHeader::GetHash() const
{
return SerializeHash(*this);
2013-06-25 03:03:03 +02:00
}
std::string CBlock::ToString() const
2013-06-25 03:03:03 +02:00
{
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(),
2013-06-25 03:03:03 +02:00
nVersion,
hashPrevBlock.ToString(),
hashMerkleRoot.ToString(),
2013-06-25 03:03:03 +02:00
nTime, nBits, nNonce,
vtx.size());
for (unsigned int i = 0; i < vtx.size(); i++)
{
s << " " << vtx[i]->ToString() << "\n";
2013-06-25 03:03:03 +02:00
}
return s.str();
2013-06-25 03:03:03 +02:00
}
2016-07-18 19:28:26 +02:00
int64_t GetBlockWeight(const CBlock& block)
{
2016-07-18 19:28:26 +02:00
// This implements the weight = (stripped_size * 4) + witness_size formula,
// using only serialization with and without witness data. As witness_size
// is equal to total_size - stripped_size, this formula is identical to:
2016-07-18 19:28:26 +02:00
// weight = (stripped_size * 3) + total_size.
return ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * (WITNESS_SCALE_FACTOR - 1) + ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION);
}