Skip to content

Commit 22f8507

Browse files
committed
[Trivial] Rename pwalletMain --> pwallet for local variables in RPC
1 parent 325baaa commit 22f8507

File tree

9 files changed

+583
-578
lines changed

9 files changed

+583
-578
lines changed

src/rpc/budget.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ void checkBudgetInputs(const UniValue& params, std::string &strProposalName, std
9797

9898
UniValue preparebudget(const JSONRPCRequest& request)
9999
{
100-
CWallet * const pwalletMain = GetWalletForJSONRPCRequest(request);
100+
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
101101

102-
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp))
102+
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
103103
return NullUniValue;
104104

105105
if (request.fHelp || request.params.size() != 6)
@@ -122,13 +122,9 @@ UniValue preparebudget(const JSONRPCRequest& request)
122122
HelpExampleCli("preparebudget", "\"test-proposal\" \"https://forum.pivx.org/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500") +
123123
HelpExampleRpc("preparebudget", "\"test-proposal\" \"https://forum.pivx.org/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500"));
124124

125-
if (!pwalletMain) {
126-
throw JSONRPCError(RPC_IN_WARMUP, "Try again after active chain is loaded");
127-
}
128-
129-
LOCK2(cs_main, pwalletMain->cs_wallet);
125+
LOCK2(cs_main, pwallet->cs_wallet);
130126

131-
EnsureWalletIsUnlocked(pwalletMain);
127+
EnsureWalletIsUnlocked(pwallet);
132128

133129
std::string strProposalName;
134130
std::string strURL;
@@ -150,19 +146,19 @@ UniValue preparebudget(const JSONRPCRequest& request)
150146

151147
CTransactionRef wtx;
152148
// make our change address
153-
CReserveKey keyChange(pwalletMain);
154-
if (!pwalletMain->CreateBudgetFeeTX(wtx, nHash, keyChange, false)) { // 50 PIV collateral for proposal
149+
CReserveKey keyChange(pwallet);
150+
if (!pwallet->CreateBudgetFeeTX(wtx, nHash, keyChange, false)) { // 50 PIV collateral for proposal
155151
throw std::runtime_error("Error making collateral transaction for proposal. Please check your wallet balance.");
156152
}
157153

158154
//send the tx to the network
159-
const CWallet::CommitResult& res = pwalletMain->CommitTransaction(wtx, keyChange, g_connman.get());
155+
const CWallet::CommitResult& res = pwallet->CommitTransaction(wtx, keyChange, g_connman.get());
160156
if (res.status != CWallet::CommitStatus::OK)
161157
throw JSONRPCError(RPC_WALLET_ERROR, res.ToString());
162158

163159
// Store proposal name as a comment
164-
assert(pwalletMain->mapWallet.count(wtx->GetHash()));
165-
pwalletMain->mapWallet.at(wtx->GetHash()).SetComment("Proposal: " + strProposalName);
160+
assert(pwallet->mapWallet.count(wtx->GetHash()));
161+
pwallet->mapWallet.at(wtx->GetHash()).SetComment("Proposal: " + strProposalName);
166162

167163
return wtx->GetHash().ToString();
168164
}

src/rpc/masternode.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,9 @@ UniValue startmasternode(const JSONRPCRequest& request)
355355
throw JSONRPCError(RPC_MISC_ERROR, "startmasternode is not supported when deterministic masternode list is active (DIP3)");
356356
}
357357

358-
CWallet * const pwalletMain = GetWalletForJSONRPCRequest(request);
358+
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
359359

360-
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp))
360+
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
361361
return NullUniValue;
362362

363363
std::string strCommand;
@@ -407,15 +407,15 @@ UniValue startmasternode(const JSONRPCRequest& request)
407407

408408
bool fLock = (request.params[1].get_str() == "true" ? true : false);
409409

410-
EnsureWalletIsUnlocked(pwalletMain);
410+
EnsureWalletIsUnlocked(pwallet);
411411

412412
if (strCommand == "local") {
413413
if (!fMasterNode) throw std::runtime_error("you must set masternode=1 in the configuration\n");
414414

415415
if (activeMasternode.GetStatus() != ACTIVE_MASTERNODE_STARTED) {
416416
activeMasternode.ResetStatus();
417417
if (fLock)
418-
pwalletMain->Lock();
418+
pwallet->Lock();
419419
}
420420

421421
return activeMasternode.GetStatusMessage();
@@ -444,7 +444,7 @@ UniValue startmasternode(const JSONRPCRequest& request)
444444
RelayMNB(mnb, fSuccess, successful, failed);
445445
}
446446
if (fLock)
447-
pwalletMain->Lock();
447+
pwallet->Lock();
448448

449449
UniValue returnObj(UniValue::VOBJ);
450450
returnObj.pushKV("overall", strprintf("Successfully started %d masternodes, failed to start %d, total %d", successful, failed, successful + failed));
@@ -484,7 +484,7 @@ UniValue startmasternode(const JSONRPCRequest& request)
484484
}
485485

486486
if (fLock)
487-
pwalletMain->Lock();
487+
pwallet->Lock();
488488

489489
if(!found) {
490490
statusObj.pushKV("success", false);
@@ -517,9 +517,9 @@ UniValue createmasternodekey (const JSONRPCRequest& request)
517517

518518
UniValue getmasternodeoutputs (const JSONRPCRequest& request)
519519
{
520-
CWallet * const pwalletMain = GetWalletForJSONRPCRequest(request);
520+
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
521521

522-
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp))
522+
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
523523
return NullUniValue;
524524

525525
if (request.fHelp || (request.params.size() != 0))
@@ -544,7 +544,7 @@ UniValue getmasternodeoutputs (const JSONRPCRequest& request)
544544
coinsFilter.fIncludeDelegated = false;
545545
coinsFilter.nCoinType = ONLY_10000;
546546
std::vector<COutput> possibleCoins;
547-
pwalletMain->AvailableCoins(&possibleCoins, nullptr, coinsFilter);
547+
pwallet->AvailableCoins(&possibleCoins, nullptr, coinsFilter);
548548

549549
UniValue ret(UniValue::VARR);
550550
for (COutput& out : possibleCoins) {
@@ -817,9 +817,9 @@ bool DecodeHexMnb(CMasternodeBroadcast& mnb, std::string strHexMnb) {
817817
}
818818
UniValue createmasternodebroadcast(const JSONRPCRequest& request)
819819
{
820-
CWallet * const pwalletMain = GetWalletForJSONRPCRequest(request);
820+
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
821821

822-
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp))
822+
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
823823
return NullUniValue;
824824

825825
std::string strCommand;
@@ -829,7 +829,7 @@ UniValue createmasternodebroadcast(const JSONRPCRequest& request)
829829
throw std::runtime_error(
830830
"createmasternodebroadcast \"command\" ( \"alias\")\n"
831831
"\nCreates a masternode broadcast message for one or all masternodes configured in masternode.conf\n" +
832-
HelpRequiringPassphrase(pwalletMain) + "\n"
832+
HelpRequiringPassphrase(pwallet) + "\n"
833833

834834
"\nArguments:\n"
835835
"1. \"command\" (string, required) \"alias\" for single masternode, \"all\" for all masternodes\n"
@@ -860,7 +860,7 @@ UniValue createmasternodebroadcast(const JSONRPCRequest& request)
860860
"\nExamples:\n" +
861861
HelpExampleCli("createmasternodebroadcast", "alias mymn1") + HelpExampleRpc("createmasternodebroadcast", "alias mymn1"));
862862

863-
EnsureWalletIsUnlocked(pwalletMain);
863+
EnsureWalletIsUnlocked(pwallet);
864864

865865
if (strCommand == "alias")
866866
{

src/rpc/mining.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#ifdef ENABLE_WALLET
2929
UniValue generateBlocks(const Consensus::Params& consensus,
30-
CWallet* wallet,
30+
CWallet* const pwallet,
3131
bool fPoS,
3232
const int nGenerate,
3333
int nHeight,
@@ -40,13 +40,13 @@ UniValue generateBlocks(const Consensus::Params& consensus,
4040

4141
// Get available coins
4242
std::vector<CStakeableOutput> availableCoins;
43-
if (fPoS && !wallet->StakeableCoins(&availableCoins)) {
43+
if (fPoS && !pwallet->StakeableCoins(&availableCoins)) {
4444
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "No available coins to stake");
4545
}
4646

4747
std::unique_ptr<CBlockTemplate> pblocktemplate(fPoS ?
48-
BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(CScript(), wallet, true, &availableCoins) :
49-
CreateNewBlockWithScript(*coinbaseScript, wallet));
48+
BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(CScript(), pwallet, true, &availableCoins) :
49+
CreateNewBlockWithScript(*coinbaseScript, pwallet));
5050
if (!pblocktemplate.get()) break;
5151
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>(pblocktemplate->block);
5252

@@ -76,9 +76,9 @@ UniValue generateBlocks(const Consensus::Params& consensus,
7676

7777
UniValue generate(const JSONRPCRequest& request)
7878
{
79-
CWallet * const pwalletMain = GetWalletForJSONRPCRequest(request);
79+
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
8080

81-
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp))
81+
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
8282
return NullUniValue;
8383

8484
if (request.fHelp || request.params.size() < 1 || request.params.size() > 1)
@@ -118,18 +118,18 @@ UniValue generate(const JSONRPCRequest& request)
118118

119119
if (fPoS) {
120120
// If we are in PoS, wallet must be unlocked.
121-
EnsureWalletIsUnlocked(pwalletMain);
121+
EnsureWalletIsUnlocked(pwallet);
122122
} else {
123123
// Coinbase key
124-
reservekey = MakeUnique<CReserveKey>(pwalletMain);
124+
reservekey = MakeUnique<CReserveKey>(pwallet);
125125
CPubKey pubkey;
126126
if (!reservekey->GetReservedKey(pubkey)) throw JSONRPCError(RPC_INTERNAL_ERROR, "Error: Cannot get key from keypool");
127127
coinbaseScript = GetScriptForDestination(pubkey.GetID());
128128
}
129129

130130
// Create the blocks
131131
UniValue blockHashes = generateBlocks(consensus,
132-
pwalletMain,
132+
pwallet,
133133
fPoS,
134134
nGenerate,
135135
nHeight,
@@ -147,6 +147,11 @@ UniValue generate(const JSONRPCRequest& request)
147147

148148
UniValue generatetoaddress(const JSONRPCRequest& request)
149149
{
150+
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
151+
152+
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
153+
return NullUniValue;
154+
150155
if (request.fHelp || request.params.size() != 2)
151156
throw std::runtime_error(
152157
"generatetoaddress numblocks \"address\"\n"
@@ -180,7 +185,7 @@ UniValue generatetoaddress(const JSONRPCRequest& request)
180185

181186
bool fPoS = consensus.NetworkUpgradeActive(nHeight + 1, Consensus::UPGRADE_POS);
182187
return generateBlocks(consensus,
183-
pwalletMain,
188+
pwallet,
184189
fPoS,
185190
nGenerate,
186191
nHeight,
@@ -278,9 +283,9 @@ UniValue getgenerate(const JSONRPCRequest& request)
278283

279284
UniValue setgenerate(const JSONRPCRequest& request)
280285
{
281-
CWallet * const pwalletMain = GetWalletForJSONRPCRequest(request);
286+
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
282287

283-
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp))
288+
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
284289
return NullUniValue;
285290

286291
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
@@ -321,7 +326,7 @@ UniValue setgenerate(const JSONRPCRequest& request)
321326

322327
gArgs.GetArg("-gen", "") = (fGenerate ? "1" : "0");
323328
gArgs.GetArg("-genproclimit", "") = itostr(nGenProcLimit);
324-
GenerateBitcoins(fGenerate, pwalletMain, nGenProcLimit);
329+
GenerateBitcoins(fGenerate, pwallet, nGenProcLimit);
325330

326331
return NullUniValue;
327332
}
@@ -446,7 +451,7 @@ static UniValue BIP22ValidationResult(const CValidationState& state)
446451
#ifdef ENABLE_MINING_RPC
447452
UniValue getblocktemplate(const JSONRPCRequest& request)
448453
{
449-
CWallet * const pwalletMain = GetWalletForJSONRPCRequest(request);
454+
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
450455

451456
if (request.fHelp || request.params.size() > 1)
452457
throw std::runtime_error(
@@ -633,7 +638,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
633638
pblocktemplate = NULL;
634639
}
635640
CScript scriptDummy = CScript() << OP_TRUE;
636-
pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptDummy, pwalletMain, false);
641+
pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptDummy, pwallet, false);
637642
if (!pblocktemplate)
638643
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
639644

src/rpc/misc.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ UniValue getsupplyinfo(const JSONRPCRequest& request);
4747
**/
4848
UniValue getinfo(const JSONRPCRequest& request)
4949
{
50-
CWallet * const pwalletMain = GetWalletForJSONRPCRequest(request);
50+
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
5151

5252
if (request.fHelp || request.params.size() != 0)
5353
throw std::runtime_error(
@@ -85,7 +85,7 @@ UniValue getinfo(const JSONRPCRequest& request)
8585
HelpExampleCli("getinfo", "") + HelpExampleRpc("getinfo", ""));
8686

8787
#ifdef ENABLE_WALLET
88-
LOCK2(cs_main, pwalletMain ? &pwalletMain->cs_wallet : NULL);
88+
LOCK2(cs_main, pwallet ? &pwallet->cs_wallet : NULL);
8989
#else
9090
LOCK(cs_main);
9191
#endif
@@ -116,10 +116,10 @@ UniValue getinfo(const JSONRPCRequest& request)
116116
obj.pushKV("protocolversion", PROTOCOL_VERSION);
117117
obj.pushKV("services", services);
118118
#ifdef ENABLE_WALLET
119-
if (pwalletMain) {
120-
obj.pushKV("walletversion", pwalletMain->GetVersion());
121-
obj.pushKV("balance", ValueFromAmount(pwalletMain->GetAvailableBalance()));
122-
obj.pushKV("staking status", (pwalletMain->pStakerStatus->IsActive() ? "Staking Active" : "Staking Not Active"));
119+
if (pwallet) {
120+
obj.pushKV("walletversion", pwallet->GetVersion());
121+
obj.pushKV("balance", ValueFromAmount(pwallet->GetAvailableBalance()));
122+
obj.pushKV("staking status", (pwallet->pStakerStatus->IsActive() ? "Staking Active" : "Staking Not Active"));
123123
}
124124
#endif
125125
obj.pushKV("blocks", (int)chainActive.Height());
@@ -137,12 +137,12 @@ UniValue getinfo(const JSONRPCRequest& request)
137137
obj.pushKV("shieldsupply", supply_info["shieldsupply"]);
138138

139139
#ifdef ENABLE_WALLET
140-
if (pwalletMain) {
141-
obj.pushKV("keypoololdest", pwalletMain->GetOldestKeyPoolTime());
142-
size_t kpExternalSize = pwalletMain->KeypoolCountExternalKeys();
140+
if (pwallet) {
141+
obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime());
142+
size_t kpExternalSize = pwallet->KeypoolCountExternalKeys();
143143
obj.pushKV("keypoolsize", (int64_t)kpExternalSize);
144144
}
145-
if (pwalletMain && pwalletMain->IsCrypted())
145+
if (pwallet && pwallet->IsCrypted())
146146
obj.pushKV("unlocked_until", nWalletUnlockTime);
147147
obj.pushKV("paytxfee", ValueFromAmount(payTxFee.GetFeePerK()));
148148
#endif
@@ -378,7 +378,7 @@ class DescribePaymentAddressVisitor : public boost::static_visitor<UniValue>
378378

379379
UniValue validateaddress(const JSONRPCRequest& request)
380380
{
381-
CWallet * const pwalletMain = GetWalletForJSONRPCRequest(request);
381+
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
382382

383383
if (request.fHelp || request.params.size() != 1)
384384
throw std::runtime_error(
@@ -412,7 +412,7 @@ UniValue validateaddress(const JSONRPCRequest& request)
412412
HelpExampleRpc("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\""));
413413

414414
#ifdef ENABLE_WALLET
415-
LOCK2(cs_main, pwalletMain ? &pwalletMain->cs_wallet : nullptr);
415+
LOCK2(cs_main, pwallet ? &pwallet->cs_wallet : nullptr);
416416
#else
417417
LOCK(cs_main);
418418
#endif
@@ -436,7 +436,7 @@ UniValue validateaddress(const JSONRPCRequest& request)
436436
ret.pushKV("isvalid", isValid);
437437
if (isValid) {
438438
ret.pushKV("address", strAddress);
439-
UniValue detail = boost::apply_visitor(DescribePaymentAddressVisitor(pwalletMain, isStakingAddress), finalAddress);
439+
UniValue detail = boost::apply_visitor(DescribePaymentAddressVisitor(pwallet, isStakingAddress), finalAddress);
440440
ret.pushKVs(detail);
441441
}
442442

@@ -506,7 +506,7 @@ CScript _createmultisig_redeemScript(CWallet * const pwallet, const UniValue& pa
506506

507507
UniValue createmultisig(const JSONRPCRequest& request)
508508
{
509-
CWallet * const pwalletMain = GetWalletForJSONRPCRequest(request);
509+
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
510510

511511
if (request.fHelp || request.params.size() < 2 || request.params.size() > 2)
512512
throw std::runtime_error(
@@ -535,7 +535,7 @@ UniValue createmultisig(const JSONRPCRequest& request)
535535
HelpExampleRpc("createmultisig", "2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\""));
536536

537537
// Construct using pay-to-script-hash:
538-
CScript inner = _createmultisig_redeemScript(pwalletMain, request.params);
538+
CScript inner = _createmultisig_redeemScript(pwallet, request.params);
539539
CScriptID innerID(inner);
540540

541541
UniValue result(UniValue::VOBJ);

0 commit comments

Comments
 (0)