Skip to content

Commit

Permalink
Add network hash per sec to getinfo.
Browse files Browse the repository at this point in the history
This shows the estimated network hashrate by looking at the past 120 blocks.
  • Loading branch information
coblee committed Oct 10, 2011
1 parent a2e7991 commit 1a4faf7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,27 @@ double GetDifficulty()
return dDiff;
}

// Litecoin: Return average network hashes per second based on last number of blocks.
int GetNetworkHashPS() {
if (pindexBest == NULL)
return 0;

// Use the last 120 blocks.
int lookup = 120;

if (pindexBest->nHeight <= lookup)
return 0;

CBlockIndex* pindexPrev = pindexBest;
for (int i = 0; i < lookup; i++)
pindexPrev = pindexPrev->pprev;

int64 timeDiff = pindexBest->GetBlockTime() - pindexPrev->GetBlockTime();
int64 timePerBlock = timeDiff / lookup;

return GetDifficulty() * pow(2.0, 32) / timePerBlock;
}

Value getdifficulty(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
Expand Down Expand Up @@ -306,6 +327,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("genproclimit", (int)(fLimitProcessors ? nLimitProcessors : -1)));
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
obj.push_back(Pair("networkhashps", (int)GetNetworkHashPS()));
obj.push_back(Pair("testnet", fTestNet));
obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime()));
obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize()));
Expand Down

0 comments on commit 1a4faf7

Please sign in to comment.