From 092c9ae7e73f2751b94d3ef6d7e95fc2f82526a5 Mon Sep 17 00:00:00 2001 From: janko33bd Date: Mon, 3 Jul 2017 22:24:04 +0200 Subject: [PATCH] adding staking info and checkkernel --- src/rpcmining.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/rpcserver.cpp | 2 ++ src/rpcserver.h | 3 +++ 3 files changed, 41 insertions(+) diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 8b540f1ee..50c4028e8 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -274,6 +274,42 @@ UniValue getmininginfo(const UniValue& params, bool fHelp) return obj; } +UniValue getstakinginfo(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getstakinginfo\n" + "Returns an object containing staking-related information."); + + uint64_t nWeight = 0; + if (pwalletMain) + nWeight = pwalletMain->GetStakeWeight(); + + uint64_t nNetworkWeight = GetPoSKernelPS(); + bool staking = nLastCoinStakeSearchInterval && nWeight; + uint64_t nExpectedTime = staking ? 1.0455 * 64 * nNetworkWeight / nWeight : 0; + + UniValue obj(UniValue::VOBJ); + + obj.push_back(Pair("enabled", GetBoolArg("-staking", true))); + obj.push_back(Pair("staking", staking)); + obj.push_back(Pair("errors", GetWarnings("statusbar"))); + + obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize)); + obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx)); + obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); + + obj.push_back(Pair("difficulty", GetDifficulty(GetLastBlockIndex(chainActive.Tip(), true)))); + obj.push_back(Pair("search-interval", (int)nLastCoinStakeSearchInterval)); + + obj.push_back(Pair("weight", (uint64_t)nWeight)); + obj.push_back(Pair("netstakeweight", (uint64_t)nNetworkWeight)); + + obj.push_back(Pair("expectedtime", nExpectedTime)); + + return obj; +} + // NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts UniValue prioritisetransaction(const UniValue& params, bool fHelp) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 207be5b5a..24ba7d099 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -383,6 +383,8 @@ static const CRPCCommand vRPCCommands[] = { "wallet", "walletlock", &walletlock, true }, { "wallet", "walletpassphrasechange", &walletpassphrasechange, true }, { "wallet", "walletpassphrase", &walletpassphrase, true }, + { "wallet", "checkkernel", &checkkernel, true }, + { "wallet", "getstakinginfo", &getstakinginfo, true }, #endif // ENABLE_WALLET }; diff --git a/src/rpcserver.h b/src/rpcserver.h index ab1604697..50846fd1e 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -159,6 +159,7 @@ extern int64_t nWalletUnlockTime; extern CAmount AmountFromValue(const UniValue& value); extern UniValue ValueFromAmount(const CAmount& amount); extern double GetDifficulty(const CBlockIndex* blockindex = NULL); +extern double GetPoSKernelPS(); extern std::string HelpRequiringPassphrase(); extern std::string HelpExampleCli(const std::string& methodname, const std::string& args); extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args); @@ -201,6 +202,8 @@ extern UniValue estimatefee(const UniValue& params, bool fHelp); extern UniValue estimatepriority(const UniValue& params, bool fHelp); extern UniValue estimatesmartfee(const UniValue& params, bool fHelp); extern UniValue estimatesmartpriority(const UniValue& params, bool fHelp); +extern UniValue checkkernel(const UniValue& params, bool fHelp); +extern UniValue getstakinginfo(const UniValue& params, bool fHelp); extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp extern UniValue getaccountaddress(const UniValue& params, bool fHelp);