57 return error(
"%s: Failed to open file %s", __func__,
pathDB.string());
63 catch (std::exception &e) {
64 return error(
"%s: Serialize or I/O error - %s", __func__, e.what());
69 LogPrintf(
" %s\n", objToSave.ToString());
80 error(
"%s: Failed to open file %s", __func__,
pathDB.string());
85 int fileSize = fs::file_size(
pathDB);
86 int dataSize = fileSize -
sizeof(
uint256);
88 if (dataSize < 0) dataSize = 0;
89 std::vector<unsigned char> vchData;
90 vchData.resize(dataSize);
95 filein.
read((
char *)vchData.data(), dataSize);
97 }
catch (std::exception &e) {
98 error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
107 if (hashIn != hashTmp) {
108 error(
"%s: Checksum mismatch, data corrupted", __func__);
112 unsigned char pchMsgTmp[4];
113 std::string strMagicMessageTmp;
116 ssObj >> strMagicMessageTmp;
120 error(
"%s: Invalid magic message", __func__);
128 if (memcmp(pchMsgTmp,
Params().MessageStart(),
sizeof(pchMsgTmp))) {
129 error(
"%s: Invalid network magic number", __func__);
135 }
catch (std::exception &e) {
137 error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
142 LogPrintf(
" %s\n", objToLoad.ToString());
147 const std::string& strMagicMessageIn) :
155 LogPrintf(
"Reading info from %s...\n",
strFilename);
158 LogPrintf(
"Missing file %s, will try to recreate\n",
strFilename);
159 }
else if (readResult !=
Ok) {
162 LogPrintf(
"%s: Magic is ok but data has invalid format, will try to recreate\n", __func__);
164 LogPrintf(
"%s: File format is unknown or invalid, please fix it manually\n", __func__);
const CChainParams & Params()
Return the currently selected parameters.
Non-refcounted RAII wrapper for FILE*.
bool IsNull() const
Return true if the wrapped FILE* is nullptr, false otherwise.
void read(char *pch, size_t nSize)
const_iterator end() const
const_iterator begin() const
const CMessageHeader::MessageStartChars & MessageStart() const
std::string strMagicMessage
fs::path GetDbPath() const
ReadResult Read(T &objToLoad)
CFlatDB(const std::string &strFilenameIn, const std::string &strMagicMessageIn)
uint256 Hash(const T1 pbegin, const T1 pend)
Compute the 256-bit hash of an object.
#define T(expected, seed, data)
FILE * fopen(const fs::path &p, const char *mode)
const fs::path & GetDataDir(bool fNetSpecific)
bool error(const char *fmt, const Args &... args)
int64_t GetTimeMillis()
Returns the system time (not mockable)