mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
Merge pull request #4748
ad49c25Split up util.cpp/h (Wladimir J. van der Laan)f841aa2Move `COIN` and `CENT` to core.h (Wladimir J. van der Laan)6e5fd00Move `*Version()` functions to version.h/cpp (Wladimir J. van der Laan)b4aa769Move `S_I*` constants and `MSG_NOSIGNAL` to compat.h (Wladimir J. van der Laan)af8297cMove functions in wallet.h to implementation file (Wladimir J. van der Laan)651480cmove functions in main and net to implementation files (Wladimir J. van der Laan)610a8c0Move SetThreadPriority implementation to util.cpp instead of the header (Wladimir J. van der Laan)f780e65Remove unused function `ByteReverse` from util.h (Wladimir J. van der Laan)121d6adRemove unused `alignup` function from util.h (Wladimir J. van der Laan)d1e26d4Move CMedianFilter to timedata.cpp (Wladimir J. van der Laan)
This commit is contained in:
62
src/main.cpp
62
src/main.cpp
@@ -24,6 +24,7 @@
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
@@ -4655,7 +4656,68 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
}
|
||||
|
||||
|
||||
bool CBlockUndo::WriteToDisk(CDiskBlockPos &pos, const uint256 &hashBlock)
|
||||
{
|
||||
// Open history file to append
|
||||
CAutoFile fileout = CAutoFile(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION);
|
||||
if (!fileout)
|
||||
return error("CBlockUndo::WriteToDisk : OpenUndoFile failed");
|
||||
|
||||
// Write index header
|
||||
unsigned int nSize = fileout.GetSerializeSize(*this);
|
||||
fileout << FLATDATA(Params().MessageStart()) << nSize;
|
||||
|
||||
// Write undo data
|
||||
long fileOutPos = ftell(fileout);
|
||||
if (fileOutPos < 0)
|
||||
return error("CBlockUndo::WriteToDisk : ftell failed");
|
||||
pos.nPos = (unsigned int)fileOutPos;
|
||||
fileout << *this;
|
||||
|
||||
// calculate & write checksum
|
||||
CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
|
||||
hasher << hashBlock;
|
||||
hasher << *this;
|
||||
fileout << hasher.GetHash();
|
||||
|
||||
// Flush stdio buffers and commit to disk before returning
|
||||
fflush(fileout);
|
||||
if (!IsInitialBlockDownload())
|
||||
FileCommit(fileout);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBlockUndo::ReadFromDisk(const CDiskBlockPos &pos, const uint256 &hashBlock)
|
||||
{
|
||||
// Open history file to read
|
||||
CAutoFile filein = CAutoFile(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
|
||||
if (!filein)
|
||||
return error("CBlockUndo::ReadFromDisk : OpenBlockFile failed");
|
||||
|
||||
// Read block
|
||||
uint256 hashChecksum;
|
||||
try {
|
||||
filein >> *this;
|
||||
filein >> hashChecksum;
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
return error("%s : Deserialize or I/O error - %s", __func__, e.what());
|
||||
}
|
||||
|
||||
// Verify checksum
|
||||
CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
|
||||
hasher << hashBlock;
|
||||
hasher << *this;
|
||||
if (hashChecksum != hasher.GetHash())
|
||||
return error("CBlockUndo::ReadFromDisk : Checksum mismatch");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string CBlockFileInfo::ToString() const {
|
||||
return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, DateTimeStrFormat("%Y-%m-%d", nTimeFirst).c_str(), DateTimeStrFormat("%Y-%m-%d", nTimeLast).c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user