Bitcoin Core  31.0.0
P2P Digital Currency
block.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-present 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.
5 
6 #include <primitives/block.h>
7 
8 #include <hash.h>
9 #include <tinyformat.h>
10 
11 #include <memory>
12 #include <span>
13 #include <sstream>
14 
16 {
17  return (HashWriter{} << *this).GetHash();
18 }
19 
20 std::string CBlock::ToString() const
21 {
22  std::stringstream s;
23  s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
24  GetHash().ToString(),
25  nVersion,
28  nTime, nBits, nNonce,
29  vtx.size());
30  for (const auto& tx : vtx) {
31  s << " " << tx->ToString() << "\n";
32  }
33  return s.str();
34 }
uint32_t nNonce
Definition: block.h:35
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1172
std::string ToString() const
Definition: block.cpp:20
uint32_t nTime
Definition: block.h:33
uint256 hashMerkleRoot
Definition: block.h:32
A writer stream (for serialization) that computes a 256-bit hash.
Definition: hash.h:100
uint256 hashPrevBlock
Definition: block.h:31
std::string ToString() const
Definition: uint256.cpp:21
uint256 GetHash() const
Definition: block.cpp:15
256-bit opaque blob.
Definition: uint256.h:195
std::vector< CTransactionRef > vtx
Definition: block.h:77
int32_t nVersion
Definition: block.h:30
uint32_t nBits
Definition: block.h:34