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 {
return inp.
find(s) != std::string::npos; };
60 if (contains(
"512") || contains(
"384") || contains(
"256") || contains(
"192") || contains(
"160") ||
62 return replace(
"UINT",
"Hash");
64 return replace(
"UINT",
"UInt");
68 {
"OBJECT",
"STObject"},
70 {
"ACCOUNT",
"AccountID"},
71 {
"LEDGERENTRY",
"LedgerEntry"},
72 {
"NOTPRESENT",
"NotPresent"},
73 {
"PATHSET",
"PathSet"},
75 {
"XCHAIN_BRIDGE",
"XChainBridge"},
78 if (
auto const& it = replacements.find(inp); it != replacements.end())
90 pos = inpToProcess.
find(
"_");
91 if (pos == std::string::npos)
92 pos = inpToProcess.
size();
96 boost::algorithm::to_lower(token);
97 token.
data()[0] -= (
'a' -
'A');
102 if (pos == inpToProcess.
size())
104 inpToProcess = inpToProcess.
substr(pos + 1);
114 defs_[jss::TYPES][
"Done"] = -1;
116 for (
auto const& [rawName, typeValue] :
sTypeMap)
119 defs_[jss::TYPES][typeName] = typeValue;
120 typeMap[typeValue] = typeName;
125 defs_[jss::LEDGER_ENTRY_TYPES][jss::Invalid] = -1;
129 defs_[jss::LEDGER_ENTRY_TYPES][f.getName()] = f.getType();
141 v[jss::isVLEncoded] =
false;
142 v[jss::isSerialized] =
false;
143 v[jss::isSigningField] =
false;
144 v[jss::type] =
"Unknown";
146 defs_[jss::FIELDS][i++] = a;
154 v[jss::isVLEncoded] =
false;
155 v[jss::isSerialized] =
false;
156 v[jss::isSigningField] =
false;
157 v[jss::type] =
"Unknown";
159 defs_[jss::FIELDS][i++] = a;
164 a[0U] =
"ObjectEndMarker";
167 v[jss::isVLEncoded] =
false;
168 v[jss::isSerialized] =
true;
169 v[jss::isSigningField] =
true;
170 v[jss::type] =
"STObject";
172 defs_[jss::FIELDS][i++] = a;
177 a[0U] =
"ArrayEndMarker";
180 v[jss::isVLEncoded] =
false;
181 v[jss::isSerialized] =
true;
182 v[jss::isSigningField] =
true;
183 v[jss::type] =
"STArray";
185 defs_[jss::FIELDS][i++] = a;
190 a[0U] =
"taker_gets_funded";
193 v[jss::isVLEncoded] =
false;
194 v[jss::isSerialized] =
false;
195 v[jss::isSigningField] =
false;
196 v[jss::type] =
"Amount";
198 defs_[jss::FIELDS][i++] = a;
203 a[0U] =
"taker_pays_funded";
206 v[jss::isVLEncoded] =
false;
207 v[jss::isSerialized] =
false;
208 v[jss::isSigningField] =
false;
209 v[jss::type] =
"Amount";
211 defs_[jss::FIELDS][i++] = a;
216 if (f->fieldName ==
"")
221 uint32_t type = f->fieldType;
223 innerObj[jss::nth] = f->fieldValue;
227 innerObj[jss::isVLEncoded] =
228 (type == 7U || type == 8U || type == 19U );
231 innerObj[jss::isSerialized] =
232 (type < 10000 && f->fieldName !=
"hash" && f->fieldName !=
"index");
236 innerObj[jss::isSigningField] = f->shouldInclude(
false);
238 innerObj[jss::type] = typeMap[type];
241 innerArray[0U] = f->fieldName;
242 innerArray[1U] = innerObj;
244 defs_[jss::FIELDS][i++] = innerArray;
252 defs_[jss::TRANSACTION_RESULTS][terInfo.first] = code;
257 defs_[jss::TRANSACTION_TYPES][jss::Invalid] = -1;
260 defs_[jss::TRANSACTION_TYPES][f.getName()] = f.getType();
276 auto& params = context.
params;
279 if (params.isMember(jss::hash))
281 if (!params[jss::hash].isString() || !hash.
parseHex(params[jss::hash].asString()))
286 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.
Json::Value const & get() const
std::string translate(std::string const &inp)
bool hashMatches(uint256 hash) 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.
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
std::string to_string(base_uint< Bits, Tag > const &a)
Json::Value doServerDefinitions(RPC::JsonContext &)
std::unordered_map< TERUnderlyingType, std::pair< char const *const, char const *const > > const & transResults()
static std::map< std::string, int > const sTypeMap