|
|
|
@ -11,6 +11,42 @@
@@ -11,6 +11,42 @@
|
|
|
|
|
using namespace json_spirit; |
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
// Litecoin: Return average network hashes per second based on last number of blocks.
|
|
|
|
|
Value GetNetworkHashPS(int lookup) { |
|
|
|
|
if (pindexBest == NULL) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
// If lookup is -1, then use blocks since last difficulty change.
|
|
|
|
|
if (lookup <= 0) |
|
|
|
|
lookup = pindexBest->nHeight % 2016 + 1; |
|
|
|
|
|
|
|
|
|
// If lookup is larger than chain, then set it to chain length.
|
|
|
|
|
if (lookup > pindexBest->nHeight) |
|
|
|
|
lookup = pindexBest->nHeight; |
|
|
|
|
|
|
|
|
|
CBlockIndex* pindexPrev = pindexBest; |
|
|
|
|
double sum = 0.0; |
|
|
|
|
for (int i = 0; i < lookup; i++) |
|
|
|
|
{ |
|
|
|
|
sum += (pindexPrev->GetBlockTime() - pindexPrev->pprev->GetBlockTime()) / GetDifficulty(pindexPrev); |
|
|
|
|
pindexPrev = pindexPrev->pprev; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return (boost::int64_t)(pow(2.0, 32) / (sum / lookup)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Value getnetworkhashps(const Array& params, bool fHelp) |
|
|
|
|
{ |
|
|
|
|
if (fHelp || params.size() > 1) |
|
|
|
|
throw runtime_error( |
|
|
|
|
"getnetworkhashps [blocks]\n" |
|
|
|
|
"Returns the estimated network hashes per second based on the last 120 blocks.\n" |
|
|
|
|
"Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change."); |
|
|
|
|
|
|
|
|
|
return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 120); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Value getgenerate(const Array& params, bool fHelp) |
|
|
|
|
{ |
|
|
|
|
if (fHelp || params.size() != 0) |
|
|
|
@ -77,6 +113,7 @@ Value getmininginfo(const Array& params, bool fHelp)
@@ -77,6 +113,7 @@ Value getmininginfo(const Array& params, bool fHelp)
|
|
|
|
|
obj.push_back(Pair("generate", GetBoolArg("-gen"))); |
|
|
|
|
obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1))); |
|
|
|
|
obj.push_back(Pair("hashespersec", gethashespersec(params, false))); |
|
|
|
|
obj.push_back(Pair("networkhashps", getnetworkhashps(params, false))); |
|
|
|
|
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); |
|
|
|
|
obj.push_back(Pair("testnet", fTestNet)); |
|
|
|
|
return obj; |
|
|
|
|