mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
merge bitcoin#23769: Disallow copies of CChain
This commit is contained in:
parent
5b66688160
commit
b4bfacfd24
54
src/chain.h
54
src/chain.h
@ -59,7 +59,8 @@ public:
|
||||
READWRITE(VARINT(obj.nTimeLast));
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
void SetNull()
|
||||
{
|
||||
nBlocks = 0;
|
||||
nSize = 0;
|
||||
nUndoSize = 0;
|
||||
@ -69,17 +70,19 @@ public:
|
||||
nTimeLast = 0;
|
||||
}
|
||||
|
||||
CBlockFileInfo() {
|
||||
CBlockFileInfo()
|
||||
{
|
||||
SetNull();
|
||||
}
|
||||
|
||||
std::string ToString() const;
|
||||
|
||||
/** update statistics (does not update nSize) */
|
||||
void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn) {
|
||||
if (nBlocks==0 || nHeightFirst > nHeightIn)
|
||||
void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn)
|
||||
{
|
||||
if (nBlocks == 0 || nHeightFirst > nHeightIn)
|
||||
nHeightFirst = nHeightIn;
|
||||
if (nBlocks==0 || nTimeFirst > nTimeIn)
|
||||
if (nBlocks == 0 || nTimeFirst > nTimeIn)
|
||||
nTimeFirst = nTimeIn;
|
||||
nBlocks++;
|
||||
if (nHeightIn > nHeightLast)
|
||||
@ -89,7 +92,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
enum BlockStatus: uint32_t {
|
||||
enum BlockStatus : uint32_t {
|
||||
//! Unused.
|
||||
BLOCK_VALID_UNKNOWN = 0,
|
||||
|
||||
@ -293,7 +296,7 @@ public:
|
||||
*(--pbegin) = pindex->GetBlockTime();
|
||||
|
||||
std::sort(pbegin, pend);
|
||||
return pbegin[(pend - pbegin)/2];
|
||||
return pbegin[(pend - pbegin) / 2];
|
||||
}
|
||||
|
||||
std::string ToString() const;
|
||||
@ -360,12 +363,14 @@ public:
|
||||
uint256 hash;
|
||||
uint256 hashPrev;
|
||||
|
||||
CDiskBlockIndex() {
|
||||
CDiskBlockIndex()
|
||||
{
|
||||
hash = uint256();
|
||||
hashPrev = uint256();
|
||||
}
|
||||
|
||||
explicit CDiskBlockIndex(const CBlockIndex* pindex) : CBlockIndex(*pindex) {
|
||||
explicit CDiskBlockIndex(const CBlockIndex* pindex) : CBlockIndex(*pindex)
|
||||
{
|
||||
hash = (hash == uint256() ? pindex->GetBlockHash() : hash);
|
||||
hashPrev = (pprev ? pprev->GetBlockHash() : uint256());
|
||||
}
|
||||
@ -413,35 +418,45 @@ public:
|
||||
};
|
||||
|
||||
/** An in-memory indexed chain of blocks. */
|
||||
class CChain {
|
||||
class CChain
|
||||
{
|
||||
private:
|
||||
std::vector<CBlockIndex*> vChain;
|
||||
|
||||
public:
|
||||
CChain() = default;
|
||||
CChain(const CChain&) = delete;
|
||||
CChain& operator=(const CChain&) = delete;
|
||||
|
||||
/** Returns the index entry for the genesis block of this chain, or nullptr if none. */
|
||||
CBlockIndex *Genesis() const {
|
||||
CBlockIndex* Genesis() const
|
||||
{
|
||||
return vChain.size() > 0 ? vChain[0] : nullptr;
|
||||
}
|
||||
|
||||
/** Returns the index entry for the tip of this chain, or nullptr if none. */
|
||||
CBlockIndex *Tip() const {
|
||||
CBlockIndex* Tip() const
|
||||
{
|
||||
return vChain.size() > 0 ? vChain[vChain.size() - 1] : nullptr;
|
||||
}
|
||||
|
||||
/** Returns the index entry at a particular height in this chain, or nullptr if no such height exists. */
|
||||
CBlockIndex *operator[](int nHeight) const {
|
||||
CBlockIndex* operator[](int nHeight) const
|
||||
{
|
||||
if (nHeight < 0 || nHeight >= (int)vChain.size())
|
||||
return nullptr;
|
||||
return vChain[nHeight];
|
||||
}
|
||||
|
||||
/** Efficiently check whether a block is present in this chain. */
|
||||
bool Contains(const CBlockIndex *pindex) const {
|
||||
bool Contains(const CBlockIndex* pindex) const
|
||||
{
|
||||
return (*this)[pindex->nHeight] == pindex;
|
||||
}
|
||||
|
||||
/** Find the successor of a block in this chain, or nullptr if the given index is not found or is the tip. */
|
||||
CBlockIndex *Next(const CBlockIndex *pindex) const {
|
||||
CBlockIndex* Next(const CBlockIndex* pindex) const
|
||||
{
|
||||
if (Contains(pindex))
|
||||
return (*this)[pindex->nHeight + 1];
|
||||
else
|
||||
@ -449,18 +464,19 @@ public:
|
||||
}
|
||||
|
||||
/** Return the maximal height in the chain. Is equal to chain.Tip() ? chain.Tip()->nHeight : -1. */
|
||||
int Height() const {
|
||||
int Height() const
|
||||
{
|
||||
return vChain.size() - 1;
|
||||
}
|
||||
|
||||
/** Set/initialize a chain with a given tip. */
|
||||
void SetTip(CBlockIndex *pindex);
|
||||
void SetTip(CBlockIndex* pindex);
|
||||
|
||||
/** Return a CBlockLocator that refers to a block in this chain (by default the tip). */
|
||||
CBlockLocator GetLocator(const CBlockIndex *pindex = nullptr) const;
|
||||
CBlockLocator GetLocator(const CBlockIndex* pindex = nullptr) const;
|
||||
|
||||
/** Find the last common block between this chain and a block index entry. */
|
||||
const CBlockIndex *FindFork(const CBlockIndex *pindex) const;
|
||||
const CBlockIndex* FindFork(const CBlockIndex* pindex) const;
|
||||
|
||||
/** Find the earliest block with timestamp equal or greater than the given time and height equal or greater than the given height. */
|
||||
CBlockIndex* FindEarliestAtLeast(int64_t nTime, int height) const;
|
||||
|
Loading…
Reference in New Issue
Block a user