@@ -38,45 +38,54 @@ static constexpr uint8_t DB_LAST_BLOCK{'l'};
3838// CBlockTreeDB::DB_TXINDEX{'t'}
3939// CBlockTreeDB::ReadFlag("txindex")
4040
41- bool CBlockTreeDB::ReadBlockFileInfo (int nFile, CBlockFileInfo &info) {
41+ bool CBlockTreeDB::ReadBlockFileInfo (int nFile, CBlockFileInfo& info)
42+ {
4243 return Read (std::make_pair (DB_BLOCK_FILES, nFile), info);
4344}
4445
45- bool CBlockTreeDB::WriteReindexing (bool fReindexing ) {
46- if (fReindexing )
46+ bool CBlockTreeDB::WriteReindexing (bool fReindexing )
47+ {
48+ if (fReindexing ) {
4749 return Write (DB_REINDEX_FLAG, uint8_t {' 1' });
48- else
50+ } else {
4951 return Erase (DB_REINDEX_FLAG);
52+ }
5053}
5154
52- void CBlockTreeDB::ReadReindexing (bool &fReindexing ) {
55+ void CBlockTreeDB::ReadReindexing (bool & fReindexing )
56+ {
5357 fReindexing = Exists (DB_REINDEX_FLAG);
5458}
5559
56- bool CBlockTreeDB::ReadLastBlockFile (int &nFile) {
60+ bool CBlockTreeDB::ReadLastBlockFile (int & nFile)
61+ {
5762 return Read (DB_LAST_BLOCK, nFile);
5863}
5964
60- bool CBlockTreeDB::WriteBatchSync (const std::vector<std::pair<int , const CBlockFileInfo*> >& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo) {
65+ bool CBlockTreeDB::WriteBatchSync (const std::vector<std::pair<int , const CBlockFileInfo*>>& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo)
66+ {
6167 CDBBatch batch (*this );
62- for (std::vector<std::pair< int , const CBlockFileInfo*> >::const_iterator it=fileInfo. begin (); it != fileInfo. end (); it++ ) {
63- batch.Write (std::make_pair (DB_BLOCK_FILES, it-> first ), *it-> second );
68+ for (const auto & [file, info] : fileInfo) {
69+ batch.Write (std::make_pair (DB_BLOCK_FILES, file ), *info );
6470 }
6571 batch.Write (DB_LAST_BLOCK, nLastFile);
66- for (std::vector< const CBlockIndex*>::const_iterator it=blockinfo. begin (); it != blockinfo. end (); it++ ) {
67- batch.Write (std::make_pair (DB_BLOCK_INDEX, (*it) ->GetBlockHash ()), CDiskBlockIndex (*it) );
72+ for (const CBlockIndex* bi : blockinfo) {
73+ batch.Write (std::make_pair (DB_BLOCK_INDEX, bi ->GetBlockHash ()), CDiskBlockIndex{bi} );
6874 }
6975 return WriteBatch (batch, true );
7076}
7177
72- bool CBlockTreeDB::WriteFlag (const std::string &name, bool fValue ) {
78+ bool CBlockTreeDB::WriteFlag (const std::string& name, bool fValue )
79+ {
7380 return Write (std::make_pair (DB_FLAG, name), fValue ? uint8_t {' 1' } : uint8_t {' 0' });
7481}
7582
76- bool CBlockTreeDB::ReadFlag (const std::string &name, bool &fValue ) {
83+ bool CBlockTreeDB::ReadFlag (const std::string& name, bool & fValue )
84+ {
7785 uint8_t ch;
78- if (!Read (std::make_pair (DB_FLAG, name), ch))
86+ if (!Read (std::make_pair (DB_FLAG, name), ch)) {
7987 return false ;
88+ }
8089 fValue = ch == uint8_t {' 1' };
8190 return true ;
8291}
0 commit comments