| 40 | // } |
| 41 | |
| 42 | bool CBlockUndo::WriteToDisk(CDiskBlockPos &pos, const uint256 &blockHash) { |
| 43 | // Open history file to append |
| 44 | CAutoFile fileout = CAutoFile(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION); |
| 45 | if (!fileout) |
| 46 | return ERRORMSG("CBlockUndo::WriteToDisk : OpenUndoFile failed"); |
| 47 | |
| 48 | // Write index header |
| 49 | uint32_t nSize = fileout.GetSerializeSize(*this); |
| 50 | fileout << FLATDATA(SysCfg().MessageStart()) << nSize; |
| 51 | |
| 52 | // Write undo data |
| 53 | long fileOutPos = ftell(fileout); |
| 54 | if (fileOutPos < 0) |
| 55 | return ERRORMSG("CBlockUndo::WriteToDisk : ftell failed"); |
| 56 | pos.nPos = (uint32_t)fileOutPos; |
| 57 | fileout << *this; |
| 58 | |
| 59 | // calculate & write checksum |
| 60 | CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION); |
| 61 | hasher << blockHash; |
| 62 | hasher << *this; |
| 63 | |
| 64 | fileout << hasher.GetHash(); |
| 65 | |
| 66 | // Flush stdio buffers and commit to disk before returning |
| 67 | fflush(fileout); |
| 68 | if (!IsInitialBlockDownload()) |
| 69 | FileCommit(fileout); |
| 70 | |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | bool CBlockUndo::ReadFromDisk(const CDiskBlockPos &pos, const uint256 &blockHash) { |
| 75 | // Open history file to read |
no test coverage detected