Skip to content

Commit

Permalink
fix bitcoin#8775 backport
Browse files Browse the repository at this point in the history
  • Loading branch information
PastaPastaPasta committed Jan 25, 2019
1 parent f914746 commit c094d4b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
3 changes: 1 addition & 2 deletions src/rpc/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 2 additions & 4 deletions src/rpc/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "utilmoneystr.h"
#include "txmempool.h"

#include "wallet/rpcwallet.h"

#include "evo/specialtx.h"
#include "evo/deterministicmns.h"

Expand All @@ -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);
Expand Down
26 changes: 14 additions & 12 deletions src/rpc/rpcevo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ static CBLSSecretKey ParseBLSSecretKey(const std::string& hexKey, const std::str
#ifdef ENABLE_WALLET

template<typename SpecialTxPayload>
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) {
Expand Down Expand Up @@ -124,7 +124,7 @@ static void FundSpecialTx(CMutableTransaction& tx, const SpecialTxPayload& paylo
coinControl.fRequireAllInputs = false;

std::vector<COutput> vecOutputs;
pwalletMain->AvailableCoins(vecOutputs);
pwallet->AvailableCoins(vecOutputs);

for (const auto& out : vecOutputs) {
CTxDestination txDest;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 14 additions & 10 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.");
}

Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()));
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit c094d4b

Please sign in to comment.