| 1504 | namespace { |
| 1505 | |
| 1506 | bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint256& hashBlock, const CMessageHeader::MessageStartChars& messageStart) |
| 1507 | { |
| 1508 | // Open history file to append |
| 1509 | CAutoFile fileout(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION); |
| 1510 | if (fileout.IsNull()) |
| 1511 | return error("%s: OpenUndoFile failed", __func__); |
| 1512 | |
| 1513 | // Write index header |
| 1514 | unsigned int nSize = GetSerializeSize(fileout, blockundo); |
| 1515 | fileout << messageStart << nSize; |
| 1516 | |
| 1517 | // Write undo data |
| 1518 | long fileOutPos = ftell(fileout.Get()); |
| 1519 | if (fileOutPos < 0) |
| 1520 | return error("%s: ftell failed", __func__); |
| 1521 | pos.nPos = (unsigned int)fileOutPos; |
| 1522 | fileout << blockundo; |
| 1523 | |
| 1524 | // calculate & write checksum |
| 1525 | CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION); |
| 1526 | hasher << hashBlock; |
| 1527 | hasher << blockundo; |
| 1528 | fileout << hasher.GetHash(); |
| 1529 | |
| 1530 | return true; |
| 1531 | } |
| 1532 | |
| 1533 | static bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex *pindex) |
| 1534 | { |
no test coverage detected