From c094d4bbe67c61939ddd5d30d5f3288a1237729f Mon Sep 17 00:00:00 2001 From: Pasta Date: Sun, 30 Dec 2018 20:37:40 -0600 Subject: [PATCH] fix #8775 backport --- src/rpc/governance.cpp | 3 +-- src/rpc/masternode.cpp | 6 ++---- src/rpc/rpcevo.cpp | 26 ++++++++++++++------------ src/wallet/rpcdump.cpp | 2 +- src/wallet/rpcwallet.cpp | 24 ++++++++++++++---------- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/rpc/governance.cpp b/src/rpc/governance.cpp index 0a596b32856a7..ee73ee830ff33 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -19,12 +19,11 @@ #include "rpc/server.h" #include "util.h" #include "utilmoneystr.h" +#include "wallet/rpcwallet.h" #ifdef ENABLE_WALLET #include "wallet/wallet.h" #endif // ENABLE_WALLET -bool EnsureWalletIsAvailable(bool avoidException); - void gobject_count_help() { throw std::runtime_error( diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 86d07d6fe1dd8..5d9115e93371b 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -20,6 +20,8 @@ #include "utilmoneystr.h" #include "txmempool.h" +#include "wallet/rpcwallet.h" + #include "evo/specialtx.h" #include "evo/deterministicmns.h" @@ -29,11 +31,7 @@ UniValue masternodelist(const JSONRPCRequest& request); -bool EnsureWalletIsAvailable(bool avoidException); - #ifdef ENABLE_WALLET -void EnsureWalletIsUnlocked(); - UniValue privatesend(const JSONRPCRequest& request) { CWallet* const pwallet = GetWalletForJSONRPCRequest(request); diff --git a/src/rpc/rpcevo.cpp b/src/rpc/rpcevo.cpp index aba8cba04846e..92e227dae144c 100644 --- a/src/rpc/rpcevo.cpp +++ b/src/rpc/rpcevo.cpp @@ -90,10 +90,10 @@ static CBLSSecretKey ParseBLSSecretKey(const std::string& hexKey, const std::str #ifdef ENABLE_WALLET template -static void FundSpecialTx(CMutableTransaction& tx, const SpecialTxPayload& payload, const CTxDestination& fundDest) +static void FundSpecialTx(CWallet* pwallet, CMutableTransaction& tx, const SpecialTxPayload& payload, const CTxDestination& fundDest) { - assert(pwalletMain != NULL); - LOCK2(cs_main, pwalletMain->cs_wallet); + assert(pwallet != NULL); + LOCK2(cs_main, pwallet->cs_wallet); CTxDestination nodest = CNoDestination(); if (fundDest == nodest) { @@ -124,7 +124,7 @@ static void FundSpecialTx(CMutableTransaction& tx, const SpecialTxPayload& paylo coinControl.fRequireAllInputs = false; std::vector vecOutputs; - pwalletMain->AvailableCoins(vecOutputs); + pwallet->AvailableCoins(vecOutputs); for (const auto& out : vecOutputs) { CTxDestination txDest; @@ -404,7 +404,7 @@ UniValue protx_register(const JSONRPCRequest& request) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Dash address: ") + request.params[paramIdx + 6].get_str()); } - FundSpecialTx(tx, ptx, fundAddress.Get()); + FundSpecialTx(pwallet, tx, ptx, fundAddress.Get()); UpdateSpecialTxInputsHash(tx, ptx); if (isFundRegister) { @@ -508,6 +508,7 @@ void protx_update_service_help() UniValue protx_update_service(const JSONRPCRequest& request) { + CWallet* const pwallet = GetWalletForJSONRPCRequest(request); if (request.fHelp || (request.params.size() < 4 || request.params.size() > 6)) protx_update_service_help(); @@ -567,7 +568,7 @@ UniValue protx_update_service(const JSONRPCRequest& request) } } - FundSpecialTx(tx, ptx, feeSource); + FundSpecialTx(pwallet, tx, ptx, feeSource); SignSpecialTxPayloadByHash(tx, ptx, keyOperator); SetTxPayload(tx, ptx); @@ -651,7 +652,7 @@ UniValue protx_update_registrar(const JSONRPCRequest& request) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Dash address: ") + request.params[5].get_str()); } - FundSpecialTx(tx, ptx, feeSourceAddress.Get()); + FundSpecialTx(pwallet, tx, ptx, feeSourceAddress.Get()); SignSpecialTxPayloadByHash(tx, ptx, keyOwner); SetTxPayload(tx, ptx); @@ -681,6 +682,7 @@ void protx_revoke_help() UniValue protx_revoke(const JSONRPCRequest& request) { + CWallet* const pwallet = GetWalletForJSONRPCRequest(request); if (request.fHelp || (request.params.size() < 3 || request.params.size() > 5)) { protx_revoke_help(); } @@ -716,17 +718,17 @@ UniValue protx_revoke(const JSONRPCRequest& request) CBitcoinAddress feeSourceAddress = CBitcoinAddress(request.params[4].get_str()); if (!feeSourceAddress.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Dash address: ") + request.params[4].get_str()); - FundSpecialTx(tx, ptx, feeSourceAddress.Get()); + FundSpecialTx(pwallet, tx, ptx, feeSourceAddress.Get()); } else if (dmn->pdmnState->scriptOperatorPayout != CScript()) { // Using funds from previousely specified operator payout address CTxDestination txDest; ExtractDestination(dmn->pdmnState->scriptOperatorPayout, txDest); - FundSpecialTx(tx, ptx, txDest); + FundSpecialTx(pwallet, tx, ptx, txDest); } else if (dmn->pdmnState->scriptPayout != CScript()) { // Using funds from previousely specified masternode payout address CTxDestination txDest; ExtractDestination(dmn->pdmnState->scriptPayout, txDest); - FundSpecialTx(tx, ptx, txDest); + FundSpecialTx(pwallet, tx, ptx, txDest); } else { throw JSONRPCError(RPC_INTERNAL_ERROR, "No payout or fee source addresses found, can't revoke"); } @@ -872,8 +874,8 @@ UniValue protx_list(const JSONRPCRequest& request) CDeterministicMNList mnList = deterministicMNManager->GetListForBlock(chainActive[height]->GetBlockHash()); mnList.ForEachMN(false, [&](const CDeterministicMNCPtr& dmn) { if (setOutpts.count(dmn->collateralOutpoint) || - CheckWalletOwnsKey(dmn->pdmnState->keyIDOwner) || - CheckWalletOwnsKey(dmn->pdmnState->keyIDVoting) || + CheckWalletOwnsKey(pwallet, dmn->pdmnState->keyIDOwner) || + CheckWalletOwnsKey(pwallet, dmn->pdmnState->keyIDVoting) || CheckWalletOwnsScript(pwallet, dmn->pdmnState->scriptPayout) || CheckWalletOwnsScript(pwallet, dmn->pdmnState->scriptOperatorPayout)) { ret.push_back(BuildDMNListEntry(pwallet, dmn, detailed)); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index b0367088a5600..0f59e0a74be47 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -708,7 +708,7 @@ UniValue dumpprivkey(const JSONRPCRequest& request) UniValue dumphdinfo(const JSONRPCRequest& request) { CWallet* const pwallet = GetWalletForJSONRPCRequest(request); - if (!EnsureWalletIsAvailable(request.fHelp)) + if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 0) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index db9cf90bb14cd..e7c7c28e61f8a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -461,7 +461,7 @@ UniValue instantsendtoaddress(const JSONRPCRequest& request) throw std::runtime_error( "instantsendtoaddress \"address\" amount ( \"comment\" \"comment-to\" subtractfeefromamount )\n" "\nSend an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n" - + HelpRequiringPassphrase() + + + HelpRequiringPassphrase(pwallet) + "\nArguments:\n" "1. \"address\" (string, required) The dash address to send to.\n" "2. \"amount\" (numeric, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1\n" @@ -2026,7 +2026,7 @@ UniValue keypoolrefill(const JSONRPCRequest& request) EnsureWalletIsUnlocked(pwallet); pwallet->TopUpKeyPool(kpSize); - if (pwallet->GetKeyPoolSize() < (pwallet->IsHDEnabled() ? kpSize * 2 : kpSize)) + if (pwallet->GetKeyPoolSize() < (pwallet->IsHDEnabled() ? kpSize * 2 : kpSize)) { throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool."); } @@ -2048,7 +2048,7 @@ UniValue walletpassphrase(const JSONRPCRequest& request) return NullUniValue; } - if (pwallet->IsCrypted() && (request.fHelp || request.params.size() < 2 || request.params.size() > 3)) + if (pwallet->IsCrypted() && (request.fHelp || request.params.size() < 2 || request.params.size() > 3)) { throw std::runtime_error( "walletpassphrase \"passphrase\" timeout ( mixingonly )\n" "\nStores the wallet decryption key in memory for 'timeout' seconds.\n" @@ -2118,7 +2118,7 @@ UniValue walletpassphrasechange(const JSONRPCRequest& request) return NullUniValue; } - if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) + if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) { throw std::runtime_error( "walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n" "\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n" @@ -2169,7 +2169,7 @@ UniValue walletlock(const JSONRPCRequest& request) return NullUniValue; } - if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 0)) + if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 0)) { throw std::runtime_error( "walletlock\n" "\nRemoves the wallet encryption key from memory, locking the wallet.\n" @@ -2209,7 +2209,7 @@ UniValue encryptwallet(const JSONRPCRequest& request) return NullUniValue; } - if (!pwallet->IsCrypted() && (request.fHelp || request.params.size() != 1)) + if (!pwallet->IsCrypted() && (request.fHelp || request.params.size() != 1)) { throw std::runtime_error( "encryptwallet \"passphrase\"\n" "\nEncrypts the wallet with 'passphrase'. This is for first time encryption.\n" @@ -2437,7 +2437,8 @@ UniValue settxfee(const JSONRPCRequest& request) UniValue setprivatesendrounds(const JSONRPCRequest& request) { - if (!EnsureWalletIsAvailable(request.fHelp)) + CWallet* const pwallet = GetWalletForJSONRPCRequest(request); + if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 1) @@ -2464,7 +2465,8 @@ UniValue setprivatesendrounds(const JSONRPCRequest& request) UniValue setprivatesendamount(const JSONRPCRequest& request) { - if (!EnsureWalletIsAvailable(request.fHelp)) + CWallet* const pwallet = GetWalletForJSONRPCRequest(request); + if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) return NullUniValue; if (request.fHelp || request.params.size() != 1) @@ -2550,7 +2552,7 @@ UniValue getwalletinfo(const JSONRPCRequest& request) } obj.push_back(Pair("keys_left", pwallet->nKeysLeftSinceAutoBackup)); if (pwallet->IsCrypted()) - obj.push_back(Pair("unlocked_until", nWalletUnlockTime)); + obj.push_back(Pair("unlocked_until", pwallet->nRelockTime)); obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK()))); if (fHDEnabled) { obj.push_back(Pair("hdchainid", hdChainCurrent.GetID().GetHex())); @@ -2576,7 +2578,8 @@ UniValue getwalletinfo(const JSONRPCRequest& request) UniValue keepass(const JSONRPCRequest& request) { - if (!EnsureWalletIsAvailable(request.fHelp)) + CWallet* const pwallet = GetWalletForJSONRPCRequest(request); + if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) return NullUniValue; std::string strCommand; @@ -2947,6 +2950,7 @@ UniValue fundrawtransaction(const JSONRPCRequest& request) UniValue setbip69enabled(const JSONRPCRequest& request) { + CWallet* const pwallet = GetWalletForJSONRPCRequest(request); if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) return NullUniValue;