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

Function GetDifficulty

src/rpc/blockchain.cpp:59–95  ·  view source on GitHub ↗

Calculate the difficulty for a given block index. */

Source from the content-addressed store, hash-verified

57/* Calculate the difficulty for a given block index.
58 */
59double GetDifficulty(const CBlockIndex* blockindex)
60{
61 if (blockindex == nullptr)
62 {
63 return 1.0;
64 }
65
66 // Floating point number that is a multiple of the minimum difficulty,
67 // minimum difficulty = 1.0.
68
69 uint32_t bits = blockindex->nBits;
70 uint32_t powLimit = 0;
71
72 if (blockindex->nHeight >= Params().GetConsensus().BTGHeight) {
73 powLimit = UintToArith256(Params().GetConsensus().powLimit).GetCompact();
74 } else {
75 powLimit = 0x1d00ffff;
76 }
77
78 int nShift = (bits >> 24) & 0xff;
79 int nShiftAmount = (powLimit >> 24) & 0xff;
80
81 double dDiff = (double)(powLimit & 0x00ffffff) / (double)(bits & 0x00ffffff);
82
83 while (nShift < nShiftAmount)
84 {
85 dDiff *= 256.0;
86 nShift++;
87 }
88 while (nShift > nShiftAmount)
89 {
90 dDiff /= 256.0;
91 nShift--;
92 }
93
94 return dDiff;
95}
96
97UniValue blockheaderToJSON(const CBlockIndex* blockindex)
98{

Callers 7

TestDifficultyFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
getmininginfoFunction · 0.85
blockheaderToJSONFunction · 0.85
blockToJSONFunction · 0.85
getdifficultyFunction · 0.85
getblockchaininfoFunction · 0.85

Calls 3

UintToArith256Function · 0.85
GetCompactMethod · 0.80
ParamsClass · 0.50

Tested by 2

TestDifficultyFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68