rpc: access some args by name
Use the new key-based Arg helper in a few locations to show how it is used.
This commit is contained in:
5 files changed
+17
-19
No files matched your search
@@ -2149,7 +2149,8 @@ static RPCHelpMan scantxoutset()
|
|||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
if (request.params[0].get_str() == "status") {
|
const auto action{self.Arg<std::string>("action")};
|
||||||
|
if (action == "status") {
|
||||||
CoinsViewScanReserver reserver;
|
CoinsViewScanReserver reserver;
|
||||||
if (reserver.reserve()) {
|
if (reserver.reserve()) {
|
||||||
// no scan in progress
|
// no scan in progress
|
||||||
@@ -2157,7 +2158,7 @@ static RPCHelpMan scantxoutset()
|
|||||||
}
|
}
|
||||||
result.pushKV("progress", g_scan_progress.load());
|
result.pushKV("progress", g_scan_progress.load());
|
||||||
return result;
|
return result;
|
||||||
} else if (request.params[0].get_str() == "abort") {
|
} else if (action == "abort") {
|
||||||
CoinsViewScanReserver reserver;
|
CoinsViewScanReserver reserver;
|
||||||
if (reserver.reserve()) {
|
if (reserver.reserve()) {
|
||||||
// reserve was possible which means no scan was running
|
// reserve was possible which means no scan was running
|
||||||
@@ -2166,7 +2167,7 @@ static RPCHelpMan scantxoutset()
|
|||||||
// set the abort flag
|
// set the abort flag
|
||||||
g_should_abort_scan = true;
|
g_should_abort_scan = true;
|
||||||
return true;
|
return true;
|
||||||
} else if (request.params[0].get_str() == "start") {
|
} else if (action == "start") {
|
||||||
CoinsViewScanReserver reserver;
|
CoinsViewScanReserver reserver;
|
||||||
if (!reserver.reserve()) {
|
if (!reserver.reserve()) {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Scan already in progress, use action \"abort\" or \"status\"");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Scan already in progress, use action \"abort\" or \"status\"");
|
||||||
@@ -2235,7 +2236,7 @@ static RPCHelpMan scantxoutset()
|
|||||||
result.pushKV("unspents", unspents);
|
result.pushKV("unspents", unspents);
|
||||||
result.pushKV("total_amount", ValueFromAmount(total_in));
|
result.pushKV("total_amount", ValueFromAmount(total_in));
|
||||||
} else {
|
} else {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid action '%s'", request.params[0].get_str()));
|
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid action '%s'", action));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|||||||
+4
-4
@@ -122,7 +122,7 @@ static RPCHelpMan getnetworkhashps()
|
|||||||
{
|
{
|
||||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
return GetNetworkHashPS(self.Arg<int>(0), self.Arg<int>(1), chainman.ActiveChain());
|
return GetNetworkHashPS(self.Arg<int>("nblocks"), self.Arg<int>("height"), chainman.ActiveChain());
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -229,12 +229,12 @@ static RPCHelpMan generatetodescriptor()
|
|||||||
"\nGenerate 11 blocks to mydesc\n" + HelpExampleCli("generatetodescriptor", "11 \"mydesc\"")},
|
"\nGenerate 11 blocks to mydesc\n" + HelpExampleCli("generatetodescriptor", "11 \"mydesc\"")},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
const auto num_blocks{self.Arg<int>(0)};
|
const auto num_blocks{self.Arg<int>("num_blocks")};
|
||||||
const auto max_tries{self.Arg<uint64_t>(2)};
|
const auto max_tries{self.Arg<uint64_t>("maxtries")};
|
||||||
|
|
||||||
CScript coinbase_script;
|
CScript coinbase_script;
|
||||||
std::string error;
|
std::string error;
|
||||||
if (!getScriptFromDescriptor(self.Arg<std::string>(1), coinbase_script, error)) {
|
if (!getScriptFromDescriptor(self.Arg<std::string>("descriptor"), coinbase_script, error)) {
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, error);
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -322,7 +322,7 @@ static RPCHelpMan addnode()
|
|||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
const std::string command{request.params[1].get_str()};
|
const auto command{self.Arg<std::string>("command")};
|
||||||
if (command != "onetry" && command != "add" && command != "remove") {
|
if (command != "onetry" && command != "add" && command != "remove") {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
self.ToString());
|
self.ToString());
|
||||||
@@ -331,9 +331,9 @@ static RPCHelpMan addnode()
|
|||||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||||
CConnman& connman = EnsureConnman(node);
|
CConnman& connman = EnsureConnman(node);
|
||||||
|
|
||||||
const std::string node_arg{request.params[0].get_str()};
|
const auto node_arg{self.Arg<std::string>("node")};
|
||||||
bool node_v2transport = connman.GetLocalServices() & NODE_P2P_V2;
|
bool node_v2transport = connman.GetLocalServices() & NODE_P2P_V2;
|
||||||
bool use_v2transport = self.MaybeArg<bool>(2).value_or(node_v2transport);
|
bool use_v2transport = self.MaybeArg<bool>("v2transport").value_or(node_v2transport);
|
||||||
|
|
||||||
if (use_v2transport && !node_v2transport) {
|
if (use_v2transport && !node_v2transport) {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: v2transport requested but not enabled (see -v2transport)");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: v2transport requested but not enabled (see -v2transport)");
|
||||||
|
|||||||
@@ -38,9 +38,9 @@ static RPCHelpMan verifymessage()
|
|||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
std::string strAddress = request.params[0].get_str();
|
std::string strAddress = self.Arg<std::string>("address");
|
||||||
std::string strSign = request.params[1].get_str();
|
std::string strSign = self.Arg<std::string>("signature");
|
||||||
std::string strMessage = request.params[2].get_str();
|
std::string strMessage = self.Arg<std::string>("message");
|
||||||
|
|
||||||
switch (MessageVerify(strAddress, strSign, strMessage)) {
|
switch (MessageVerify(strAddress, strSign, strMessage)) {
|
||||||
case MessageVerificationResult::ERR_INVALID_ADDRESS:
|
case MessageVerificationResult::ERR_INVALID_ADDRESS:
|
||||||
|
|||||||
@@ -194,15 +194,12 @@ RPCHelpMan getbalance()
|
|||||||
|
|
||||||
LOCK(pwallet->cs_wallet);
|
LOCK(pwallet->cs_wallet);
|
||||||
|
|
||||||
const auto dummy_value{self.MaybeArg<std::string>(0)};
|
const auto dummy_value{self.MaybeArg<std::string>("dummy")};
|
||||||
if (dummy_value && *dummy_value != "*") {
|
if (dummy_value && *dummy_value != "*") {
|
||||||
throw JSONRPCError(RPC_METHOD_DEPRECATED, "dummy first argument must be excluded or set to \"*\".");
|
throw JSONRPCError(RPC_METHOD_DEPRECATED, "dummy first argument must be excluded or set to \"*\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
int min_depth = 0;
|
const auto min_depth{self.Arg<int>("minconf")};
|
||||||
if (!request.params[1].isNull()) {
|
|
||||||
min_depth = request.params[1].getInt<int>();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool include_watchonly = ParseIncludeWatchonly(request.params[2], *pwallet);
|
bool include_watchonly = ParseIncludeWatchonly(request.params[2], *pwallet);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user