Skip to content

Commit

Permalink
Check networkhashps
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo authored and Lorenzo committed Mar 11, 2015
1 parent 5d28406 commit 5263492
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 0 deletions.
Binary file modified src/qt/res/icons/ecurrency.ico
100755 → 100644
Binary file not shown.
Binary file modified src/qt/res/icons/ecurrency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/qt/res/icons/ecurrency_testnet.ico
100755 → 100644
Binary file not shown.
Binary file modified src/qt/res/icons/ecurrency_testnet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/qt/res/icons/toolbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/qt/res/images/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/qt/res/images/splash_testnet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,55 @@
using namespace json_spirit;
using namespace std;

Value GetNetworkHashPS(int lookup, int height) {
CBlockIndex *pb = pindexBest;

if (height >= 0 && height < nBestHeight)
pb = FindBlockByHeight(height);

if (pb == NULL || !pb->nHeight)
return 0;

// If lookup is -1, then use blocks since last difficulty change.
if (lookup <= 0)
lookup = pb->nHeight % 2016 + 1;

// If lookup is larger than chain, then set it to chain length.
if (lookup > pb->nHeight)
lookup = pb->nHeight;

CBlockIndex *pb0 = pb;
int64 minTime = pb0->GetBlockTime();
int64 maxTime = minTime;
for (int i = 0; i < lookup; i++) {
pb0 = pb0->pprev;
int64 time = pb0->GetBlockTime();
minTime = std::min(time, minTime);
maxTime = std::max(time, maxTime);
}

// In case there's a situation where minTime == maxTime, we don't want a divide by zero exception.
if (minTime == maxTime)
return 0;

uint256 workDiff = pb->nChainWork - pb0->nChainWork;
int64 timeDiff = maxTime - minTime;

return (boost::int64_t)(workDiff.getdouble() / timeDiff);
}

Value getnetworkhashps(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 2)
throw runtime_error(
"getnetworkhashps [blocks] [height]\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.\n"
"Pass in [height] to estimate the network speed at the time when a certain block was found.");

return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 120, params.size() > 1 ? params[1].get_int() : -1);
}

Value getgenerate(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
Expand Down Expand Up @@ -77,6 +126,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;
Expand Down

0 comments on commit 5263492

Please sign in to comment.