1#include <xrpld/rpc/Context.h>
2#include <xrpld/rpc/Role.h>
4#include <xrpl/json/json_value.h>
5#include <xrpl/json/json_writer.h>
6#include <xrpl/protocol/LedgerFormats.h>
7#include <xrpl/protocol/SField.h>
8#include <xrpl/protocol/TER.h>
9#include <xrpl/protocol/TxFormats.h>
10#include <xrpl/protocol/digest.h>
11#include <xrpl/protocol/jss.h>
13#include <boost/algorithm/string.hpp>
50 auto replace = [&](
char const* oldStr,
char const* newStr) ->
std::string {
52 boost::replace_all(
out, oldStr, newStr);
56 auto contains = [&](
char const* s) ->
bool {
57 return inp.
find(s) != std::string::npos;
62 if (contains(
"512") || contains(
"384") || contains(
"256") ||
63 contains(
"192") || contains(
"160") || contains(
"128"))
64 return replace(
"UINT",
"Hash");
66 return replace(
"UINT",
"UInt");
70 {
"OBJECT",
"STObject"},
72 {
"ACCOUNT",
"AccountID"},
73 {
"LEDGERENTRY",
"LedgerEntry"},
74 {
"NOTPRESENT",
"NotPresent"},
75 {
"PATHSET",
"PathSet"},
77 {
"XCHAIN_BRIDGE",
"XChainBridge"},
80 if (
auto const& it = replacements.find(inp); it != replacements.end())
92 pos = inpToProcess.
find(
"_");
93 if (pos == std::string::npos)
94 pos = inpToProcess.
size();
98 boost::algorithm::to_lower(token);
99 token.
data()[0] -= (
'a' -
'A');
104 if (pos == inpToProcess.
size())
106 inpToProcess = inpToProcess.
substr(pos + 1);
116 defs_[jss::TYPES][
"Done"] = -1;
118 for (
auto const& [rawName, typeValue] :
sTypeMap)
122 defs_[jss::TYPES][typeName] = typeValue;
123 typeMap[typeValue] = typeName;
128 defs_[jss::LEDGER_ENTRY_TYPES][jss::Invalid] = -1;
132 defs_[jss::LEDGER_ENTRY_TYPES][f.getName()] = f.getType();
144 v[jss::isVLEncoded] =
false;
145 v[jss::isSerialized] =
false;
146 v[jss::isSigningField] =
false;
147 v[jss::type] =
"Unknown";
149 defs_[jss::FIELDS][i++] = a;
157 v[jss::isVLEncoded] =
false;
158 v[jss::isSerialized] =
false;
159 v[jss::isSigningField] =
false;
160 v[jss::type] =
"Unknown";
162 defs_[jss::FIELDS][i++] = a;
167 a[0U] =
"ObjectEndMarker";
170 v[jss::isVLEncoded] =
false;
171 v[jss::isSerialized] =
true;
172 v[jss::isSigningField] =
true;
173 v[jss::type] =
"STObject";
175 defs_[jss::FIELDS][i++] = a;
180 a[0U] =
"ArrayEndMarker";
183 v[jss::isVLEncoded] =
false;
184 v[jss::isSerialized] =
true;
185 v[jss::isSigningField] =
true;
186 v[jss::type] =
"STArray";
188 defs_[jss::FIELDS][i++] = a;
193 a[0U] =
"taker_gets_funded";
196 v[jss::isVLEncoded] =
false;
197 v[jss::isSerialized] =
false;
198 v[jss::isSigningField] =
false;
199 v[jss::type] =
"Amount";
201 defs_[jss::FIELDS][i++] = a;
206 a[0U] =
"taker_pays_funded";
209 v[jss::isVLEncoded] =
false;
210 v[jss::isSerialized] =
false;
211 v[jss::isSigningField] =
false;
212 v[jss::type] =
"Amount";
214 defs_[jss::FIELDS][i++] = a;
219 if (f->fieldName ==
"")
224 uint32_t type = f->fieldType;
226 innerObj[jss::nth] = f->fieldValue;
230 innerObj[jss::isVLEncoded] =
231 (type == 7U || type == 8U ||
235 innerObj[jss::isSerialized] =
236 (type < 10000 && f->fieldName !=
"hash" &&
237 f->fieldName !=
"index");
241 innerObj[jss::isSigningField] = f->shouldInclude(
false);
243 innerObj[jss::type] = typeMap[type];
246 innerArray[0U] = f->fieldName;
247 innerArray[1U] = innerObj;
249 defs_[jss::FIELDS][i++] = innerArray;
257 defs_[jss::TRANSACTION_RESULTS][terInfo.first] = code;
262 defs_[jss::TRANSACTION_TYPES][jss::Invalid] = -1;
265 defs_[jss::TRANSACTION_TYPES][f.getName()] = f.getType();
281 auto& params = context.
params;
284 if (params.isMember(jss::hash))
286 if (!params[jss::hash].isString() ||
287 !hash.
parseHex(params[jss::hash].asString()))
292 if (defs.hashMatches(hash))
Outputs a Value in JSON format without formatting (not human friendly).
std::string write(Value const &root) override
Value get(UInt index, Value const &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
static std::unordered_map< int, SField const * > const & getKnownCodeToField()
An immutable linear range of bytes.
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
std::string translate(std::string const &inp)
bool hashMatches(uint256 hash) const
Json::Value const & get() const
JSON (JavaScript Object Notation).
@ arrayValue
array value (ordered list)
@ objectValue
object value (collection of name/value pairs).
Json::Value invalid_field_error(std::string const &name)
static std::string to_string(TableType type)
to_string Returns the name of a table according to its TableType.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static std::map< std::string, int > const sTypeMap
Json::Value doServerDefinitions(RPC::JsonContext &)
std::string to_string(base_uint< Bits, Tag > const &a)
std::unordered_map< TERUnderlyingType, std::pair< char const *const, char const *const > > const & transResults()
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.