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) { | /* Calculate the difficulty for a given block index. | ||||
int nShift = (nBits >> 24) & 0xff; | */ | ||||
jasonbcox: Fix comment style:
```
/**
* First line...
*/
``` | |||||
double dDiff = 0x0000ffff / double(nBits & 0x00ffffff); | double GetDifficulty(const CBlockIndex *blockindex) { | ||||
assert(blockindex); | |||||
int nShift = (blockindex->nBits >> 24) & 0xff; | |||||
schancelUnsubmitted Done Inline Actionsuint32_t nbits = blockindex->nBits; and leave the other two things alone. schancel: `uint32_t nbits = blockindex->nBits;` and leave the other two things alone. | |||||
markblundebergAuthorUnsubmitted Done Inline ActionsI agree but just want to get this backported for now. markblundeberg: I agree but just want to get this backported for now. | |||||
jasonbcoxUnsubmitted Done Inline ActionsAlso agree. Taking ownership of this code is not wise if we can avoid it. jasonbcox: Also agree. Taking ownership of this code is not wise if we can avoid it. | |||||
double dDiff = | |||||
(double)0x0000ffff / (double)(blockindex->nBits & 0x00ffffff); | |||||
jasonbcoxUnsubmitted Done Inline Actionscasting style should be: double(...) like a function call jasonbcox: casting style should be: `double(...)` like a function call | |||||
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,855 Lines • Show Last 20 Lines |
Fix comment style: