rpc: Bail out early when no wallet is available in rpcs that require it, even on help <cmd> (#4123)

This commit is contained in:
UdjinM6 2021-04-27 17:12:12 +03:00 committed by GitHub
parent bf7b6adef2
commit 08ebd31fdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 30 deletions

View File

@ -139,12 +139,12 @@ UniValue gobject_prepare(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); CWallet* const pwallet = wallet.get();
if (request.fHelp || (request.params.size() != 5 && request.params.size() != 6 && request.params.size() != 8))
gobject_prepare_help(pwallet);
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue; return NullUniValue;
if (request.fHelp || (request.params.size() != 5 && request.params.size() != 6 && request.params.size() != 8))
gobject_prepare_help(pwallet);
EnsureWalletIsUnlocked(pwallet); EnsureWalletIsUnlocked(pwallet);
// ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS // ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS
@ -247,13 +247,13 @@ UniValue gobject_list_prepared(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;
if (request.fHelp || (request.params.size() > 2)) { if (request.fHelp || (request.params.size() > 2)) {
gobject_list_prepared_help(pwallet); gobject_list_prepared_help(pwallet);
} }
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;
EnsureWalletIsUnlocked(pwallet); EnsureWalletIsUnlocked(pwallet);
int64_t nCount = request.params.size() > 1 ? ParseInt64V(request.params[1], "count") : 10; int64_t nCount = request.params.size() > 1 ? ParseInt64V(request.params[1], "count") : 10;
@ -574,12 +574,12 @@ UniValue gobject_vote_many(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); CWallet* const pwallet = wallet.get();
if (request.fHelp || request.params.size() != 4)
gobject_vote_many_help(pwallet);
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue; return NullUniValue;
if (request.fHelp || request.params.size() != 4)
gobject_vote_many_help(pwallet);
uint256 hash = ParseHashV(request.params[1], "Object hash"); uint256 hash = ParseHashV(request.params[1], "Object hash");
std::string strVoteSignal = request.params[2].get_str(); std::string strVoteSignal = request.params[2].get_str();
std::string strVoteOutcome = request.params[3].get_str(); std::string strVoteOutcome = request.params[3].get_str();
@ -629,12 +629,12 @@ UniValue gobject_vote_alias(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); CWallet* const pwallet = wallet.get();
if (request.fHelp || request.params.size() != 5)
gobject_vote_alias_help(pwallet);
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue; return NullUniValue;
if (request.fHelp || request.params.size() != 5)
gobject_vote_alias_help(pwallet);
uint256 hash = ParseHashV(request.params[1], "Object hash"); uint256 hash = ParseHashV(request.params[1], "Object hash");
std::string strVoteSignal = request.params[2].get_str(); std::string strVoteSignal = request.params[2].get_str();
std::string strVoteOutcome = request.params[3].get_str(); std::string strVoteOutcome = request.params[3].get_str();

View File

@ -190,12 +190,12 @@ UniValue masternode_outputs(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); CWallet* const pwallet = wallet.get();
if (request.fHelp)
masternode_outputs_help();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue; return NullUniValue;
if (request.fHelp)
masternode_outputs_help();
LOCK2(cs_main, pwallet->cs_wallet); LOCK2(cs_main, pwallet->cs_wallet);
// Find possible candidates // Find possible candidates

View File

@ -405,6 +405,9 @@ UniValue protx_register(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;
bool isExternalRegister = request.params[0].get_str() == "register"; bool isExternalRegister = request.params[0].get_str() == "register";
bool isFundRegister = request.params[0].get_str() == "register_fund"; bool isFundRegister = request.params[0].get_str() == "register_fund";
bool isPrepareRegister = request.params[0].get_str() == "register_prepare"; bool isPrepareRegister = request.params[0].get_str() == "register_prepare";
@ -417,9 +420,6 @@ UniValue protx_register(const JSONRPCRequest& request)
protx_register_prepare_help(); protx_register_prepare_help();
} }
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;
if (isExternalRegister || isFundRegister) { if (isExternalRegister || isFundRegister) {
EnsureWalletIsUnlocked(pwallet); EnsureWalletIsUnlocked(pwallet);
} }
@ -567,13 +567,13 @@ UniValue protx_register_submit(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() != 3) { if (request.fHelp || request.params.size() != 3) {
protx_register_submit_help(pwallet); protx_register_submit_help(pwallet);
} }
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;
EnsureWalletIsUnlocked(pwallet); EnsureWalletIsUnlocked(pwallet);
CMutableTransaction tx; CMutableTransaction tx;
@ -622,12 +622,12 @@ UniValue protx_update_service(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); CWallet* const pwallet = wallet.get();
if (request.fHelp || (request.params.size() < 4 || request.params.size() > 6))
protx_update_service_help(pwallet);
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue; return NullUniValue;
if (request.fHelp || (request.params.size() < 4 || request.params.size() > 6))
protx_update_service_help(pwallet);
EnsureWalletIsUnlocked(pwallet); EnsureWalletIsUnlocked(pwallet);
CProUpServTx ptx; CProUpServTx ptx;
@ -718,13 +718,13 @@ UniValue protx_update_registrar(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;
if (request.fHelp || (request.params.size() != 5 && request.params.size() != 6)) { if (request.fHelp || (request.params.size() != 5 && request.params.size() != 6)) {
protx_update_registrar_help(pwallet); protx_update_registrar_help(pwallet);
} }
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;
EnsureWalletIsUnlocked(pwallet); EnsureWalletIsUnlocked(pwallet);
CProUpRegTx ptx; CProUpRegTx ptx;
@ -807,13 +807,13 @@ UniValue protx_revoke(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;
if (request.fHelp || (request.params.size() < 3 || request.params.size() > 5)) { if (request.fHelp || (request.params.size() < 3 || request.params.size() > 5)) {
protx_revoke_help(pwallet); protx_revoke_help(pwallet);
} }
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;
EnsureWalletIsUnlocked(pwallet); EnsureWalletIsUnlocked(pwallet);
CProUpRevTx ptx; CProUpRevTx ptx;