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

Function WriteBlockToDisk

src/persistence/block.cpp:136–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134// global functions
135
136bool WriteBlockToDisk(CBlock &block, CDiskBlockPos &pos) {
137 // Open history file to append
138 CAutoFile fileout = CAutoFile(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
139 if (!fileout)
140 return ERRORMSG("WriteBlockToDisk : OpenBlockFile failed");
141
142 // Write index header
143 uint32_t nSize = fileout.GetSerializeSize(block);
144 fileout << FLATDATA(SysCfg().MessageStart()) << nSize;
145
146 // Write block
147 int32_t fileOutPos = ftell(fileout);
148 if (fileOutPos < 0)
149 return ERRORMSG("WriteBlockToDisk : ftell failed");
150 pos.nPos = (uint32_t)fileOutPos;
151 fileout << block;
152
153 // Flush stdio buffers and commit to disk before returning
154 fflush(fileout);
155 if (!IsInitialBlockDownload())
156 FileCommit(fileout);
157
158 return true;
159}
160
161bool ReadBlockFromDisk(const CDiskBlockPos &pos, CBlock &block) {
162 block.SetNull();

Callers 2

AcceptBlockFunction · 0.85
InitBlockIndexFunction · 0.85

Calls 5

CAutoFileClass · 0.85
OpenBlockFileFunction · 0.85
IsInitialBlockDownloadFunction · 0.85
FileCommitFunction · 0.85
GetSerializeSizeMethod · 0.45

Tested by

no test coverage detected