| 72 | } |
| 73 | |
| 74 | bool CBlockUndo::ReadFromDisk(const CDiskBlockPos &pos, const uint256 &blockHash) { |
| 75 | // Open history file to read |
| 76 | CAutoFile filein = CAutoFile(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION); |
| 77 | if (!filein) |
| 78 | return ERRORMSG("CBlockUndo::ReadFromDisk : OpenBlockFile failed"); |
| 79 | |
| 80 | // Read block |
| 81 | uint256 hashChecksum; |
| 82 | try { |
| 83 | filein >> *this; |
| 84 | filein >> hashChecksum; |
| 85 | } catch (std::exception &e) { |
| 86 | return ERRORMSG("Deserialize or I/O error - %s", e.what()); |
| 87 | } |
| 88 | |
| 89 | // Verify checksum |
| 90 | CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION); |
| 91 | hasher << blockHash; |
| 92 | hasher << *this; |
| 93 | |
| 94 | if (hashChecksum != hasher.GetHash()) |
| 95 | return ERRORMSG("CBlockUndo::ReadFromDisk : Checksum mismatch"); |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | string CBlockUndo::ToString() const { |
| 100 | string str; |
no test coverage detected