mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 21:42:47 +01:00
Litecoin: getnetworkhashps
This commit is contained in:
parent
0b646aed42
commit
3da6dc7302
@ -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
|
||||
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]);
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
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…
Reference in New Issue
Block a user