MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / CDiskBlockIndex

Class CDiskBlockIndex

src/chain.h:399–468  ·  view source on GitHub ↗

Used to marshal pointers into hashes for db storage. */

Source from the content-addressed store, hash-verified

397
398/** Used to marshal pointers into hashes for db storage. */
399class CDiskBlockIndex : public CBlockIndex
400{
401public:
402 uint256 hashPrev;
403
404 CDiskBlockIndex() {
405 hashPrev = uint256();
406 }
407
408 explicit CDiskBlockIndex(const CBlockIndex* pindex) : CBlockIndex(*pindex) {
409 hashPrev = (pprev ? pprev->GetBlockHash() : uint256());
410 }
411
412 ADD_SERIALIZE_METHODS;
413
414 template <typename Stream, typename Operation>
415 inline void SerializationOp(Stream& s, Operation ser_action) {
416 int _nVersion = s.GetVersion();
417 if (!(s.GetType() & SER_GETHASH))
418 READWRITE(VARINT(_nVersion, VarIntMode::NONNEGATIVE_SIGNED));
419
420 READWRITE(VARINT(nHeight, VarIntMode::NONNEGATIVE_SIGNED));
421 READWRITE(VARINT(nStatus));
422 READWRITE(VARINT(nTx));
423 if (nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO))
424 READWRITE(VARINT(nFile, VarIntMode::NONNEGATIVE_SIGNED));
425 if (nStatus & BLOCK_HAVE_DATA)
426 READWRITE(VARINT(nDataPos));
427 if (nStatus & BLOCK_HAVE_UNDO)
428 READWRITE(VARINT(nUndoPos));
429
430 // block header
431 READWRITE(this->nVersion);
432 READWRITE(hashPrev);
433 READWRITE(hashMerkleRoot);
434 for(size_t i = 0; i < (sizeof(nReserved) / sizeof(nReserved[0])); i++) {
435 READWRITE(nReserved[i]);
436 }
437 READWRITE(nTime);
438 READWRITE(nBits);
439 READWRITE(nNonce);
440 READWRITE(nSolution);
441 }
442
443 uint256 GetBlockHash() const
444 {
445 CBlockHeader block;
446 block.nVersion = nVersion;
447 block.hashPrevBlock = hashPrev;
448 block.hashMerkleRoot = hashMerkleRoot;
449 block.nHeight = nHeight;
450 memcpy(block.nReserved, nReserved, sizeof(block.nReserved));
451 block.nTime = nTime;
452 block.nBits = nBits;
453 block.nNonce = nNonce;
454 block.nSolution = nSolution;
455 return block.GetHash();
456 }

Callers 1

WriteBatchSyncMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected