Define block signatures, active IFF g_signed_blocks active

This commit is contained in:
Gregory Sanders 2018-12-07 10:26:35 +01:00
parent f7c5cf7d92
commit 60f70620c2
2 changed files with 60 additions and 5 deletions

View file

@ -13,6 +13,12 @@
bool g_con_blockheightinheader = false;
bool g_signed_blocks = false;
std::string CProof::ToString() const
{
return strprintf("CProof(challenge=%s, solution=%s)",
HexStr(challenge), HexStr(solution));
}
uint256 CBlockHeader::GetHash() const
{
return SerializeHash(*this);
@ -21,12 +27,12 @@ uint256 CBlockHeader::GetHash() const
std::string CBlock::ToString() const
{
std::stringstream s;
s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, proof=%u, vtx=%u)\n",
GetHash().ToString(),
nVersion,
hashPrevBlock.ToString(),
hashMerkleRoot.ToString(),
nTime, nBits, nNonce,
nTime, nBits, nNonce, proof.ToString(),
vtx.size());
for (const auto& tx : vtx) {
s << " " << tx->ToString() << "\n";

View file

@ -7,10 +7,48 @@
#define BITCOIN_PRIMITIVES_BLOCK_H
#include <primitives/transaction.h>
#include <script/script.h>
#include <serialize.h>
#include <uint256.h>
extern bool g_con_blockheightinheader;
extern bool g_signed_blocks;
class CProof
{
public:
CScript challenge;
CScript solution;
CProof()
{
SetNull();
}
CProof(CScript challengeIn, CScript solutionIn) : challenge(challengeIn), solution(solutionIn) {}
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(*(CScriptBase*)(&challenge));
if (!(s.GetType() & SER_GETHASH))
READWRITE(*(CScriptBase*)(&solution));
}
void SetNull()
{
challenge.clear();
solution.clear();
}
bool IsNull() const
{
return challenge.empty();
}
std::string ToString() const;
};
/** Nodes collect new transactions into a block, hash them into a hash tree,
* and scan through nonce values to make the block's hash satisfy proof-of-work
@ -32,6 +70,7 @@ public:
uint32_t block_height;
uint32_t nBits;
uint32_t nNonce;
CProof proof;
CBlockHeader()
{
@ -49,8 +88,12 @@ public:
if (g_con_blockheightinheader) {
READWRITE(block_height);
}
READWRITE(nBits);
READWRITE(nNonce);
if (g_signed_blocks) {
READWRITE(proof);
} else {
READWRITE(nBits);
READWRITE(nNonce);
}
}
void SetNull()
@ -62,11 +105,16 @@ public:
block_height = 0;
nBits = 0;
nNonce = 0;
proof.SetNull();
}
bool IsNull() const
{
return (nBits == 0);
if (g_signed_blocks) {
return proof.IsNull();
} else {
return (nBits == 0);
}
}
uint256 GetHash() const;
@ -123,6 +171,7 @@ public:
block.block_height = block_height;
block.nBits = nBits;
block.nNonce = nNonce;
block.proof = proof;
return block;
}