mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
@@ -36,66 +36,6 @@ clio::Logger gLog{"RPC"};
|
||||
|
||||
namespace RPC {
|
||||
|
||||
std::optional<bool>
|
||||
getBool(boost::json::object const& request, std::string const& field)
|
||||
{
|
||||
if (!request.contains(field))
|
||||
return {};
|
||||
else if (request.at(field).is_bool())
|
||||
return request.at(field).as_bool();
|
||||
else
|
||||
throw InvalidParamsError("Invalid field " + field + ", not bool.");
|
||||
}
|
||||
|
||||
bool
|
||||
getBool(boost::json::object const& request, std::string const& field, bool dfault)
|
||||
{
|
||||
if (auto res = getBool(request, field))
|
||||
return *res;
|
||||
else
|
||||
return dfault;
|
||||
}
|
||||
|
||||
bool
|
||||
getRequiredBool(boost::json::object const& request, std::string const& field)
|
||||
{
|
||||
if (auto res = getBool(request, field))
|
||||
return *res;
|
||||
else
|
||||
throw InvalidParamsError("Missing field " + field);
|
||||
}
|
||||
|
||||
std::optional<std::uint32_t>
|
||||
getUInt(boost::json::object const& request, std::string const& field)
|
||||
{
|
||||
if (!request.contains(field))
|
||||
return {};
|
||||
else if (request.at(field).is_uint64())
|
||||
return request.at(field).as_uint64();
|
||||
else if (request.at(field).is_int64())
|
||||
return request.at(field).as_int64();
|
||||
else
|
||||
throw InvalidParamsError("Invalid field " + field + ", not uint.");
|
||||
}
|
||||
|
||||
std::uint32_t
|
||||
getUInt(boost::json::object const& request, std::string const& field, std::uint32_t const dfault)
|
||||
{
|
||||
if (auto res = getUInt(request, field))
|
||||
return *res;
|
||||
else
|
||||
return dfault;
|
||||
}
|
||||
|
||||
std::uint32_t
|
||||
getRequiredUInt(boost::json::object const& request, std::string const& field)
|
||||
{
|
||||
if (auto res = getUInt(request, field))
|
||||
return *res;
|
||||
else
|
||||
throw InvalidParamsError("Missing field " + field);
|
||||
}
|
||||
|
||||
std::optional<AccountCursor>
|
||||
parseAccountCursor(std::optional<std::string> jsonCursor)
|
||||
{
|
||||
@@ -130,143 +70,6 @@ parseAccountCursor(std::optional<std::string> jsonCursor)
|
||||
return AccountCursor({cursorIndex, startHint});
|
||||
}
|
||||
|
||||
std::optional<std::string>
|
||||
getString(boost::json::object const& request, std::string const& field)
|
||||
{
|
||||
if (!request.contains(field))
|
||||
return {};
|
||||
else if (request.at(field).is_string())
|
||||
return request.at(field).as_string().c_str();
|
||||
else
|
||||
throw InvalidParamsError("Invalid field " + field + ", not string.");
|
||||
}
|
||||
|
||||
std::string
|
||||
getRequiredString(boost::json::object const& request, std::string const& field)
|
||||
{
|
||||
if (auto res = getString(request, field))
|
||||
return *res;
|
||||
else
|
||||
throw InvalidParamsError("Missing field " + field);
|
||||
}
|
||||
|
||||
std::string
|
||||
getString(boost::json::object const& request, std::string const& field, std::string dfault)
|
||||
{
|
||||
if (auto res = getString(request, field))
|
||||
return *res;
|
||||
else
|
||||
return dfault;
|
||||
}
|
||||
|
||||
Status
|
||||
getHexMarker(boost::json::object const& request, ripple::uint256& marker)
|
||||
{
|
||||
if (request.contains(JS(marker)))
|
||||
{
|
||||
if (!request.at(JS(marker)).is_string())
|
||||
return Status{RippledError::rpcINVALID_PARAMS, "markerNotString"};
|
||||
|
||||
if (!marker.parseHex(request.at(JS(marker)).as_string().c_str()))
|
||||
return Status{RippledError::rpcINVALID_PARAMS, "malformedMarker"};
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Status
|
||||
getAccount(
|
||||
boost::json::object const& request,
|
||||
ripple::AccountID& account,
|
||||
boost::string_view const& field,
|
||||
bool required)
|
||||
{
|
||||
if (!request.contains(field))
|
||||
{
|
||||
if (required)
|
||||
return Status{RippledError::rpcINVALID_PARAMS, field.to_string() + "Missing"};
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!request.at(field).is_string())
|
||||
return Status{RippledError::rpcINVALID_PARAMS, field.to_string() + "NotString"};
|
||||
|
||||
if (auto a = accountFromStringStrict(request.at(field).as_string().c_str()); a)
|
||||
{
|
||||
account = a.value();
|
||||
return {};
|
||||
}
|
||||
|
||||
return Status{RippledError::rpcACT_MALFORMED, field.to_string() + "Malformed"};
|
||||
}
|
||||
|
||||
Status
|
||||
getOptionalAccount(
|
||||
boost::json::object const& request,
|
||||
std::optional<ripple::AccountID>& account,
|
||||
boost::string_view const& field)
|
||||
{
|
||||
if (!request.contains(field))
|
||||
{
|
||||
account = {};
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!request.at(field).is_string())
|
||||
return Status{RippledError::rpcINVALID_PARAMS, field.to_string() + "NotString"};
|
||||
|
||||
if (auto a = accountFromStringStrict(request.at(field).as_string().c_str()); a)
|
||||
{
|
||||
account = a.value();
|
||||
return {};
|
||||
}
|
||||
|
||||
return Status{RippledError::rpcINVALID_PARAMS, field.to_string() + "Malformed"};
|
||||
}
|
||||
|
||||
Status
|
||||
getAccount(boost::json::object const& request, ripple::AccountID& accountId)
|
||||
{
|
||||
return getAccount(request, accountId, JS(account), true);
|
||||
}
|
||||
|
||||
Status
|
||||
getAccount(boost::json::object const& request, ripple::AccountID& destAccount, boost::string_view const& field)
|
||||
{
|
||||
return getAccount(request, destAccount, field, false);
|
||||
}
|
||||
|
||||
Status
|
||||
getTaker(boost::json::object const& request, ripple::AccountID& takerID)
|
||||
{
|
||||
if (request.contains(JS(taker)))
|
||||
{
|
||||
auto parsed = parseTaker(request.at(JS(taker)));
|
||||
if (auto status = std::get_if<Status>(&parsed); status)
|
||||
return *status;
|
||||
else
|
||||
takerID = std::get<ripple::AccountID>(parsed);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Status
|
||||
getChannelId(boost::json::object const& request, ripple::uint256& channelId)
|
||||
{
|
||||
if (!request.contains(JS(channel_id)))
|
||||
return Status{RippledError::rpcINVALID_PARAMS, "missingChannelID"};
|
||||
|
||||
if (!request.at(JS(channel_id)).is_string())
|
||||
return Status{RippledError::rpcINVALID_PARAMS, "channelIDNotString"};
|
||||
|
||||
if (!channelId.parseHex(request.at(JS(channel_id)).as_string().c_str()))
|
||||
return Status{RippledError::rpcCHANNEL_MALFORMED, "malformedChannelID"};
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<ripple::STAmount>
|
||||
getDeliveredAmount(
|
||||
std::shared_ptr<ripple::STTx const> const& txn,
|
||||
@@ -305,11 +108,6 @@ canHaveDeliveredAmount(
|
||||
if (tt != ripple::ttPAYMENT && tt != ripple::ttCHECK_CASH && tt != ripple::ttACCOUNT_DELETE)
|
||||
return false;
|
||||
|
||||
/*
|
||||
if (tt == ttCHECK_CASH && !getFix1623Enabled())
|
||||
return false;
|
||||
*/
|
||||
|
||||
if (meta->getResultTER() != ripple::tesSUCCESS)
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user