mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
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:
parent
bbb31269bf
commit
30a6c99935
5 changed files with 17 additions and 19 deletions
|
@ -2149,7 +2149,8 @@ static RPCHelpMan scantxoutset()
|
|||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
if (request.params[0].get_str() == "status") {
|
||||
const auto action{self.Arg<std::string>("action")};
|
||||
if (action == "status") {
|
||||
CoinsViewScanReserver reserver;
|
||||
if (reserver.reserve()) {
|
||||
// no scan in progress
|
||||
|
@ -2157,7 +2158,7 @@ static RPCHelpMan scantxoutset()
|
|||
}
|
||||
result.pushKV("progress", g_scan_progress.load());
|
||||
return result;
|
||||
} else if (request.params[0].get_str() == "abort") {
|
||||
} else if (action == "abort") {
|
||||
CoinsViewScanReserver reserver;
|
||||
if (reserver.reserve()) {
|
||||
// reserve was possible which means no scan was running
|
||||
|
@ -2166,7 +2167,7 @@ static RPCHelpMan scantxoutset()
|
|||
// set the abort flag
|
||||
g_should_abort_scan = true;
|
||||
return true;
|
||||
} else if (request.params[0].get_str() == "start") {
|
||||
} else if (action == "start") {
|
||||
CoinsViewScanReserver reserver;
|
||||
if (!reserver.reserve()) {
|
||||
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("total_amount", ValueFromAmount(total_in));
|
||||
} 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;
|
||||
},
|
||||
|
|
|
@ -122,7 +122,7 @@ static RPCHelpMan getnetworkhashps()
|
|||
{
|
||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||
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\"")},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
const auto num_blocks{self.Arg<int>(0)};
|
||||
const auto max_tries{self.Arg<uint64_t>(2)};
|
||||
const auto num_blocks{self.Arg<int>("num_blocks")};
|
||||
const auto max_tries{self.Arg<uint64_t>("maxtries")};
|
||||
|
||||
CScript coinbase_script;
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -322,7 +322,7 @@ static RPCHelpMan addnode()
|
|||
},
|
||||
[&](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") {
|
||||
throw std::runtime_error(
|
||||
self.ToString());
|
||||
|
@ -331,9 +331,9 @@ static RPCHelpMan addnode()
|
|||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
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 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) {
|
||||
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
|
||||
{
|
||||
std::string strAddress = request.params[0].get_str();
|
||||
std::string strSign = request.params[1].get_str();
|
||||
std::string strMessage = request.params[2].get_str();
|
||||
std::string strAddress = self.Arg<std::string>("address");
|
||||
std::string strSign = self.Arg<std::string>("signature");
|
||||
std::string strMessage = self.Arg<std::string>("message");
|
||||
|
||||
switch (MessageVerify(strAddress, strSign, strMessage)) {
|
||||
case MessageVerificationResult::ERR_INVALID_ADDRESS:
|
||||
|
|
|
@ -194,15 +194,12 @@ RPCHelpMan getbalance()
|
|||
|
||||
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 != "*") {
|
||||
throw JSONRPCError(RPC_METHOD_DEPRECATED, "dummy first argument must be excluded or set to \"*\".");
|
||||
}
|
||||
|
||||
int min_depth = 0;
|
||||
if (!request.params[1].isNull()) {
|
||||
min_depth = request.params[1].getInt<int>();
|
||||
}
|
||||
const auto min_depth{self.Arg<int>("minconf")};
|
||||
|
||||
bool include_watchonly = ParseIncludeWatchonly(request.params[2], *pwallet);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue