Skip to content

Commit

Permalink
[RPC] Fix getstakingstatus removing compile-time conditional
Browse files Browse the repository at this point in the history
The call is already wrapped in it, no need to check a second time.
Further, since the status is get from pwalletMain, throw if it is not
loaded.

Also move the staking status inside if(pwalletMain) in getinfo
Github-Pull: #1245
Rebased-From: 3893739
  • Loading branch information
random-zebra authored and Fuzzbawls committed Jan 11, 2020
1 parent 876d393 commit a80e2e9
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,19 @@ UniValue getinfo(const UniValue& params, bool fHelp)

"\nResult:\n"
"{\n"
" \"version\": xxxxx, (numeric) the server version\n"
" \"protocolversion\": xxxxx, (numeric) the protocol version\n"
" \"walletversion\": xxxxx, (numeric) the wallet version\n"
" \"balance\": xxxxxxx, (numeric) the total pivx balance of the wallet (excluding zerocoins)\n"
" \"zerocoinbalance\": xxxxxxx, (numeric) the total zerocoin balance of the wallet\n"
" \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
" \"timeoffset\": xxxxx, (numeric) the time offset\n"
" \"connections\": xxxxx, (numeric) the number of connections\n"
" \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
" \"testnet\": true|false, (boolean) if the server is using testnet or not\n"
" \"moneysupply\" : \"supply\" (numeric) The money supply when this block was added to the blockchain\n"
" \"version\": xxxxx, (numeric) the server version\n"
" \"protocolversion\": xxxxx, (numeric) the protocol version\n"
" \"walletversion\": xxxxx, (numeric) the wallet version\n"
" \"balance\": xxxxxxx, (numeric) the total pivx balance of the wallet (excluding zerocoins)\n"
" \"zerocoinbalance\": xxxxxxx, (numeric) the total zerocoin balance of the wallet\n"
" \"staking status\": true|false, (boolean) if the wallet is staking or not\n"
" \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
" \"timeoffset\": xxxxx, (numeric) the time offset\n"
" \"connections\": xxxxx, (numeric) the number of connections\n"
" \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
" \"testnet\": true|false, (boolean) if the server is using testnet or not\n"
" \"moneysupply\" : \"supply\" (numeric) The money supply when this block was added to the blockchain\n"
" \"zPIVsupply\" :\n"
" {\n"
" \"1\" : n, (numeric) supply of 1 zPIV denomination\n"
Expand All @@ -76,13 +77,12 @@ UniValue getinfo(const UniValue& params, bool fHelp)
" \"5000\" : n, (numeric) supply of 5000 zPIV denomination\n"
" \"total\" : n, (numeric) The total supply of all zPIV denominations\n"
" }\n"
" \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
" \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
" \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
" \"paytxfee\": x.xxxx, (numeric) the transaction fee set in pivx/kb\n"
" \"relayfee\": x.xxxx, (numeric) minimum relay fee for non-free transactions in pivx/kb\n"
" \"staking status\": true|false, (boolean) if the wallet is staking or not\n"
" \"errors\": \"...\" (string) any error messages\n"
" \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
" \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
" \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
" \"paytxfee\": x.xxxx, (numeric) the transaction fee set in pivx/kb\n"
" \"relayfee\": x.xxxx, (numeric) minimum relay fee for non-free transactions in pivx/kb\n"
" \"errors\": \"...\" (string) any error messages\n"
"}\n"

"\nExamples:\n" +
Expand Down Expand Up @@ -127,6 +127,9 @@ UniValue getinfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
obj.push_back(Pair("zerocoinbalance", ValueFromAmount(pwalletMain->GetZerocoinBalance(true))));
obj.push_back(Pair("staking status", (pwalletMain->pStakerStatus->IsActive() ?
"Staking Active" :
"Staking Not Active")));
}
#endif
obj.push_back(Pair("blocks", (int)chainActive.Height()));
Expand Down Expand Up @@ -160,9 +163,6 @@ UniValue getinfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
#endif
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
obj.push_back(Pair("staking status", (pwalletMain->pStakerStatus->IsActive() ?
"Staking Active" :
"Staking Not Active")));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
return obj;
}
Expand Down Expand Up @@ -598,10 +598,10 @@ UniValue getstakingstatus(const UniValue& params, bool fHelp)
" \"staking_enabled\": true|false, (boolean) if staking is enabled/disabled in pivx.conf\n"
" \"tiptime\": n, (integer) chain tip blocktime\n"
" \"haveconnections\": true|false, (boolean) if network connections are present\n"
" \"mnsync\": true|false, (boolean) if masternode data is synced\n"
" \"walletunlocked\": true|false, (boolean) if the wallet is unlocked\n"
" \"mintablecoins\": true|false, (boolean) if the wallet has mintable coins\n"
" \"enoughcoins\": true|false, (boolean) if available coins are greater than reserve balance\n"
" \"mnsync\": true|false, (boolean) if masternode data is synced\n"
" \"hashLastStakeAttempt\": xxx (hex string) hash of last block on top of which the miner attempted to stake\n"
" \"heightLastStakeAttempt\": n (integer) height of last block on top of which the miner attempted to stake\n"
" \"timeLastStakeAttempt\": n (integer) time of last attempted stake\n"
Expand All @@ -610,28 +610,28 @@ UniValue getstakingstatus(const UniValue& params, bool fHelp)
"\nExamples:\n" +
HelpExampleCli("getstakingstatus", "") + HelpExampleRpc("getstakingstatus", ""));

#ifdef ENABLE_WALLET
LOCK2(cs_main, pwalletMain ? &pwalletMain->cs_wallet : NULL);
#else
LOCK(cs_main);
#endif

UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("staking_status", pwalletMain->pStakerStatus->IsActive()));
obj.push_back(Pair("staking_enabled", GetBoolArg("-staking", true)));
obj.push_back(Pair("tiptime", (int)chainActive.Tip()->nTime));
obj.push_back(Pair("haveconnections", !vNodes.empty()));
if (pwalletMain) {
if (!pwalletMain)
throw JSONRPCError(RPC_IN_WARMUP, "Try again after active chain is loaded");
{
LOCK2(cs_main, &pwalletMain->cs_wallet);
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("staking_status", pwalletMain->pStakerStatus->IsActive()));
obj.push_back(Pair("staking_enabled", GetBoolArg("-staking", true)));
obj.push_back(Pair("tiptime", (int)chainActive.Tip()->nTime));
obj.push_back(Pair("haveconnections", !vNodes.empty()));
obj.push_back(Pair("mnsync", masternodeSync.IsSynced()));
obj.push_back(Pair("walletunlocked", !pwalletMain->IsLocked()));
obj.push_back(Pair("mintablecoins", pwalletMain->MintableCoins()));
obj.push_back(Pair("enoughcoins", nReserveBalance <= pwalletMain->GetStakingBalance(GetBoolArg("-coldstaking", true))));
uint256 lastHash = pwalletMain->pStakerStatus->GetLastHash();
obj.push_back(Pair("hashLastStakeAttempt", lastHash.GetHex()));
obj.push_back(Pair("heightLastStakeAttempt", (mapBlockIndex.count(lastHash) > 0 ?
mapBlockIndex.at(lastHash)->nHeight : -1)) );
obj.push_back(Pair("timeLastStakeAttempt", pwalletMain->pStakerStatus->GetLastTime()));
return obj;
}
obj.push_back(Pair("mnsync", masternodeSync.IsSynced()));
uint256 lastHash = pwalletMain->pStakerStatus->GetLastHash();
obj.push_back(Pair("hashLastStakeAttempt", lastHash.GetHex()));
obj.push_back(Pair("heightLastStakeAttempt", (mapBlockIndex.count(lastHash) > 0 ?
mapBlockIndex.at(lastHash)->nHeight : -1)) );
obj.push_back(Pair("timeLastStakeAttempt", pwalletMain->pStakerStatus->GetLastTime()));
return obj;


}
#endif // ENABLE_WALLET

0 comments on commit a80e2e9

Please sign in to comment.