Skip to content

Commit

Permalink
remove all references to pwalletMain in rpc folder
Browse files Browse the repository at this point in the history
  • Loading branch information
PastaPastaPasta committed Jan 25, 2019
1 parent 87af117 commit d7474fd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 48 deletions.
21 changes: 12 additions & 9 deletions src/rpc/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ void gobject_prepare_help()

UniValue gobject_prepare(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
if (request.fHelp || (request.params.size() != 5 && request.params.size() != 6 && request.params.size() != 8))
gobject_prepare_help();

if (!EnsureWalletIsAvailable(request.fHelp))
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;

// ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS
Expand Down Expand Up @@ -192,13 +193,13 @@ UniValue gobject_prepare(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Watchdogs are deprecated");
}

LOCK2(cs_main, pwalletMain->cs_wallet);
LOCK2(cs_main, pwallet->cs_wallet);

std::string strError = "";
if (!govobj.IsValidLocally(strError, false))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + govobj.GetHash().ToString() + " - " + strError);

EnsureWalletIsUnlocked();
EnsureWalletIsUnlocked(pwallet);

// If specified, spend this outpoint as the proposal fee
COutPoint outpoint;
Expand All @@ -213,17 +214,17 @@ UniValue gobject_prepare(const JSONRPCRequest& request)
}

CWalletTx wtx;
if (!pwalletMain->GetBudgetSystemCollateralTX(wtx, govobj.GetHash(), govobj.GetMinCollateralFee(), useIS, outpoint)) {
if (!pwallet->GetBudgetSystemCollateralTX(wtx, govobj.GetHash(), govobj.GetMinCollateralFee(), useIS, outpoint)) {
std::string err = "Error making collateral transaction for governance object. Please check your wallet balance and make sure your wallet is unlocked.";
if (request.params.size() == 8) err += "Please verify your specified output is valid and is enough for the combined proposal fee and transaction fee.";
throw JSONRPCError(RPC_INTERNAL_ERROR, err);
}

// -- make our change address
CReserveKey reservekey(pwalletMain);
CReserveKey reservekey(pwallet);
// -- send the tx to the network
CValidationState state;
if (!pwalletMain->CommitTransaction(wtx, reservekey, g_connman.get(), state, NetMsgType::TX)) {
if (!pwallet->CommitTransaction(wtx, reservekey, g_connman.get(), state, NetMsgType::TX)) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "CommitTransaction failed! Reason given: " + state.GetRejectReason());
}

Expand Down Expand Up @@ -538,6 +539,7 @@ void gobject_vote_many_help()

UniValue gobject_vote_many(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
if (request.fHelp || request.params.size() != 4)
gobject_vote_many_help();

Expand All @@ -557,7 +559,7 @@ UniValue gobject_vote_many(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");
}

if (!pwalletMain) {
if (!pwallet) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "vote-many not supported when wallet is disabled.");
}

Expand All @@ -566,7 +568,7 @@ UniValue gobject_vote_many(const JSONRPCRequest& request)
auto mnList = deterministicMNManager->GetListAtChainTip();
mnList.ForEachMN(true, [&](const CDeterministicMNCPtr& dmn) {
CKey votingKey;
if (pwalletMain->GetKey(dmn->pdmnState->keyIDVoting, votingKey)) {
if (pwallet->GetKey(dmn->pdmnState->keyIDVoting, votingKey)) {
votingKeys.emplace(dmn->proTxHash, votingKey);
}
});
Expand All @@ -589,6 +591,7 @@ void gobject_vote_alias_help()

UniValue gobject_vote_alias(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
if (request.fHelp || request.params.size() != 5)
gobject_vote_alias_help();

Expand All @@ -608,7 +611,7 @@ UniValue gobject_vote_alias(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");
}

if (!pwalletMain) {
if (!pwallet) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "vote-alias not supported when wallet is disabled");
}

Expand Down
19 changes: 11 additions & 8 deletions src/rpc/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ void EnsureWalletIsUnlocked();

UniValue privatesend(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 @@ -55,8 +56,8 @@ UniValue privatesend(const JSONRPCRequest& request)

if (request.params[0].get_str() == "start") {
{
LOCK(pwalletMain->cs_wallet);
if (pwalletMain->IsLocked(true))
LOCK(pwallet->cs_wallet);
if (pwallet->IsLocked(true))
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please unlock wallet for mixing with walletpassphrase first.");
}

Expand All @@ -81,6 +82,7 @@ UniValue privatesend(const JSONRPCRequest& request)

UniValue getpoolinfo(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
"getpoolinfo\n"
Expand Down Expand Up @@ -108,9 +110,9 @@ UniValue getpoolinfo(const JSONRPCRequest& request)
obj.push_back(Pair("pools", pools));
}

if (pwalletMain) {
obj.push_back(Pair("keys_left", pwalletMain->nKeysLeftSinceAutoBackup));
obj.push_back(Pair("warnings", pwalletMain->nKeysLeftSinceAutoBackup < PRIVATESEND_KEYS_THRESHOLD_WARNING
if (pwallet) {
obj.push_back(Pair("keys_left", pwallet->nKeysLeftSinceAutoBackup));
obj.push_back(Pair("warnings", pwallet->nKeysLeftSinceAutoBackup < PRIVATESEND_KEYS_THRESHOLD_WARNING
? "WARNING: keypool is almost depleted!" : ""));
}
#else // ENABLE_WALLET
Expand Down Expand Up @@ -312,15 +314,16 @@ void masternode_outputs_help()

UniValue masternode_outputs(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
if (request.fHelp)
masternode_outputs_help();

if (!EnsureWalletIsAvailable(request.fHelp))
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;

// Find possible candidates
std::vector<COutput> vPossibleCoins;
pwalletMain->AvailableCoins(vPossibleCoins, true, NULL, false, ONLY_1000);
pwallet->AvailableCoins(vPossibleCoins, true, NULL, false, ONLY_1000);

UniValue obj(UniValue::VOBJ);
for (const auto& out : vPossibleCoins) {
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ UniValue validateaddress(const JSONRPCRequest& request)
}

CHDChain hdChainCurrent;
if (!keyID.IsNull() && pwalletMain->mapHdPubKeys.count(keyID) && pwalletMain->GetHDChain(hdChainCurrent)) {
ret.push_back(Pair("hdkeypath", pwalletMain->mapHdPubKeys[keyID].GetKeyPath()));
if (!keyID.IsNull() && pwallet->mapHdPubKeys.count(keyID) && pwallet->GetHDChain(hdChainCurrent)) {
ret.push_back(Pair("hdkeypath", pwallet->mapHdPubKeys[keyID].GetKeyPath()));
ret.push_back(Pair("hdchainid", hdChainCurrent.GetID().GetHex()));
}
}
Expand Down
Loading

0 comments on commit d7474fd

Please sign in to comment.