From 08ebd31fdb8ebdd9be22cf580c5f1f5090d198e9 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 27 Apr 2021 17:12:12 +0300 Subject: [PATCH] rpc: Bail out early when no wallet is available in rpcs that require it, even on `help ` (#4123) --- src/rpc/governance.cpp | 24 ++++++++++++------------ src/rpc/masternode.cpp | 6 +++--- src/rpc/rpcevo.cpp | 30 +++++++++++++++--------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/rpc/governance.cpp b/src/rpc/governance.cpp index 0222c99db2..aeaa3d7baa 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -139,12 +139,12 @@ UniValue gobject_prepare(const JSONRPCRequest& request) { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); 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)) return NullUniValue; + if (request.fHelp || (request.params.size() != 5 && request.params.size() != 6 && request.params.size() != 8)) + gobject_prepare_help(pwallet); + EnsureWalletIsUnlocked(pwallet); // ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS @@ -247,13 +247,13 @@ UniValue gobject_list_prepared(const JSONRPCRequest& request) { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); CWallet* const pwallet = wallet.get(); + if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) + return NullUniValue; + if (request.fHelp || (request.params.size() > 2)) { gobject_list_prepared_help(pwallet); } - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) - return NullUniValue; - EnsureWalletIsUnlocked(pwallet); 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 const wallet = GetWalletForJSONRPCRequest(request); CWallet* const pwallet = wallet.get(); - if (request.fHelp || request.params.size() != 4) - gobject_vote_many_help(pwallet); - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) return NullUniValue; + if (request.fHelp || request.params.size() != 4) + gobject_vote_many_help(pwallet); + uint256 hash = ParseHashV(request.params[1], "Object hash"); std::string strVoteSignal = request.params[2].get_str(); std::string strVoteOutcome = request.params[3].get_str(); @@ -629,12 +629,12 @@ UniValue gobject_vote_alias(const JSONRPCRequest& request) { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); CWallet* const pwallet = wallet.get(); - if (request.fHelp || request.params.size() != 5) - gobject_vote_alias_help(pwallet); - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) return NullUniValue; + if (request.fHelp || request.params.size() != 5) + gobject_vote_alias_help(pwallet); + uint256 hash = ParseHashV(request.params[1], "Object hash"); std::string strVoteSignal = request.params[2].get_str(); std::string strVoteOutcome = request.params[3].get_str(); diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 352db89a16..fbf4f95249 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -190,12 +190,12 @@ UniValue masternode_outputs(const JSONRPCRequest& request) { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); CWallet* const pwallet = wallet.get(); - if (request.fHelp) - masternode_outputs_help(); - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) return NullUniValue; + if (request.fHelp) + masternode_outputs_help(); + LOCK2(cs_main, pwallet->cs_wallet); // Find possible candidates diff --git a/src/rpc/rpcevo.cpp b/src/rpc/rpcevo.cpp index f24a406016..832402550e 100644 --- a/src/rpc/rpcevo.cpp +++ b/src/rpc/rpcevo.cpp @@ -405,6 +405,9 @@ UniValue protx_register(const JSONRPCRequest& request) { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); CWallet* const pwallet = wallet.get(); + if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) + return NullUniValue; + bool isExternalRegister = request.params[0].get_str() == "register"; bool isFundRegister = request.params[0].get_str() == "register_fund"; bool isPrepareRegister = request.params[0].get_str() == "register_prepare"; @@ -417,9 +420,6 @@ UniValue protx_register(const JSONRPCRequest& request) protx_register_prepare_help(); } - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) - return NullUniValue; - if (isExternalRegister || isFundRegister) { EnsureWalletIsUnlocked(pwallet); } @@ -567,13 +567,13 @@ UniValue protx_register_submit(const JSONRPCRequest& request) { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); CWallet* const pwallet = wallet.get(); + if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) + return NullUniValue; + if (request.fHelp || request.params.size() != 3) { protx_register_submit_help(pwallet); } - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) - return NullUniValue; - EnsureWalletIsUnlocked(pwallet); CMutableTransaction tx; @@ -622,12 +622,12 @@ UniValue protx_update_service(const JSONRPCRequest& request) { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); 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)) return NullUniValue; + if (request.fHelp || (request.params.size() < 4 || request.params.size() > 6)) + protx_update_service_help(pwallet); + EnsureWalletIsUnlocked(pwallet); CProUpServTx ptx; @@ -718,13 +718,13 @@ UniValue protx_update_registrar(const JSONRPCRequest& request) { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); CWallet* const pwallet = wallet.get(); + if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) + return NullUniValue; + if (request.fHelp || (request.params.size() != 5 && request.params.size() != 6)) { protx_update_registrar_help(pwallet); } - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) - return NullUniValue; - EnsureWalletIsUnlocked(pwallet); CProUpRegTx ptx; @@ -807,13 +807,13 @@ UniValue protx_revoke(const JSONRPCRequest& request) { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); CWallet* const pwallet = wallet.get(); + if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) + return NullUniValue; + if (request.fHelp || (request.params.size() < 3 || request.params.size() > 5)) { protx_revoke_help(pwallet); } - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) - return NullUniValue; - EnsureWalletIsUnlocked(pwallet); CProUpRevTx ptx;