fix can_delete

This commit is contained in:
Mayukha Vadari
2025-11-17 17:58:22 +05:30
parent 403bfaa636
commit fb5d878b86
2 changed files with 43 additions and 6 deletions

View File

@@ -1948,8 +1948,16 @@ static RPCCallTestData const rpcCallTestArray[] = {
"can_delete",
"4294967296",
},
RPCCallTestData::bad_cast,
R"()"},
RPCCallTestData::no_exception,
R"({
"method" : "can_delete",
"params" : [
{
"error" : "invalidParams",
"error_message" : "Invalid field 'can_delete'."
}
]
})"},
{// Note: this really shouldn't throw since it's a legitimate ledger hash.
"can_delete: ledger hash with no alphas.",
__LINE__,
@@ -1957,8 +1965,16 @@ static RPCCallTestData const rpcCallTestArray[] = {
"can_delete",
"0123456701234567012345670123456701234567012345670123456701234567",
},
RPCCallTestData::bad_cast,
R"()"},
RPCCallTestData::no_exception,
R"({
"method" : "can_delete",
"params" : [
{
"error" : "invalidParams",
"error_message" : "Invalid field 'can_delete'."
}
]
})"},
// channel_authorize
// -----------------------------------------------------------

View File

@@ -135,7 +135,7 @@ private:
}
}
static std::optional<std::uint32_t>
static std::optional<std::int32_t>
jvParseInt(Json::Value const& param)
{
if (param.isUInt() || param.isInt())
@@ -151,6 +151,22 @@ private:
return std::nullopt;
}
static std::optional<std::uint32_t>
jvParseUInt(Json::Value const& param)
{
if (param.isUInt() || (param.isInt() && param.asInt() >= 0))
return param.asUInt();
if (param.isString())
{
std::uint32_t v;
if (beast::lexicalCastChecked(v, param.asString()))
return v;
}
return std::nullopt;
}
static bool
validPublicKey(
std::string const& strPk,
@@ -418,7 +434,12 @@ private:
std::string input = jvParams[0u].asString();
if (input.find_first_not_of("0123456789") == std::string::npos)
jvRequest["can_delete"] = jvParams[0u].asUInt();
{
if (auto seq = jvParseUInt(jvParams[0u]))
jvRequest["can_delete"] = *seq;
else
return RPC::invalid_field_error(jss::can_delete);
}
else
jvRequest["can_delete"] = input;