| 134 | // global functions |
| 135 | |
| 136 | bool WriteBlockToDisk(CBlock &block, CDiskBlockPos &pos) { |
| 137 | // Open history file to append |
| 138 | CAutoFile fileout = CAutoFile(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION); |
| 139 | if (!fileout) |
| 140 | return ERRORMSG("WriteBlockToDisk : OpenBlockFile failed"); |
| 141 | |
| 142 | // Write index header |
| 143 | uint32_t nSize = fileout.GetSerializeSize(block); |
| 144 | fileout << FLATDATA(SysCfg().MessageStart()) << nSize; |
| 145 | |
| 146 | // Write block |
| 147 | int32_t fileOutPos = ftell(fileout); |
| 148 | if (fileOutPos < 0) |
| 149 | return ERRORMSG("WriteBlockToDisk : ftell failed"); |
| 150 | pos.nPos = (uint32_t)fileOutPos; |
| 151 | fileout << block; |
| 152 | |
| 153 | // Flush stdio buffers and commit to disk before returning |
| 154 | fflush(fileout); |
| 155 | if (!IsInitialBlockDownload()) |
| 156 | FileCommit(fileout); |
| 157 | |
| 158 | return true; |
| 159 | } |
| 160 | |
| 161 | bool ReadBlockFromDisk(const CDiskBlockPos &pos, CBlock &block) { |
| 162 | block.SetNull(); |
no test coverage detected