MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / WriteToDisk

Method WriteToDisk

src/persistence/blockundo.cpp:42–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40// }
41
42bool 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
74bool CBlockUndo::ReadFromDisk(const CDiskBlockPos &pos, const uint256 &blockHash) {
75 // Open history file to read

Callers 1

ConnectBlockFunction · 0.45

Calls 6

CAutoFileClass · 0.85
OpenUndoFileFunction · 0.85
IsInitialBlockDownloadFunction · 0.85
FileCommitFunction · 0.85
GetSerializeSizeMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected