MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetDifficulty

Function GetDifficulty

src/rpc/blockchain.cpp:106–124  ·  view source on GitHub ↗

Calculate the difficulty for a given block index. */

Source from the content-addressed store, hash-verified

104/* Calculate the difficulty for a given block index.
105 */
106double GetDifficulty(const CBlockIndex& blockindex)
107{
108 int nShift = (blockindex.nBits >> 24) & 0xff;
109 double dDiff =
110 (double)0x0000ffff / (double)(blockindex.nBits & 0x00ffffff);
111
112 while (nShift < 29)
113 {
114 dDiff *= 256.0;
115 nShift++;
116 }
117 while (nShift > 29)
118 {
119 dDiff /= 256.0;
120 nShift--;
121 }
122
123 return dDiff;
124}
125
126static int ComputeNextBlockAndDepth(const CBlockIndex& tip, const CBlockIndex& blockindex, const CBlockIndex*& next)
127{

Callers 6

TestDifficultyFunction · 0.85
getmininginfoFunction · 0.85
blockheaderToJSONFunction · 0.85
getdifficultyFunction · 0.85
getblockchaininfoFunction · 0.85
getchainstatesFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestDifficultyFunction · 0.68