mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
Moved CBlock::WriteToDisk out of CBlock to inline function WriteBlockToDisk in main.h
This commit is contained in:
51
src/main.h
51
src/main.h
@@ -682,31 +682,6 @@ public:
|
||||
return hash;
|
||||
}
|
||||
|
||||
bool WriteToDisk(CDiskBlockPos &pos)
|
||||
{
|
||||
// Open history file to append
|
||||
CAutoFile fileout = CAutoFile(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
|
||||
if (!fileout)
|
||||
return error("CBlock::WriteToDisk() : OpenBlockFile failed");
|
||||
|
||||
// Write index header
|
||||
unsigned int nSize = fileout.GetSerializeSize(*this);
|
||||
fileout << FLATDATA(Params().MessageStart()) << nSize;
|
||||
|
||||
// Write block
|
||||
long fileOutPos = ftell(fileout);
|
||||
if (fileOutPos < 0)
|
||||
return error("CBlock::WriteToDisk() : ftell failed");
|
||||
pos.nPos = (unsigned int)fileOutPos;
|
||||
fileout << *this;
|
||||
|
||||
// Flush stdio buffers and commit to disk before returning
|
||||
fflush(fileout);
|
||||
if (!IsInitialBlockDownload())
|
||||
FileCommit(fileout);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReadFromDisk(const CDiskBlockPos &pos)
|
||||
{
|
||||
@@ -779,6 +754,32 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user