mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Moved WriteBlockToDisk implementation from main.h to main.cpp
This commit is contained in:
parent
a6dba0fdb2
commit
226f821942
26
src/main.cpp
26
src/main.cpp
@ -1146,6 +1146,32 @@ CBlockIndex* FindBlockByHeight(int nHeight)
|
||||
return vBlockIndexByHeight[nHeight];
|
||||
}
|
||||
|
||||
bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
|
||||
{
|
||||
// Open history file to append
|
||||
CAutoFile fileout = CAutoFile(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
|
||||
if (!fileout)
|
||||
return error("WriteBlockToDisk() : OpenBlockFile failed");
|
||||
|
||||
// Write index header
|
||||
unsigned int nSize = fileout.GetSerializeSize(block);
|
||||
fileout << FLATDATA(Params().MessageStart()) << nSize;
|
||||
|
||||
// Write block
|
||||
long fileOutPos = ftell(fileout);
|
||||
if (fileOutPos < 0)
|
||||
return error("WriteBlockToDisk() : ftell failed");
|
||||
pos.nPos = (unsigned int)fileOutPos;
|
||||
fileout << block;
|
||||
|
||||
// Flush stdio buffers and commit to disk before returning
|
||||
fflush(fileout);
|
||||
if (!IsInitialBlockDownload())
|
||||
FileCommit(fileout);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBlock::ReadFromDisk(const CBlockIndex* pindex)
|
||||
{
|
||||
if (!ReadFromDisk(pindex->GetBlockPos()))
|
||||
|
26
src/main.h
26
src/main.h
@ -755,31 +755,7 @@ public:
|
||||
|
||||
|
||||
/** Functions for disk access for blocks */
|
||||
inline bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
|
||||
{
|
||||
// Open history file to append
|
||||
CAutoFile fileout = CAutoFile(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
|
||||
if (!fileout)
|
||||
return error("WriteBlockToDisk() : OpenBlockFile failed");
|
||||
|
||||
// Write index header
|
||||
unsigned int nSize = fileout.GetSerializeSize(block);
|
||||
fileout << FLATDATA(Params().MessageStart()) << nSize;
|
||||
|
||||
// Write block
|
||||
long fileOutPos = ftell(fileout);
|
||||
if (fileOutPos < 0)
|
||||
return error("WriteBlockToDisk() : ftell failed");
|
||||
pos.nPos = (unsigned int)fileOutPos;
|
||||
fileout << block;
|
||||
|
||||
// Flush stdio buffers and commit to disk before returning
|
||||
fflush(fileout);
|
||||
if (!IsInitialBlockDownload())
|
||||
FileCommit(fileout);
|
||||
|
||||
return true;
|
||||
}
|
||||
bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos);
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user