mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-14 00:58:09 +00:00
WIP: fixed block serialization.
This commit is contained in:
parent
420c6a56d6
commit
9e442eb109
@ -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;
|
||||
}
|
||||
|
@ -49,7 +49,28 @@ public:
|
||||
return (timestamp == 0);
|
||||
}
|
||||
|
||||
BEGIN_SERIALIZE()
|
||||
// load
|
||||
template <template <bool> class Archive>
|
||||
bool do_serialize(Archive<false>& ar)
|
||||
{
|
||||
VARINT_FIELD(major_version)
|
||||
VARINT_FIELD(minor_version)
|
||||
VARINT_FIELD(timestamp)
|
||||
crypto::hash prev_hash;
|
||||
FIELD(prev_hash)
|
||||
memcpy(prev_id.begin(), &prev_hash, prev_id.size());
|
||||
FIELD(nonce)
|
||||
crypto::hash merkle_hash;
|
||||
FIELD(merkle_hash)
|
||||
memcpy(merkle_root.begin(), &merkle_hash, merkle_root.size());
|
||||
VARINT_FIELD(nTxes)
|
||||
return true;
|
||||
}
|
||||
|
||||
// store
|
||||
template <template <bool> class Archive>
|
||||
bool do_serialize(Archive<true>& ar)
|
||||
{
|
||||
VARINT_FIELD(major_version)
|
||||
VARINT_FIELD(minor_version)
|
||||
VARINT_FIELD(timestamp)
|
||||
@ -57,16 +78,33 @@ public:
|
||||
memcpy(&prev_hash, prev_id.begin(), prev_id.size());
|
||||
FIELD(prev_hash)
|
||||
FIELD(nonce)
|
||||
END_SERIALIZE()
|
||||
crypto::hash merkle_hash;
|
||||
memcpy(&merkle_hash, merkle_root.begin(), merkle_root.size());
|
||||
FIELD(merkle_hash)
|
||||
VARINT_FIELD(nTxes)
|
||||
return true;
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
std::string blob = cryptonote::t_serializable_object_to_blob(*this);
|
||||
blob.append(reinterpret_cast<const char*>(merkle_root.begin()), merkle_root.size());
|
||||
blob.append(tools::get_varint_data(nTxes + 1));
|
||||
READWRITE(blob);
|
||||
if (ser_action.ForRead()) {
|
||||
std::string blob;
|
||||
READWRITE(blob);
|
||||
std::stringstream ss;
|
||||
ss << blob;
|
||||
// load
|
||||
binary_archive<false> ba(ss);
|
||||
::serialization::serialize(ba, *this);
|
||||
} else {
|
||||
std::stringstream ss;
|
||||
// store
|
||||
binary_archive<true> ba(ss);
|
||||
::serialization::serialize(ba, *this);
|
||||
std::string blob = ss.str();
|
||||
READWRITE(blob);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -661,7 +661,7 @@ UniValue submitblock(const JSONRPCRequest& request)
|
||||
block.cnHeader.prev_id = CryptoHashToUint256(cnblock.prev_id);
|
||||
|
||||
block.cnHeader.nonce = cnblock.nonce;
|
||||
crypto::hash tree_root_hash = get_tx_tree_hash(cnblock);
|
||||
crypto::hash tree_root_hash = cryptonote::get_tx_tree_hash(cnblock);
|
||||
block.cnHeader.merkle_root = CryptoHashToUint256(tree_root_hash);
|
||||
uint256 hash = block.GetHash();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user