1#include <xrpld/rpc/detail/RPCHelpers.h>
3#include <xrpl/basics/StringUtilities.h>
4#include <xrpl/basics/strHex.h>
5#include <xrpl/beast/core/LexicalCast.h>
6#include <xrpl/json/json_errors.h>
7#include <xrpl/protocol/ErrorCodes.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/RPCErr.h>
10#include <xrpl/protocol/STXChainBridge.h>
11#include <xrpl/protocol/jss.h>
17namespace LedgerEntryHelpers {
26 json[jss::error] = err.value_or(
"malformedRequest");
28 json[jss::error_message] = std::move(error);
40 json[jss::error] = err;
42 json[jss::error_message] = std::move(error);
50 json[jss::error] = err;
52 json[jss::error_message] = message;
62 for (
auto const field : fields)
88 if (
auto obj = parse<T>(params[fieldName]))
102 auto const account = parseBase58<AccountID>(param.
asString());
103 if (!account || account->isZero())
117 return required<AccountID>(params, fieldName, err,
"AccountID");
127 if (!blob || blob->empty() || blob->size() > maxLength)
144 if (
auto blob =
parseHexBlob(params[fieldName], maxLength))
174 return required<std::uint32_t>(params, fieldName, err,
"number");
196 return required<uint256>(params, fieldName, err,
"Hash256");
218 return required<uint192>(params, fieldName, err,
"Hash192");
241 return required<Issue>(params, fieldName, err,
"Issue");
249 {jss::LockingChainDoor,
250 jss::LockingChainIssue,
251 jss::IssuingChainDoor,
252 jss::IssuingChainIssue});
259 params, jss::LockingChainDoor,
"malformedLockingChainDoor");
260 if (!lockingChainDoor)
266 params, jss::IssuingChainDoor,
"malformedIssuingChainDoor");
267 if (!issuingChainDoor)
272 Issue lockingChainIssue;
275 lockingChainIssue =
issueFromJson(params[jss::LockingChainIssue]);
280 "malformedIssue", jss::LockingChainIssue,
"Issue");
283 Issue issuingChainIssue;
286 issuingChainIssue =
issueFromJson(params[jss::IssuingChainIssue]);
291 "malformedIssue", jss::IssuingChainIssue,
"Issue");
Lightweight wrapper to tag static string.
std::string asString() const
Returns the unquoted string value.
bool isNull() const
isNull() tests to see if this field is null.
bool isMember(char const *key) const
Return true if the object has a member named key.
A currency issued by an account.
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
@ objectValue
object value (collection of name/value pairs).
bool lexicalCastChecked(Out &out, In in)
Intelligently convert from one type to another.
Expected< std::uint32_t, Json::Value > requiredUInt32(Json::Value const ¶ms, Json::StaticString const fieldName, std::string const &err)
Expected< AccountID, Json::Value > requiredAccountID(Json::Value const ¶ms, Json::StaticString const fieldName, std::string const &err)
Unexpected< Json::Value > missingFieldError(Json::StaticString const field, std::optional< std::string > err=std::nullopt)
std::optional< Blob > parseHexBlob(Json::Value const ¶m, std::size_t maxLength)
Expected< uint192, Json::Value > requiredUInt192(Json::Value const ¶ms, Json::StaticString const fieldName, std::string const &err)
Expected< T, Json::Value > required(Json::Value const ¶ms, Json::StaticString const fieldName, std::string const &err, std::string const &expectedType)
Expected< bool, Json::Value > hasRequired(Json::Value const ¶ms, std::initializer_list< Json::StaticString > fields, std::optional< std::string > err=std::nullopt)
Expected< Blob, Json::Value > requiredHexBlob(Json::Value const ¶ms, Json::StaticString const fieldName, std::size_t maxLength, std::string const &err)
Expected< Issue, Json::Value > requiredIssue(Json::Value const ¶ms, Json::StaticString const fieldName, std::string const &err)
Expected< STXChainBridge, Json::Value > parseBridgeFields(Json::Value const ¶ms)
Unexpected< Json::Value > malformedError(std::string const &err, std::string const &message)
std::optional< T > parse(Json::Value const ¶m)
Expected< uint256, Json::Value > requiredUInt256(Json::Value const ¶ms, Json::StaticString const fieldName, std::string const &err)
Unexpected< Json::Value > invalidFieldError(std::string const &err, Json::StaticString const field, std::string const &type)
std::string expected_field_message(std::string const &name, std::string const &type)
std::string missing_field_message(std::string const &name)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
Issue issueFromJson(Json::Value const &v)