mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-10 23:07:52 +00:00
Moved CBlock::WriteToDisk out of CBlock to inline function WriteBlockToDisk in main.h
This commit is contained in:
parent
fd967fed89
commit
a6dba0fdb2
@ -2262,7 +2262,7 @@ bool CBlock::AcceptBlock(CValidationState &state, CDiskBlockPos *dbp)
|
|||||||
if (!FindBlockPos(state, blockPos, nBlockSize+8, nHeight, nTime, dbp != NULL))
|
if (!FindBlockPos(state, blockPos, nBlockSize+8, nHeight, nTime, dbp != NULL))
|
||||||
return error("AcceptBlock() : FindBlockPos failed");
|
return error("AcceptBlock() : FindBlockPos failed");
|
||||||
if (dbp == NULL)
|
if (dbp == NULL)
|
||||||
if (!WriteToDisk(blockPos))
|
if (!WriteBlockToDisk(*this, blockPos))
|
||||||
return state.Abort(_("Failed to write block"));
|
return state.Abort(_("Failed to write block"));
|
||||||
if (!AddToBlockIndex(state, blockPos))
|
if (!AddToBlockIndex(state, blockPos))
|
||||||
return error("AcceptBlock() : AddToBlockIndex failed");
|
return error("AcceptBlock() : AddToBlockIndex failed");
|
||||||
@ -2800,7 +2800,7 @@ bool InitBlockIndex() {
|
|||||||
CValidationState state;
|
CValidationState state;
|
||||||
if (!FindBlockPos(state, blockPos, nBlockSize+8, 0, block.nTime))
|
if (!FindBlockPos(state, blockPos, nBlockSize+8, 0, block.nTime))
|
||||||
return error("LoadBlockIndex() : FindBlockPos failed");
|
return error("LoadBlockIndex() : FindBlockPos failed");
|
||||||
if (!block.WriteToDisk(blockPos))
|
if (!WriteBlockToDisk(block, blockPos))
|
||||||
return error("LoadBlockIndex() : writing genesis block to disk failed");
|
return error("LoadBlockIndex() : writing genesis block to disk failed");
|
||||||
if (!block.AddToBlockIndex(state, blockPos))
|
if (!block.AddToBlockIndex(state, blockPos))
|
||||||
return error("LoadBlockIndex() : genesis block not accepted");
|
return error("LoadBlockIndex() : genesis block not accepted");
|
||||||
|
51
src/main.h
51
src/main.h
@ -682,31 +682,6 @@ public:
|
|||||||
return hash;
|
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)
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user