nit: helper variables often seem to bring more noise than clarity after this clean up, so i think they could be removed fully in many cases?
<details>
<summary>git diff on fa005e85e9</summary>
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index a6bbc308f7..96ceff6d23 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -671,8 +671,6 @@ static RPCMethod getblockheader()
{
uint256 hash(ParseHashV(request.params[0], "hash"));
- const bool fVerbose{self.Arg<bool>("verbose")};
-
const CBlockIndex* pblockindex;
const CBlockIndex* tip;
ChainstateManager& chainman = EnsureAnyChainman(request.context);
@@ -686,8 +684,7 @@ static RPCMethod getblockheader()
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
}
- if (!fVerbose)
- {
+ if (!self.Arg<bool>("verbose")) {
DataStream ssBlock{};
ssBlock << pblockindex->GetBlockHeader();
std::string strHex = HexStr(ssBlock);
@@ -1249,13 +1246,12 @@ static RPCMethod gettxout()
auto hash{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
COutPoint out{hash, request.params[1].getInt<uint32_t>()};
- const bool fMempool{self.Arg<bool>("include_mempool")};
Chainstate& active_chainstate = chainman.ActiveChainstate();
CCoinsViewCache* coins_view = &active_chainstate.CoinsTip();
std::optional<Coin> coin;
- if (fMempool) {
+ if (self.Arg<bool>("include_mempool")) {
const CTxMemPool& mempool = EnsureMemPool(node);
LOCK(mempool.cs);
CCoinsViewMemPool view(coins_view, mempool);
@@ -2922,9 +2918,7 @@ static RPCMethod getdescriptoractivity()
}
}
- const bool search_mempool{self.Arg<bool>("include_mempool")};
-
- if (search_mempool) {
+ if (self.Arg<bool>("include_mempool")) {
const CTxMemPool& mempool = EnsureMemPool(node);
LOCK(::cs_main);
LOCK(mempool.cs);
diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp
index c128723a6f..a0008708ad 100644
--- a/src/rpc/mempool.cpp
+++ b/src/rpc/mempool.cpp
@@ -753,10 +753,7 @@ static RPCMethod getrawmempool()
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
- const bool fVerbose{self.Arg<bool>("verbose")};
- const bool include_mempool_sequence{self.Arg<bool>("mempool_sequence")};
-
- return MempoolToJSON(EnsureAnyMemPool(request.context), fVerbose, include_mempool_sequence);
+ return MempoolToJSON(EnsureAnyMemPool(request.context), self.Arg<bool>("verbose"), self.Arg<bool>("mempool_sequence"));
},
};
}
@@ -786,8 +783,6 @@ static RPCMethod getmempoolancestors()
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
- const bool fVerbose{self.Arg<bool>("verbose")};
-
auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
@@ -800,7 +795,7 @@ static RPCMethod getmempoolancestors()
auto ancestors{mempool.CalculateMemPoolAncestors(*entry)};
- if (!fVerbose) {
+ if (!self.Arg<bool>("verbose")) {
UniValue o(UniValue::VARR);
for (CTxMemPool::txiter ancestorIt : ancestors) {
o.push_back(ancestorIt->GetTx().GetHash().ToString());
@@ -845,8 +840,6 @@ static RPCMethod getmempooldescendants()
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
- const bool fVerbose{self.Arg<bool>("verbose")};
-
auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
@@ -862,7 +855,7 @@ static RPCMethod getmempooldescendants()
// CTxMemPool::CalculateDescendants will include the given tx
setDescendants.erase(*it);
- if (!fVerbose) {
+ if (!self.Arg<bool>("verbose")) {
UniValue o(UniValue::VARR);
for (CTxMemPool::txiter descendantIt : setDescendants) {
o.push_back(descendantIt->GetTx().GetHash().ToString());
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index e407b95c6b..ef507d3b15 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -1057,7 +1057,6 @@ static RPCMethod addpeeraddress()
const std::string& addr_string{request.params[0].get_str()};
const auto port{request.params[1].getInt<uint16_t>()};
- const bool tried{self.Arg<bool>("tried")};
UniValue obj(UniValue::VOBJ);
std::optional<CNetAddr> net_addr{LookupHost(addr_string, false)};
@@ -1074,7 +1073,7 @@ static RPCMethod addpeeraddress()
// announcing itself.
if (addrman.Add({address}, address)) {
success = true;
- if (tried) {
+ if (self.Arg<bool>("tried")) {
// Attempt to move the address to the tried addresses table.
if (!addrman.Good(address)) {
success = false;
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
index 031ec21c6a..2279315239 100644
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -1693,8 +1693,6 @@ static RPCMethod finalizepsbt()
}
PartiallySignedTransaction psbtx = *psbt_res;
- const bool extract{self.Arg<bool>("extract")};
-
CMutableTransaction mtx;
bool complete = FinalizeAndExtractPSBT(psbtx, mtx);
@@ -1702,7 +1700,7 @@ static RPCMethod finalizepsbt()
DataStream ssTx{};
std::string result_str;
- if (complete && extract) {
+ if (complete && self.Arg<bool>("extract")) {
ssTx << TX_WITH_WITNESS(mtx);
result_str = HexStr(ssTx);
result.pushKV("hex", result_str);
@@ -2117,15 +2115,13 @@ RPCMethod descriptorprocesspsbt()
}
std::optional<int> sighash_type = ParseSighashString(request.params[2]);
- const bool bip32derivs{self.Arg<bool>("bip32derivs")};
- const bool finalize{self.Arg<bool>("finalize")};
const PartiallySignedTransaction& psbtx = ProcessPSBT(
request.params[0].get_str(),
request.context,
- HidingSigningProvider(&provider, /*hide_secret=*/false, !bip32derivs),
+ HidingSigningProvider(&provider, /*hide_secret=*/false, !self.Arg<bool>("bip32derivs")),
sighash_type,
- finalize);
+ self.Arg<bool>("finalize"));
// Check whether or not all of the inputs are now correctly signed
bool complete = true;
diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp
index 8a78a612d9..03b0a01fb3 100644
--- a/src/wallet/rpc/spend.cpp
+++ b/src/wallet/rpc/spend.cpp
@@ -335,9 +335,8 @@ RPCMethod sendtoaddress()
}
std::vector<CRecipient> recipients{CreateRecipients(ParseOutputs(address_amounts), sffo_set)};
- const bool verbose{self.Arg<bool>("verbose")};
- return SendMoney(*pwallet, coin_control, recipients, comment, comment_to, verbose);
+ return SendMoney(*pwallet, coin_control, recipients, comment, comment_to, self.Arg<bool>("verbose"));
},
};
}
@@ -431,9 +430,8 @@ RPCMethod sendmany()
ParseOutputs(sendTo),
InterpretSubtractFeeFromOutputInstructions(request.params[4], sendTo.getKeys())
);
- const bool verbose{self.Arg<bool>("verbose")};
- return SendMoney(*pwallet, coin_control, recipients, comment, /*comment_to=*/std::nullopt, verbose);
+ return SendMoney(*pwallet, coin_control, recipients, comment, /*comment_to=*/std::nullopt, self.Arg<bool>("verbose"));
},
};
}
@@ -1825,9 +1823,8 @@ RPCMethod walletcreatefundedpsbt()
PartiallySignedTransaction psbtx(CMutableTransaction(*txr.tx), psbt_version);
// Fill transaction with our data but don't sign
- const bool bip32derivs{self.Arg<bool>("bip32derivs")};
bool complete = true;
- const auto err{wallet.FillPSBT(psbtx, {.sign = false, .bip32_derivs = bip32derivs}, complete)};
+ const auto err{wallet.FillPSBT(psbtx, {.sign = false, .bip32_derivs = self.Arg<bool>("bip32derivs")}, complete)};
if (err) {
throw JSONRPCPSBTError(*err);
}
diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp
index dd5361ce66..4be755b717 100644
--- a/src/wallet/rpc/transactions.cpp
+++ b/src/wallet/rpc/transactions.cpp
@@ -247,11 +247,9 @@ RPCMethod listreceivedbyaddress()
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
- const bool include_immature_coinbase{self.Arg<bool>("include_immature_coinbase")};
-
LOCK(pwallet->cs_wallet);
- return ListReceived(*pwallet, request.params, false, include_immature_coinbase);
+ return ListReceived(*pwallet, request.params, false, self.Arg<bool>("include_immature_coinbase"));
},
};
}
@@ -292,11 +290,9 @@ RPCMethod listreceivedbylabel()
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
- const bool include_immature_coinbase{self.Arg<bool>("include_immature_coinbase")};
-
LOCK(pwallet->cs_wallet);
- return ListReceived(*pwallet, request.params, true, include_immature_coinbase);
+ return ListReceived(*pwallet, request.params, true, self.Arg<bool>("include_immature_coinbase"));
},
};
}
@@ -889,8 +885,6 @@ RPCMethod gettransaction()
Txid hash{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
- const bool verbose{self.Arg<bool>("verbose")};
-
UniValue entry(UniValue::VOBJ);
auto it = pwallet->mapWallet.find(hash);
if (it == pwallet->mapWallet.end()) {
@@ -908,7 +902,7 @@ RPCMethod gettransaction()
entry.pushKV("hex", EncodeHexTx(*wtx.GetTx()));
- if (verbose) {
+ if (self.Arg<bool>("verbose")) {
PushTxDecoded(*pwallet, wtx, entry);
}
</details>