Fix GetDifficulty

This commit is contained in:
myriadcoin
2014-09-26 02:15:48 +02:00
parent af187c9c36
commit e580967a54
2 changed files with 8 additions and 5 deletions
+6 -5
View File
@@ -20,16 +20,17 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeH
double GetDifficulty(const CBlockIndex* blockindex, int algo)
{
unsigned int nBits;
// Floating point number that is a multiple of the minimum difficulty,
// minimum difficulty = 1.0.
if (blockindex == NULL)
{
if (chainActive.Tip() == NULL)
CBlockIndex* tip = chainActive.Tip();
if (tip == NULL)
nBits = Params().ProofOfWorkLimit(ALGO_SHA256D).GetCompact();
else
{
blockindex = GetLastBlockIndexForAlgo(chainActive.Tip(), algo);
blockindex = GetLastBlockIndexForAlgo(tip, algo);
if (blockindex == NULL)
nBits = Params().ProofOfWorkLimit(algo).GetCompact();
else
@@ -38,11 +39,11 @@ double GetDifficulty(const CBlockIndex* blockindex, int algo)
}
else
nBits = blockindex->nBits;
int nShift = (nBits >> 24) & 0xff;
double dDiff =
(double)0x0000ffff / (double)(blockindex->nBits & 0x00ffffff);
(double)0x0000ffff / (double)(nBits & 0x00ffffff);
while (nShift < 29)
{
+2
View File
@@ -81,6 +81,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("difficulty_skein", (double)GetDifficulty(NULL, ALGO_SKEIN)));
obj.push_back(Pair("difficulty_qubit", (double)GetDifficulty(NULL, ALGO_QUBIT)));
obj.push_back(Pair("testnet", TestNet()));
#ifdef ENABLE_WALLET
if (pwalletMain) {
obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime()));
@@ -92,6 +93,7 @@ Value getinfo(const Array& params, bool fHelp)
#endif
obj.push_back(Pair("relayfee", ValueFromAmount(CTransaction::nMinRelayTxFee)));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
return obj;
}