aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorEric Lombrozo <elombrozo@gmail.com>2013-06-23 17:47:47 -0700
committerEric Lombrozo <elombrozo@gmail.com>2013-06-23 19:59:32 -0700
commit226f8219422e9252cece036cf61d87738782d674 (patch)
tree7b0d0b917383238856e24f5394a72646c6276ebf /src/main.cpp
parenta6dba0fdb281ee99e6814ad64c1c4d3032347816 (diff)
Moved WriteBlockToDisk implementation from main.h to main.cpp
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index bde9d66031..87f5256f50 100644
--- a/src/main.cpp
+++ b/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()))