Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show All 36 Lines | struct CUpdatedBlock { | ||||
uint256 hash; | uint256 hash; | ||||
int height; | int height; | ||||
}; | }; | ||||
static Mutex cs_blockchange; | static Mutex cs_blockchange; | ||||
static std::condition_variable cond_blockchange; | static std::condition_variable cond_blockchange; | ||||
static CUpdatedBlock latestblock; | static CUpdatedBlock latestblock; | ||||
static double GetDifficultyFromBits(uint32_t nBits) { | /** | ||||
int nShift = (nBits >> 24) & 0xff; | * Calculate the difficulty for a given block index. | ||||
double dDiff = 0x0000ffff / double(nBits & 0x00ffffff); | */ | ||||
double GetDifficulty(const CBlockIndex *blockindex) { | |||||
assert(blockindex); | |||||
int nShift = (blockindex->nBits >> 24) & 0xff; | |||||
double dDiff = double(0x0000ffff) / double(blockindex->nBits & 0x00ffffff); | |||||
while (nShift < 29) { | while (nShift < 29) { | ||||
dDiff *= 256.0; | dDiff *= 256.0; | ||||
nShift++; | nShift++; | ||||
} | } | ||||
while (nShift > 29) { | while (nShift > 29) { | ||||
dDiff /= 256.0; | dDiff /= 256.0; | ||||
nShift--; | nShift--; | ||||
} | } | ||||
return dDiff; | return dDiff; | ||||
} | } | ||||
double GetDifficulty(const CBlockIndex *blockindex) { | |||||
assert(blockindex); | |||||
return GetDifficultyFromBits(blockindex->nBits); | |||||
} | |||||
static int ComputeNextBlockAndDepth(const CBlockIndex *tip, | static int ComputeNextBlockAndDepth(const CBlockIndex *tip, | ||||
const CBlockIndex *blockindex, | const CBlockIndex *blockindex, | ||||
const CBlockIndex *&next) { | const CBlockIndex *&next) { | ||||
next = tip->GetAncestor(blockindex->nHeight + 1); | next = tip->GetAncestor(blockindex->nHeight + 1); | ||||
if (next && next->pprev == blockindex) { | if (next && next->pprev == blockindex) { | ||||
return tip->nHeight - blockindex->nHeight + 1; | return tip->nHeight - blockindex->nHeight + 1; | ||||
} | } | ||||
next = nullptr; | next = nullptr; | ||||
▲ Show 20 Lines • Show All 1,858 Lines • Show Last 20 Lines |