mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Extract common function RPC::readLimitField.
This commit is contained in:
committed by
Edward Hennis
parent
a65f692ab7
commit
b2cf1e4c65
@@ -20,6 +20,8 @@
|
||||
#include <ripple/rpc/impl/Utilities.h>
|
||||
#include <ripple/json/json_value.h>
|
||||
#include <ripple/protocol/JsonFields.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <ripple/rpc/Context.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/format.hpp>
|
||||
|
||||
@@ -94,5 +96,23 @@ injectSLE (Json::Value& jv,
|
||||
}
|
||||
}
|
||||
|
||||
boost::optional<Json::Value> readLimitField(
|
||||
unsigned int& limit,
|
||||
Tuning::LimitRange const& range,
|
||||
Context const& context)
|
||||
{
|
||||
limit = range.rdefault;
|
||||
if (auto const& jvLimit = context.params[jss::limit])
|
||||
{
|
||||
if (! (jvLimit.isUInt() || (jvLimit.isInt() && jvLimit.asInt() >= 0)))
|
||||
return RPC::expected_field_error (jss::limit, "unsigned integer");
|
||||
|
||||
limit = jvLimit.asUInt();
|
||||
if (context.role != Role::ADMIN)
|
||||
limit = std::max(range.rmin, std::min(range.rmax, limit));
|
||||
}
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
} // ripple
|
||||
} // RPC
|
||||
|
||||
Reference in New Issue
Block a user