rpc: Add MaybeArg() and Arg() default helper

This commit is contained in:
MarcoFalke
2023-08-07 14:53:42 +02:00
parent cd5d2f5f09
commit c00000df16
5 changed files with 113 additions and 8 deletions

View File

@@ -194,8 +194,8 @@ RPCHelpMan getbalance()
LOCK(pwallet->cs_wallet);
const UniValue& dummy_value = request.params[0];
if (!dummy_value.isNull() && dummy_value.get_str() != "*") {
const auto dummy_value{self.MaybeArg<std::string>(0)};
if (dummy_value && *dummy_value != "*") {
throw JSONRPCError(RPC_METHOD_DEPRECATED, "dummy first argument must be excluded or set to \"*\".");
}

View File

@@ -478,7 +478,7 @@ static RPCHelpMan unloadwallet()
// Release the "main" shared pointer and prevent further notifications.
// Note that any attempt to load the same wallet would fail until the wallet
// is destroyed (see CheckUniqueFileid).
std::optional<bool> load_on_start = request.params[1].isNull() ? std::nullopt : std::optional<bool>(request.params[1].get_bool());
std::optional<bool> load_on_start{self.MaybeArg<bool>(1)};
if (!RemoveWallet(context, wallet, load_on_start, warnings)) {
throw JSONRPCError(RPC_MISC_ERROR, "Requested wallet already unloaded");
}