Changeset View
Changeset View
Standalone View
Standalone View
src/addrdb.cpp
Show All 17 Lines | |||||
namespace { | namespace { | ||||
template <typename Stream, typename Data> | template <typename Stream, typename Data> | ||||
bool SerializeDB(const CChainParams &chainParams, Stream &stream, | bool SerializeDB(const CChainParams &chainParams, Stream &stream, | ||||
const Data &data) { | const Data &data) { | ||||
// Write and commit header, data | // Write and commit header, data | ||||
try { | try { | ||||
CHashWriter hasher(SER_DISK, CLIENT_VERSION); | CHashWriter hasher(SER_DISK, CLIENT_VERSION); | ||||
stream << FLATDATA(chainParams.DiskMagic()) << data; | stream << chainParams.DiskMagic() << data; | ||||
hasher << FLATDATA(chainParams.DiskMagic()) << data; | hasher << chainParams.DiskMagic() << data; | ||||
stream << hasher.GetHash(); | stream << hasher.GetHash(); | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
return error("%s: Serialize or I/O error - %s", __func__, e.what()); | return error("%s: Serialize or I/O error - %s", __func__, e.what()); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
Show All 32 Lines | |||||
template <typename Stream, typename Data> | template <typename Stream, typename Data> | ||||
bool DeserializeDB(const CChainParams &chainParams, Stream &stream, Data &data, | bool DeserializeDB(const CChainParams &chainParams, Stream &stream, Data &data, | ||||
bool fCheckSum = true) { | bool fCheckSum = true) { | ||||
try { | try { | ||||
CHashVerifier<Stream> verifier(&stream); | CHashVerifier<Stream> verifier(&stream); | ||||
// de-serialize file header (network specific magic number) and .. | // de-serialize file header (network specific magic number) and .. | ||||
uint8_t pchMsgTmp[4]; | uint8_t pchMsgTmp[4]; | ||||
verifier >> FLATDATA(pchMsgTmp); | verifier >> pchMsgTmp; | ||||
// ... verify the network matches ours | // ... verify the network matches ours | ||||
if (memcmp(pchMsgTmp, std::begin(chainParams.DiskMagic()), | if (memcmp(pchMsgTmp, std::begin(chainParams.DiskMagic()), | ||||
sizeof(pchMsgTmp))) { | sizeof(pchMsgTmp))) { | ||||
return error("%s: Invalid network magic number", __func__); | return error("%s: Invalid network magic number", __func__); | ||||
} | } | ||||
// de-serialize data | // de-serialize data | ||||
verifier >> data; | verifier >> data; | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |