Skip to content

Commit

Permalink
Serialize the block header in CBlockHeader::GetHash() (#2531)
Browse files Browse the repository at this point in the history
* Serialize the block header in CBlockHeader::GetHash()

* Switch from CDataStream to CVectorWriter

Co-Authored-By: solardiz <solar@openwall.com>
  • Loading branch information
solardiz authored and codablock committed Dec 10, 2018
1 parent 5185dd5 commit cbd0303
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Makefile.am
Expand Up @@ -397,6 +397,7 @@ libdash_consensus_a_SOURCES = \
script/script_error.cpp \
script/script_error.h \
serialize.h \
streams.h \
tinyformat.h \
uint256.cpp \
uint256.h \
Expand Down
6 changes: 5 additions & 1 deletion src/primitives/block.cpp
Expand Up @@ -6,13 +6,17 @@
#include "primitives/block.h"

#include "hash.h"
#include "streams.h"
#include "tinyformat.h"
#include "utilstrencodings.h"
#include "crypto/common.h"

uint256 CBlockHeader::GetHash() const
{
return HashX11(BEGIN(nVersion), END(nNonce));
std::vector<unsigned char> vch(80);
CVectorWriter ss(SER_NETWORK, PROTOCOL_VERSION, vch, 0);
ss << *this;
return HashX11((const char *)vch.data(), (const char *)vch.data() + vch.size());
}

std::string CBlock::ToString() const
Expand Down

0 comments on commit cbd0303

Please sign in to comment.