Skip to content

Commit 30a6c99

Browse files
committed
rpc: access some args by name
Use the new key-based Arg helper in a few locations to show how it is used.
1 parent bbb3126 commit 30a6c99

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

src/rpc/blockchain.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,15 +2149,16 @@ static RPCHelpMan scantxoutset()
21492149
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
21502150
{
21512151
UniValue result(UniValue::VOBJ);
2152-
if (request.params[0].get_str() == "status") {
2152+
const auto action{self.Arg<std::string>("action")};
2153+
if (action == "status") {
21532154
CoinsViewScanReserver reserver;
21542155
if (reserver.reserve()) {
21552156
// no scan in progress
21562157
return UniValue::VNULL;
21572158
}
21582159
result.pushKV("progress", g_scan_progress.load());
21592160
return result;
2160-
} else if (request.params[0].get_str() == "abort") {
2161+
} else if (action == "abort") {
21612162
CoinsViewScanReserver reserver;
21622163
if (reserver.reserve()) {
21632164
// reserve was possible which means no scan was running
@@ -2166,7 +2167,7 @@ static RPCHelpMan scantxoutset()
21662167
// set the abort flag
21672168
g_should_abort_scan = true;
21682169
return true;
2169-
} else if (request.params[0].get_str() == "start") {
2170+
} else if (action == "start") {
21702171
CoinsViewScanReserver reserver;
21712172
if (!reserver.reserve()) {
21722173
throw JSONRPCError(RPC_INVALID_PARAMETER, "Scan already in progress, use action \"abort\" or \"status\"");
@@ -2235,7 +2236,7 @@ static RPCHelpMan scantxoutset()
22352236
result.pushKV("unspents", unspents);
22362237
result.pushKV("total_amount", ValueFromAmount(total_in));
22372238
} else {
2238-
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid action '%s'", request.params[0].get_str()));
2239+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid action '%s'", action));
22392240
}
22402241
return result;
22412242
},

src/rpc/mining.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static RPCHelpMan getnetworkhashps()
122122
{
123123
ChainstateManager& chainman = EnsureAnyChainman(request.context);
124124
LOCK(cs_main);
125-
return GetNetworkHashPS(self.Arg<int>(0), self.Arg<int>(1), chainman.ActiveChain());
125+
return GetNetworkHashPS(self.Arg<int>("nblocks"), self.Arg<int>("height"), chainman.ActiveChain());
126126
},
127127
};
128128
}
@@ -229,12 +229,12 @@ static RPCHelpMan generatetodescriptor()
229229
"\nGenerate 11 blocks to mydesc\n" + HelpExampleCli("generatetodescriptor", "11 \"mydesc\"")},
230230
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
231231
{
232-
const auto num_blocks{self.Arg<int>(0)};
233-
const auto max_tries{self.Arg<uint64_t>(2)};
232+
const auto num_blocks{self.Arg<int>("num_blocks")};
233+
const auto max_tries{self.Arg<uint64_t>("maxtries")};
234234

235235
CScript coinbase_script;
236236
std::string error;
237-
if (!getScriptFromDescriptor(self.Arg<std::string>(1), coinbase_script, error)) {
237+
if (!getScriptFromDescriptor(self.Arg<std::string>("descriptor"), coinbase_script, error)) {
238238
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, error);
239239
}
240240

src/rpc/net.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static RPCHelpMan addnode()
322322
},
323323
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
324324
{
325-
const std::string command{request.params[1].get_str()};
325+
const auto command{self.Arg<std::string>("command")};
326326
if (command != "onetry" && command != "add" && command != "remove") {
327327
throw std::runtime_error(
328328
self.ToString());
@@ -331,9 +331,9 @@ static RPCHelpMan addnode()
331331
NodeContext& node = EnsureAnyNodeContext(request.context);
332332
CConnman& connman = EnsureConnman(node);
333333

334-
const std::string node_arg{request.params[0].get_str()};
334+
const auto node_arg{self.Arg<std::string>("node")};
335335
bool node_v2transport = connman.GetLocalServices() & NODE_P2P_V2;
336-
bool use_v2transport = self.MaybeArg<bool>(2).value_or(node_v2transport);
336+
bool use_v2transport = self.MaybeArg<bool>("v2transport").value_or(node_v2transport);
337337

338338
if (use_v2transport && !node_v2transport) {
339339
throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: v2transport requested but not enabled (see -v2transport)");

src/rpc/signmessage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ static RPCHelpMan verifymessage()
3838
},
3939
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
4040
{
41-
std::string strAddress = request.params[0].get_str();
42-
std::string strSign = request.params[1].get_str();
43-
std::string strMessage = request.params[2].get_str();
41+
std::string strAddress = self.Arg<std::string>("address");
42+
std::string strSign = self.Arg<std::string>("signature");
43+
std::string strMessage = self.Arg<std::string>("message");
4444

4545
switch (MessageVerify(strAddress, strSign, strMessage)) {
4646
case MessageVerificationResult::ERR_INVALID_ADDRESS:

src/wallet/rpc/coins.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,12 @@ RPCHelpMan getbalance()
194194

195195
LOCK(pwallet->cs_wallet);
196196

197-
const auto dummy_value{self.MaybeArg<std::string>(0)};
197+
const auto dummy_value{self.MaybeArg<std::string>("dummy")};
198198
if (dummy_value && *dummy_value != "*") {
199199
throw JSONRPCError(RPC_METHOD_DEPRECATED, "dummy first argument must be excluded or set to \"*\".");
200200
}
201201

202-
int min_depth = 0;
203-
if (!request.params[1].isNull()) {
204-
min_depth = request.params[1].getInt<int>();
205-
}
202+
const auto min_depth{self.Arg<int>("minconf")};
206203

207204
bool include_watchonly = ParseIncludeWatchonly(request.params[2], *pwallet);
208205

0 commit comments

Comments
 (0)