refactor: Add and use RPCResultOptions

Initially only move skip_type_check there.

In the future, more options can be added, without having to touch the
constructors.
This commit is contained in:
MarcoFalke
2026-03-11 09:26:31 +01:00
parent b97abdcdf1
commit fa8250e961
4 changed files with 17 additions and 12 deletions

View File

@@ -2739,7 +2739,7 @@ static RPCHelpMan getdescriptoractivity()
{RPCResult::Type::OBJ, "output_spk", "", ScriptPubKeyDoc()},
}},
// TODO is the skip_type_check avoidable with a heterogeneous ARR?
}, /*skip_type_check=*/true},
}, {.skip_type_check=true}, },
},
},
RPCExamples{

View File

@@ -1130,7 +1130,7 @@ static std::optional<UniValue::VType> ExpectedType(RPCResult::Type type)
// NOLINTNEXTLINE(misc-no-recursion)
UniValue RPCResult::MatchesType(const UniValue& result) const
{
if (m_skip_type_check) {
if (m_opts.skip_type_check) {
return true;
}

View File

@@ -292,6 +292,9 @@ struct RPCArg {
std::string ToDescriptionString(bool is_named_arg) const;
};
struct RPCResultOptions {
bool skip_type_check{false};
};
// NOLINTNEXTLINE(misc-no-recursion)
struct RPCResult {
enum class Type {
@@ -314,7 +317,7 @@ struct RPCResult {
const std::string m_key_name; //!< Only used for dicts
const std::vector<RPCResult> m_inner; //!< Only used for arrays or dicts
const bool m_optional;
const bool m_skip_type_check;
const RPCResultOptions m_opts;
const std::string m_description;
const std::string m_cond;
@@ -324,12 +327,13 @@ struct RPCResult {
std::string m_key_name,
bool optional,
std::string description,
std::vector<RPCResult> inner = {})
std::vector<RPCResult> inner = {},
RPCResultOptions opts = {})
: m_type{std::move(type)},
m_key_name{std::move(m_key_name)},
m_inner{std::move(inner)},
m_optional{optional},
m_skip_type_check{false},
m_opts{std::move(opts)},
m_description{std::move(description)},
m_cond{std::move(cond)}
{
@@ -342,8 +346,9 @@ struct RPCResult {
Type type,
std::string m_key_name,
std::string description,
std::vector<RPCResult> inner = {})
: RPCResult{std::move(cond), type, std::move(m_key_name), /*optional=*/false, std::move(description), std::move(inner)} {}
std::vector<RPCResult> inner = {},
RPCResultOptions opts = {})
: RPCResult{std::move(cond), type, std::move(m_key_name), /*optional=*/false, std::move(description), std::move(inner), std::move(opts)} {}
RPCResult(
Type type,
@@ -351,12 +356,12 @@ struct RPCResult {
bool optional,
std::string description,
std::vector<RPCResult> inner = {},
bool skip_type_check = false)
RPCResultOptions opts = {})
: m_type{std::move(type)},
m_key_name{std::move(m_key_name)},
m_inner{std::move(inner)},
m_optional{optional},
m_skip_type_check{skip_type_check},
m_opts{std::move(opts)},
m_description{std::move(description)},
m_cond{}
{
@@ -368,8 +373,8 @@ struct RPCResult {
std::string m_key_name,
std::string description,
std::vector<RPCResult> inner = {},
bool skip_type_check = false)
: RPCResult{type, std::move(m_key_name), /*optional=*/false, std::move(description), std::move(inner), skip_type_check} {}
RPCResultOptions opts = {})
: RPCResult{type, std::move(m_key_name), /*optional=*/false, std::move(description), std::move(inner), std::move(opts)} {}
/** Append the sections of the result. */
void ToSections(Sections& sections, OuterType outer_type = OuterType::NONE, int current_indent = 0) const;

View File

@@ -53,7 +53,7 @@ static RPCHelpMan getwalletinfo()
{
{RPCResult::Type::NUM, "duration", "elapsed seconds since scan start"},
{RPCResult::Type::NUM, "progress", "scanning progress percentage [0.0, 1.0]"},
}, /*skip_type_check=*/true},
}, {.skip_type_check=true}, },
{RPCResult::Type::BOOL, "descriptors", "whether this wallet uses descriptors for output script management"},
{RPCResult::Type::BOOL, "external_signer", "whether this wallet is configured to use an external signer such as a hardware wallet"},
{RPCResult::Type::BOOL, "blank", "Whether this wallet intentionally does not contain any keys, scripts, or descriptors"},