Fabcoin Core  0.16.2
P2P Digital Currency
block.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 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 #include <utilstrencodings.h>
11 #include <crypto/common.h>
12 #include <chainparams.h>
13 #include <consensus/params.h>
14 #include <util.h>
15 
16 
18 {
19  return SerializeHash(*this);
20 
21  /*int version;
22 
23  if ((uint32_t) -1 == (uint32_t)params.FABHeight ) {
24  version = PROTOCOL_VERSION | SERIALIZE_BLOCK_LEGACY;
25  }
26  else if (nHeight >= (uint32_t)params.FABHeight) {
27  version = PROTOCOL_VERSION;
28  } else {
29  version = PROTOCOL_VERSION | SERIALIZE_BLOCK_LEGACY;
30  }
31  CHashWriter writer(SER_GETHASH, version);
32 
33  ::Serialize(writer, *this);
34  return writer.GetHash();
35  */
36 }
37 
39 {
40  //const Consensus::Params& consensusParams = Params().GetConsensus();
41  //return GetHash(consensusParams);
42 
43  return SerializeHash(*this);
44 }
45 
47 {
48  return SerializeHash(*this, SER_GETHASH | SER_WITHOUT_SIGNATURE);
49 }
50 
51 std::string CBlockHeader::ToString() const
52 {
53  std::stringstream s;
54  s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, hashStateRoot=%s, hashUTXORoot=%s, nHeight=%u, nTime=%u, nBits=%08x, nNonce=%s)\n",
55  GetHash().ToString(),
56  nVersion,
59  hashStateRoot.ToString(), // fasc
60  hashUTXORoot.ToString(), // fasc
62 
63  return s.str();
64 }
65 
66 std::string CBlock::ToString() const
67 {
68  std::stringstream s;
69  s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, hashStateRoot=%s, hashUTXORoot=%s, nHeight=%u, nTime=%u, nBits=%08x, nNonce=%s, vtx=%u)\n",
70  GetHash().ToString(),
71  nVersion,
74  hashStateRoot.ToString(), // fasc
75  hashUTXORoot.ToString(), // fasc
77  vtx.size());
78  for (const auto& tx : vtx) {
79  s << " " << tx->ToString() << "\n";
80  }
81 
82  return s.str();
83 }
84 
86 {
87  //genesis block
88  if ( nHeight == 0 ) {
89  if ( nVersion == 5 )
90  return true;
91  else
92  return false;
93  }
94 
96  if ( fRegTest )
97  return true;
98 
99  return ((uint32_t) nHeight >= (uint32_t) Params().GetConsensus().ContractHeight );
100 
101 }
102 
104 {
105  if ( nHeight == 0 )
106  return false;
107  //regtest legacyformat
108  return (Params().NetworkIDString() == CBaseChainParams::REGTEST ) || (Params().NetworkIDString() == CBaseChainParams::UNITTEST );
109 }
uint256 nNonce
Definition: block.h:53
static const std::string REGTEST
#define strprintf
Definition: tinyformat.h:1054
std::string GetHex() const
Definition: uint256.cpp:21
static const std::string UNITTEST
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:60
uint32_t nHeight
Definition: block.h:46
uint32_t nTime
Definition: block.h:48
std::string ToString() const
Definition: uint256.cpp:95
std::string NetworkIDString() const
Return the BIP70 network string (main, test or regtest)
Definition: chainparams.h:78
uint256 SerializeHash(const T &obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
Compute the 256-bit hash of an object&#39;s serialization.
Definition: hash.h:200
uint256 hashMerkleRoot
Definition: block.h:45
uint32_t ContractHeight
Block height at which Fabcoin Smart Contract hard fork becomes active.
Definition: params.h:56
uint256 hashPrevBlock
Definition: block.h:44
uint256 GetHashWithoutSign() const
Definition: block.cpp:46
Parameters that influence chain consensus.
Definition: params.h:39
std::string ToString() const
Definition: block.cpp:66
256-bit opaque blob.
Definition: uint256.h:132
std::string ToString() const
Definition: block.cpp:51
uint256 GetHash() const
Definition: block.cpp:38
const CChainParams & Params()
Return the currently selected parameters.
bool _IsLegacyFormat(int nHeight)
Definition: block.cpp:103
uint256 hashStateRoot
Definition: block.h:50
bool _IsSupportContract(int nVersion, int nHeight)
Definition: block.cpp:85
uint256 hashUTXORoot
Definition: block.h:51
int32_t nVersion
Definition: block.h:43
uint32_t nBits
Definition: block.h:49