@@ -59,37 +59,40 @@ class CBlockFileInfo
59
59
READWRITE (VARINT (obj.nTimeLast ));
60
60
}
61
61
62
- void SetNull () {
63
- nBlocks = 0 ;
64
- nSize = 0 ;
65
- nUndoSize = 0 ;
66
- nHeightFirst = 0 ;
67
- nHeightLast = 0 ;
68
- nTimeFirst = 0 ;
69
- nTimeLast = 0 ;
70
- }
71
-
72
- CBlockFileInfo () {
73
- SetNull ();
74
- }
75
-
76
- std::string ToString () const ;
77
-
78
- /* * update statistics (does not update nSize) */
79
- void AddBlock (unsigned int nHeightIn, uint64_t nTimeIn) {
80
- if (nBlocks==0 || nHeightFirst > nHeightIn)
81
- nHeightFirst = nHeightIn;
82
- if (nBlocks==0 || nTimeFirst > nTimeIn)
83
- nTimeFirst = nTimeIn;
84
- nBlocks++;
85
- if (nHeightIn > nHeightLast)
86
- nHeightLast = nHeightIn;
87
- if (nTimeIn > nTimeLast)
88
- nTimeLast = nTimeIn;
89
- }
62
+ void SetNull ()
63
+ {
64
+ nBlocks = 0 ;
65
+ nSize = 0 ;
66
+ nUndoSize = 0 ;
67
+ nHeightFirst = 0 ;
68
+ nHeightLast = 0 ;
69
+ nTimeFirst = 0 ;
70
+ nTimeLast = 0 ;
71
+ }
72
+
73
+ CBlockFileInfo ()
74
+ {
75
+ SetNull ();
76
+ }
77
+
78
+ std::string ToString () const ;
79
+
80
+ /* * update statistics (does not update nSize) */
81
+ void AddBlock (unsigned int nHeightIn, uint64_t nTimeIn)
82
+ {
83
+ if (nBlocks == 0 || nHeightFirst > nHeightIn)
84
+ nHeightFirst = nHeightIn;
85
+ if (nBlocks == 0 || nTimeFirst > nTimeIn)
86
+ nTimeFirst = nTimeIn;
87
+ nBlocks++;
88
+ if (nHeightIn > nHeightLast)
89
+ nHeightLast = nHeightIn;
90
+ if (nTimeIn > nTimeLast)
91
+ nTimeLast = nTimeIn;
92
+ }
90
93
};
91
94
92
- enum BlockStatus: uint32_t {
95
+ enum BlockStatus : uint32_t {
93
96
// ! Unused.
94
97
BLOCK_VALID_UNKNOWN = 0 ,
95
98
@@ -220,34 +223,36 @@ class CBlockIndex
220
223
{
221
224
}
222
225
223
- FlatFilePos GetBlockPos () const {
226
+ FlatFilePos GetBlockPos () const
227
+ {
224
228
FlatFilePos ret;
225
229
if (nStatus & BLOCK_HAVE_DATA) {
226
230
ret.nFile = nFile;
227
- ret.nPos = nDataPos;
231
+ ret.nPos = nDataPos;
228
232
}
229
233
return ret;
230
234
}
231
235
232
- FlatFilePos GetUndoPos () const {
236
+ FlatFilePos GetUndoPos () const
237
+ {
233
238
FlatFilePos ret;
234
239
if (nStatus & BLOCK_HAVE_UNDO) {
235
240
ret.nFile = nFile;
236
- ret.nPos = nUndoPos;
241
+ ret.nPos = nUndoPos;
237
242
}
238
243
return ret;
239
244
}
240
245
241
246
CBlockHeader GetBlockHeader () const
242
247
{
243
248
CBlockHeader block;
244
- block.nVersion = nVersion;
249
+ block.nVersion = nVersion;
245
250
if (pprev)
246
251
block.hashPrevBlock = pprev->GetBlockHash ();
247
252
block.hashMerkleRoot = hashMerkleRoot;
248
- block.nTime = nTime;
249
- block.nBits = nBits;
250
- block.nNonce = nNonce;
253
+ block.nTime = nTime;
254
+ block.nBits = nBits;
255
+ block.nNonce = nNonce;
251
256
return block;
252
257
}
253
258
@@ -288,7 +293,7 @@ class CBlockIndex
288
293
*(--pbegin) = pindex->GetBlockTime ();
289
294
290
295
std::sort (pbegin, pend);
291
- return pbegin[(pend - pbegin)/ 2 ];
296
+ return pbegin[(pend - pbegin) / 2 ];
292
297
}
293
298
294
299
std::string ToString () const
@@ -353,11 +358,13 @@ class CDiskBlockIndex : public CBlockIndex
353
358
public:
354
359
uint256 hashPrev;
355
360
356
- CDiskBlockIndex () {
361
+ CDiskBlockIndex ()
362
+ {
357
363
hashPrev = uint256 ();
358
364
}
359
365
360
- explicit CDiskBlockIndex (const CBlockIndex* pindex) : CBlockIndex(*pindex) {
366
+ explicit CDiskBlockIndex (const CBlockIndex* pindex) : CBlockIndex(*pindex)
367
+ {
361
368
hashPrev = (pprev ? pprev->GetBlockHash () : uint256 ());
362
369
}
363
370
@@ -385,12 +392,12 @@ class CDiskBlockIndex : public CBlockIndex
385
392
uint256 GetBlockHash () const
386
393
{
387
394
CBlockHeader block;
388
- block.nVersion = nVersion;
389
- block.hashPrevBlock = hashPrev;
390
- block.hashMerkleRoot = hashMerkleRoot;
391
- block.nTime = nTime;
392
- block.nBits = nBits;
393
- block.nNonce = nNonce;
395
+ block.nVersion = nVersion;
396
+ block.hashPrevBlock = hashPrev;
397
+ block.hashMerkleRoot = hashMerkleRoot;
398
+ block.nTime = nTime;
399
+ block.nBits = nBits;
400
+ block.nNonce = nNonce;
394
401
return block.GetHash ();
395
402
}
396
403
@@ -407,7 +414,8 @@ class CDiskBlockIndex : public CBlockIndex
407
414
};
408
415
409
416
/* * An in-memory indexed chain of blocks. */
410
- class CChain {
417
+ class CChain
418
+ {
411
419
private:
412
420
std::vector<CBlockIndex*> vChain;
413
421
@@ -417,48 +425,54 @@ class CChain {
417
425
CChain& operator =(const CChain&) = delete ;
418
426
419
427
/* * Returns the index entry for the genesis block of this chain, or nullptr if none. */
420
- CBlockIndex *Genesis () const {
428
+ CBlockIndex* Genesis () const
429
+ {
421
430
return vChain.size () > 0 ? vChain[0 ] : nullptr ;
422
431
}
423
432
424
433
/* * Returns the index entry for the tip of this chain, or nullptr if none. */
425
- CBlockIndex *Tip () const {
434
+ CBlockIndex* Tip () const
435
+ {
426
436
return vChain.size () > 0 ? vChain[vChain.size () - 1 ] : nullptr ;
427
437
}
428
438
429
439
/* * Returns the index entry at a particular height in this chain, or nullptr if no such height exists. */
430
- CBlockIndex *operator [](int nHeight) const {
440
+ CBlockIndex* operator [](int nHeight) const
441
+ {
431
442
if (nHeight < 0 || nHeight >= (int )vChain.size ())
432
443
return nullptr ;
433
444
return vChain[nHeight];
434
445
}
435
446
436
447
/* * Efficiently check whether a block is present in this chain. */
437
- bool Contains (const CBlockIndex *pindex) const {
448
+ bool Contains (const CBlockIndex* pindex) const
449
+ {
438
450
return (*this )[pindex->nHeight ] == pindex;
439
451
}
440
452
441
453
/* * Find the successor of a block in this chain, or nullptr if the given index is not found or is the tip. */
442
- CBlockIndex *Next (const CBlockIndex *pindex) const {
454
+ CBlockIndex* Next (const CBlockIndex* pindex) const
455
+ {
443
456
if (Contains (pindex))
444
457
return (*this )[pindex->nHeight + 1 ];
445
458
else
446
459
return nullptr ;
447
460
}
448
461
449
462
/* * Return the maximal height in the chain. Is equal to chain.Tip() ? chain.Tip()->nHeight : -1. */
450
- int Height () const {
463
+ int Height () const
464
+ {
451
465
return vChain.size () - 1 ;
452
466
}
453
467
454
468
/* * Set/initialize a chain with a given tip. */
455
- void SetTip (CBlockIndex * pindex);
469
+ void SetTip (CBlockIndex* pindex);
456
470
457
471
/* * Return a CBlockLocator that refers to a block in this chain (by default the tip). */
458
- CBlockLocator GetLocator (const CBlockIndex * pindex = nullptr ) const ;
472
+ CBlockLocator GetLocator (const CBlockIndex* pindex = nullptr ) const ;
459
473
460
474
/* * Find the last common block between this chain and a block index entry. */
461
- const CBlockIndex * FindFork (const CBlockIndex * pindex) const ;
475
+ const CBlockIndex* FindFork (const CBlockIndex* pindex) const ;
462
476
463
477
/* * Find the earliest block with timestamp equal or greater than the given time and height equal or greater than the given height. */
464
478
CBlockIndex* FindEarliestAtLeast (int64_t nTime, int height) const ;
0 commit comments