From 9e442eb109e05a7572cb55b1b66f7a4625e58307 Mon Sep 17 00:00:00 2001 From: Jianping Wu Date: Fri, 8 Mar 2019 11:19:10 -0800 Subject: [PATCH] WIP: fixed block serialization. --- src/primitives/block.cpp | 13 +++++------ src/primitives/block.h | 50 +++++++++++++++++++++++++++++++++++----- src/rpc/mining.cpp | 2 +- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp index 787302a70..f5a94ea85 100644 --- a/src/primitives/block.cpp +++ b/src/primitives/block.cpp @@ -16,7 +16,9 @@ extern "C" void cn_slow_hash(const void *data, size_t length, char *hash, int va uint256 CBlockHeader::GetHash() const { - return SerializeHash(*this); + CHashWriter hashWriter(SER_GETHASH, PROTOCOL_VERSION); + hashWriter.write(BEGIN(nVersion), 80); + return hashWriter.GetHash(); } uint256 CBlockHeader::GetPoWHash() const @@ -33,13 +35,10 @@ uint256 CBlockHeader::GetPoWHash() const // following XOR operatiosn, the value of expectedHash is not changed. blockHash ^= expectedHash; expectedHash ^= blockHash; - CryptoNoteHeader header = cnHeader; + CryptoNoteHeader cnHeaderCompute = cnHeader; // Cryptonote prev_id is used to store kevacoin block hash. - header.prev_id = ArithToUint256(expectedHash); - - CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); - stream << header; - std::string blob = stream.str(); + cnHeaderCompute.prev_id = ArithToUint256(expectedHash); + cryptonote::blobdata blob = cryptonote::t_serializable_object_to_blob(cnHeaderCompute); cn_slow_hash(blob.data(), blob.size(), BEGIN(thash), 2, 0, 0); return thash; } diff --git a/src/primitives/block.h b/src/primitives/block.h index e74ebc358..588603049 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -49,7 +49,28 @@ public: return (timestamp == 0); } - BEGIN_SERIALIZE() + // load + template