20#include <xrpld/app/misc/NetworkOPs.h>
21#include <xrpld/rpc/Context.h>
22#include <xrpld/rpc/Role.h>
24#include <xrpl/json/json_value.h>
25#include <xrpl/json/json_writer.h>
26#include <xrpl/protocol/LedgerFormats.h>
27#include <xrpl/protocol/SField.h>
28#include <xrpl/protocol/TER.h>
29#include <xrpl/protocol/TxFormats.h>
30#include <xrpl/protocol/digest.h>
31#include <xrpl/protocol/jss.h>
33#include <boost/algorithm/string.hpp>
70 auto replace = [&](
char const* oldStr,
char const* newStr) ->
std::string {
72 boost::replace_all(
out, oldStr, newStr);
76 auto contains = [&](
char const* s) ->
bool {
77 return inp.
find(s) != std::string::npos;
82 if (contains(
"512") || contains(
"384") || contains(
"256") ||
83 contains(
"192") || contains(
"160") || contains(
"128"))
84 return replace(
"UINT",
"Hash");
86 return replace(
"UINT",
"UInt");
90 {
"OBJECT",
"STObject"},
92 {
"ACCOUNT",
"AccountID"},
93 {
"LEDGERENTRY",
"LedgerEntry"},
94 {
"NOTPRESENT",
"NotPresent"},
95 {
"PATHSET",
"PathSet"},
97 {
"XCHAIN_BRIDGE",
"XChainBridge"},
100 if (
auto const& it = replacements.find(inp); it != replacements.end())
112 pos = inpToProcess.
find(
"_");
113 if (pos == std::string::npos)
114 pos = inpToProcess.
size();
116 if (token.
size() > 1)
118 boost::algorithm::to_lower(token);
119 token.
data()[0] -= (
'a' -
'A');
124 if (pos == inpToProcess.
size())
126 inpToProcess = inpToProcess.
substr(pos + 1);
136 defs_[jss::TYPES][
"Done"] = -1;
138 for (
auto const& [rawName, typeValue] :
sTypeMap)
142 defs_[jss::TYPES][typeName] = typeValue;
143 typeMap[typeValue] = typeName;
148 defs_[jss::LEDGER_ENTRY_TYPES][jss::Invalid] = -1;
152 defs_[jss::LEDGER_ENTRY_TYPES][f.getName()] = f.getType();
164 v[jss::isVLEncoded] =
false;
165 v[jss::isSerialized] =
false;
166 v[jss::isSigningField] =
false;
167 v[jss::type] =
"Unknown";
169 defs_[jss::FIELDS][i++] = a;
177 v[jss::isVLEncoded] =
false;
178 v[jss::isSerialized] =
false;
179 v[jss::isSigningField] =
false;
180 v[jss::type] =
"Unknown";
182 defs_[jss::FIELDS][i++] = a;
187 a[0U] =
"ObjectEndMarker";
190 v[jss::isVLEncoded] =
false;
191 v[jss::isSerialized] =
true;
192 v[jss::isSigningField] =
true;
193 v[jss::type] =
"STObject";
195 defs_[jss::FIELDS][i++] = a;
200 a[0U] =
"ArrayEndMarker";
203 v[jss::isVLEncoded] =
false;
204 v[jss::isSerialized] =
true;
205 v[jss::isSigningField] =
true;
206 v[jss::type] =
"STArray";
208 defs_[jss::FIELDS][i++] = a;
213 a[0U] =
"taker_gets_funded";
216 v[jss::isVLEncoded] =
false;
217 v[jss::isSerialized] =
false;
218 v[jss::isSigningField] =
false;
219 v[jss::type] =
"Amount";
221 defs_[jss::FIELDS][i++] = a;
226 a[0U] =
"taker_pays_funded";
229 v[jss::isVLEncoded] =
false;
230 v[jss::isSerialized] =
false;
231 v[jss::isSigningField] =
false;
232 v[jss::type] =
"Amount";
234 defs_[jss::FIELDS][i++] = a;
239 if (f->fieldName ==
"")
244 uint32_t type = f->fieldType;
246 innerObj[jss::nth] = f->fieldValue;
250 innerObj[jss::isVLEncoded] =
251 (type == 7U || type == 8U ||
255 innerObj[jss::isSerialized] =
256 (type < 10000 && f->fieldName !=
"hash" &&
257 f->fieldName !=
"index");
261 innerObj[jss::isSigningField] = f->shouldInclude(
false);
263 innerObj[jss::type] = typeMap[type];
266 innerArray[0U] = f->fieldName;
267 innerArray[1U] = innerObj;
269 defs_[jss::FIELDS][i++] = innerArray;
277 defs_[jss::TRANSACTION_RESULTS][terInfo.first] = code;
282 defs_[jss::TRANSACTION_TYPES][jss::Invalid] = -1;
285 defs_[jss::TRANSACTION_TYPES][f.getName()] = f.getType();
301 auto& params = context.
params;
304 if (params.isMember(jss::hash))
306 if (!params[jss::hash].isString() ||
307 !hash.
parseHex(params[jss::hash].asString()))
312 if (defs.hashMatches(hash))
Outputs a Value in JSON format without formatting (not human friendly).
std::string write(const Value &root) override
Value get(UInt index, const Value &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
bool isMember(const char *key) const
Return true if the object has a member named key.
virtual Json::Value getServerInfo(bool human, bool admin, bool counters)=0
static std::map< int, SField const * > const & getKnownCodeToField()
An immutable linear range of bytes.
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 doServerInfo(RPC::JsonContext &)
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.