| 496 | } |
| 497 | |
| 498 | static bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock, const CMessageHeader::MessageStartChars& messageStart) |
| 499 | { |
| 500 | // Open history file to append |
| 501 | CAutoFile fileout(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION); |
| 502 | if (fileout.IsNull()) { |
| 503 | return error("%s: OpenUndoFile failed", __func__); |
| 504 | } |
| 505 | |
| 506 | // Write index header |
| 507 | unsigned int nSize = GetSerializeSize(blockundo, fileout.GetVersion()); |
| 508 | fileout << messageStart << nSize; |
| 509 | |
| 510 | // Write undo data |
| 511 | long fileOutPos = ftell(fileout.Get()); |
| 512 | if (fileOutPos < 0) { |
| 513 | return error("%s: ftell failed", __func__); |
| 514 | } |
| 515 | pos.nPos = (unsigned int)fileOutPos; |
| 516 | fileout << blockundo; |
| 517 | |
| 518 | // calculate & write checksum |
| 519 | CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION); |
| 520 | hasher << hashBlock; |
| 521 | hasher << blockundo; |
| 522 | fileout << hasher.GetHash(); |
| 523 | |
| 524 | return true; |
| 525 | } |
| 526 | |
| 527 | bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex) |
| 528 | { |
no test coverage detected