Browse Source

Litecoin: getnetworkhashps

0.8
coblee 12 years ago committed by Warren Togami
parent
commit
3da6dc7302
  1. 2
      src/bitcoinrpc.cpp
  2. 1
      src/bitcoinrpc.h
  3. 37
      src/rpcmining.cpp

2
src/bitcoinrpc.cpp

@ -207,6 +207,7 @@ static const CRPCCommand vRPCCommands[] = @@ -207,6 +207,7 @@ static const CRPCCommand vRPCCommands[] =
{ "addnode", &addnode, true, true },
{ "getaddednodeinfo", &getaddednodeinfo, true, true },
{ "getdifficulty", &getdifficulty, true, false },
{ "getnetworkhashps", &getnetworkhashps, true, false },
{ "getgenerate", &getgenerate, true, false },
{ "setgenerate", &setgenerate, true, false },
{ "gethashespersec", &gethashespersec, true, false },
@ -1145,6 +1146,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri @@ -1145,6 +1146,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "getaddednodeinfo" && n > 0) ConvertTo<bool>(params[0]);
if (strMethod == "setgenerate" && n > 0) ConvertTo<bool>(params[0]);
if (strMethod == "setgenerate" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "getnetworkhashps" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]);
if (strMethod == "settxfee" && n > 0) ConvertTo<double>(params[0]);
if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<boost::int64_t>(params[1]);

1
src/bitcoinrpc.h

@ -142,6 +142,7 @@ extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool f @@ -142,6 +142,7 @@ extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool f
extern json_spirit::Value getgenerate(const json_spirit::Array& params, bool fHelp); // in rpcmining.cpp
extern json_spirit::Value setgenerate(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getnetworkhashps(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value gethashespersec(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getwork(const json_spirit::Array& params, bool fHelp);

37
src/rpcmining.cpp

@ -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;

Loading…
Cancel
Save