Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 939 Lines • ▼ Show 20 Lines | static bool WriteBlockToDisk(const CBlock &block, FlatFilePos &pos, | ||||
// Open history file to append | // Open history file to append | ||||
CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION); | CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION); | ||||
if (fileout.IsNull()) { | if (fileout.IsNull()) { | ||||
return error("WriteBlockToDisk: OpenBlockFile failed"); | return error("WriteBlockToDisk: OpenBlockFile failed"); | ||||
} | } | ||||
// Write index header | // Write index header | ||||
unsigned int nSize = GetSerializeSize(fileout, block); | unsigned int nSize = GetSerializeSize(fileout, block); | ||||
fileout << FLATDATA(messageStart) << nSize; | fileout << messageStart << nSize; | ||||
// Write block | // Write block | ||||
long fileOutPos = ftell(fileout.Get()); | long fileOutPos = ftell(fileout.Get()); | ||||
if (fileOutPos < 0) { | if (fileOutPos < 0) { | ||||
return error("WriteBlockToDisk: ftell failed"); | return error("WriteBlockToDisk: ftell failed"); | ||||
} | } | ||||
pos.nPos = (unsigned int)fileOutPos; | pos.nPos = (unsigned int)fileOutPos; | ||||
▲ Show 20 Lines • Show All 395 Lines • ▼ Show 20 Lines | bool UndoWriteToDisk(const CBlockUndo &blockundo, FlatFilePos &pos, | ||||
// Open history file to append | // Open history file to append | ||||
CAutoFile fileout(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION); | CAutoFile fileout(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION); | ||||
if (fileout.IsNull()) { | if (fileout.IsNull()) { | ||||
return error("%s: OpenUndoFile failed", __func__); | return error("%s: OpenUndoFile failed", __func__); | ||||
} | } | ||||
// Write index header | // Write index header | ||||
unsigned int nSize = GetSerializeSize(fileout, blockundo); | unsigned int nSize = GetSerializeSize(fileout, blockundo); | ||||
fileout << FLATDATA(messageStart) << nSize; | fileout << messageStart << nSize; | ||||
// Write undo data | // Write undo data | ||||
long fileOutPos = ftell(fileout.Get()); | long fileOutPos = ftell(fileout.Get()); | ||||
if (fileOutPos < 0) { | if (fileOutPos < 0) { | ||||
return error("%s: ftell failed", __func__); | return error("%s: ftell failed", __func__); | ||||
} | } | ||||
pos.nPos = (unsigned int)fileOutPos; | pos.nPos = (unsigned int)fileOutPos; | ||||
fileout << blockundo; | fileout << blockundo; | ||||
▲ Show 20 Lines • Show All 3,743 Lines • ▼ Show 20 Lines | try { | ||||
// Remove former limit. | // Remove former limit. | ||||
blkdat.SetLimit(); | blkdat.SetLimit(); | ||||
unsigned int nSize = 0; | unsigned int nSize = 0; | ||||
try { | try { | ||||
// Locate a header. | // Locate a header. | ||||
uint8_t buf[CMessageHeader::MESSAGE_START_SIZE]; | uint8_t buf[CMessageHeader::MESSAGE_START_SIZE]; | ||||
blkdat.FindByte(chainparams.DiskMagic()[0]); | blkdat.FindByte(chainparams.DiskMagic()[0]); | ||||
nRewind = blkdat.GetPos() + 1; | nRewind = blkdat.GetPos() + 1; | ||||
blkdat >> FLATDATA(buf); | blkdat >> buf; | ||||
if (memcmp(buf, std::begin(chainparams.DiskMagic()), | if (memcmp(buf, chainparams.DiskMagic().data(), | ||||
CMessageHeader::MESSAGE_START_SIZE)) { | CMessageHeader::MESSAGE_START_SIZE)) { | ||||
continue; | continue; | ||||
} | } | ||||
// Read size. | // Read size. | ||||
blkdat >> nSize; | blkdat >> nSize; | ||||
if (nSize < 80) { | if (nSize < 80) { | ||||
continue; | continue; | ||||
▲ Show 20 Lines • Show All 628 Lines • Show Last 20 Lines |