| 1206 | |
| 1207 | #ifdef ENABLE_WALLET |
| 1208 | UniValue getstakingstatus(const UniValue& params, bool fHelp) |
| 1209 | { |
| 1210 | if (fHelp || params.size() != 0) |
| 1211 | throw runtime_error( |
| 1212 | "getstakingstatus\n" |
| 1213 | "Returns an object containing various staking information.\n" |
| 1214 | "\nResult:\n" |
| 1215 | "{\n" |
| 1216 | " \"staking\": true|false, (boolean) if the wallet is staking or not\n" |
| 1217 | " \"validtime\": true|false, (boolean) if the chain tip is within staking phases\n" |
| 1218 | " \"haveconnections\": true|false, (boolean) if network connections are present\n" |
| 1219 | " \"walletunlocked\": true|false, (boolean) if the wallet is unlocked\n" |
| 1220 | " \"mintablecoins\": true|false, (boolean) if the wallet has mintable coins\n" |
| 1221 | " \"enoughcoins\": true|false, (boolean) if available coins are greater than reserve balance\n" |
| 1222 | " \"stakeweight\": {\n" |
| 1223 | " \"min\": X, (integer) min weight of staked coin\n" |
| 1224 | " \"max\": X, (integer) max weight of staked coin\n" |
| 1225 | " \"combined\": X, (integer) sum of weights of staked coins\n" |
| 1226 | " \"valuesum\": X, (integer) sum of values of staked coins\n" |
| 1227 | " },\n" |
| 1228 | " \"stakeblockscreated\": X, (integer) number of stake blocks created\n" |
| 1229 | " \"stakeblocksaccepted\": X, (integer) number of stake blocks accepted\n" |
| 1230 | " \"foundstake\": X, (integer) number of stake kernels found\n" |
| 1231 | " \"difficulty\": X, (integer) Returns the proof-of-stake difficulty as a multiple of the minimum difficulty. \n" |
| 1232 | " \"beststakediff\": X.X, (double) best diff of staked coins\n" |
| 1233 | " \"sumdiff\": X.X, (double) sum of diff of staked coins\n" |
| 1234 | " \"netstakeweight\": X, (integer) estimated network weight\n" |
| 1235 | " \"expectedtime\": X (integer) expected time to stake in seconds\n" |
| 1236 | "}\n" |
| 1237 | "\nExamples:\n" + |
| 1238 | HelpExampleCli("getstakingstatus", "") + HelpExampleRpc("getstakingstatus", "")); |
| 1239 | |
| 1240 | UniValue obj(UniValue::VOBJ); |
| 1241 | obj.push_back(Pair("staking", stake->IsActive())); |
| 1242 | obj.push_back(Pair("validtime", chainActive.Tip()->nTime > 1471482000)); |
| 1243 | obj.push_back(Pair("haveconnections", !vNodes.empty())); |
| 1244 | if (pwalletMain) { |
| 1245 | obj.push_back(Pair("walletunlocked", !pwalletMain->IsLocked())); |
| 1246 | obj.push_back(Pair("mintablecoins", pwalletMain->MintableCoins())); |
| 1247 | obj.push_back(Pair("enoughcoins", (stake->GetReservedBalance() <= pwalletMain->GetBalance() ? "yes" : "no"))); |
| 1248 | } |
| 1249 | uint64_t nWeight = 0; |
| 1250 | if (pwalletMain) |
| 1251 | pwalletMain->GetStakeWeight(nWeight); |
| 1252 | uint64_t nNetworkWeight = GetPoSKernelPS(); |
| 1253 | int64_t nTargetSpacing = Params().StakingInterval(); |
| 1254 | uint64_t nExpectedTime = nWeight != 0 ? (nTargetSpacing * nNetworkWeight / nWeight) : 0; |
| 1255 | UniValue weight(UniValue::VOBJ); |
| 1256 | { |
| 1257 | LOCK(stake->stakeMiner.lock); |
| 1258 | weight.pushKV("min", stake->stakeMiner.nWeightMin); |
| 1259 | weight.pushKV("max", stake->stakeMiner.nWeightMax); |
| 1260 | weight.pushKV("combined", stake->stakeMiner.nWeightSum); |
| 1261 | weight.pushKV("valuesum", stake->stakeMiner.dValueSum); |
| 1262 | obj.pushKV("stakeweight", weight); |
| 1263 | obj.pushKV("stakeblockscreated", stake->stakeMiner.nBlocksCreated); |
| 1264 | obj.pushKV("stakeblocksaccepted", stake->stakeMiner.nBlocksAccepted); |
| 1265 | obj.pushKV("foundstake", stake->stakeMiner.nKernelsFound); |
nothing calls this directly
no test coverage detected