20#include <xrpld/app/main/Application.h>
21#include <xrpld/app/misc/NetworkOPs.h>
22#include <xrpld/rpc/Context.h>
23#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/RPCErr.h>
28#include <xrpl/protocol/SField.h>
29#include <xrpl/protocol/TER.h>
30#include <xrpl/protocol/TxFormats.h>
31#include <xrpl/protocol/digest.h>
32#include <xrpl/protocol/jss.h>
34#include <boost/algorithm/string.hpp>
71 auto replace = [&](
char const* oldStr,
char const* newStr) ->
std::string {
73 boost::replace_all(
out, oldStr, newStr);
77 auto contains = [&](
char const* s) ->
bool {
78 return inp.
find(s) != std::string::npos;
83 if (contains(
"512") || contains(
"384") || contains(
"256") ||
84 contains(
"192") || contains(
"160") || contains(
"128"))
85 return replace(
"UINT",
"Hash");
87 return replace(
"UINT",
"UInt");
91 {
"OBJECT",
"STObject"},
93 {
"ACCOUNT",
"AccountID"},
94 {
"LEDGERENTRY",
"LedgerEntry"},
95 {
"NOTPRESENT",
"NotPresent"},
96 {
"PATHSET",
"PathSet"},
98 {
"XCHAIN_BRIDGE",
"XChainBridge"},
101 if (
auto const& it = replacements.find(inp); it != replacements.end())
113 pos = inpToProcess.
find(
"_");
114 if (pos == std::string::npos)
115 pos = inpToProcess.
size();
117 if (token.
size() > 1)
119 boost::algorithm::to_lower(token);
120 token.
data()[0] -= (
'a' -
'A');
125 if (pos == inpToProcess.
size())
127 inpToProcess = inpToProcess.
substr(pos + 1);
137 defs_[jss::TYPES][
"Done"] = -1;
139 for (
auto const& [rawName, typeValue] :
sTypeMap)
143 defs_[jss::TYPES][typeName] = typeValue;
144 typeMap[typeValue] = typeName;
149 defs_[jss::LEDGER_ENTRY_TYPES][jss::Invalid] = -1;
153 defs_[jss::LEDGER_ENTRY_TYPES][f.getName()] = f.getType();
165 v[jss::isVLEncoded] =
false;
166 v[jss::isSerialized] =
false;
167 v[jss::isSigningField] =
false;
168 v[jss::type] =
"Unknown";
170 defs_[jss::FIELDS][i++] = a;
178 v[jss::isVLEncoded] =
false;
179 v[jss::isSerialized] =
false;
180 v[jss::isSigningField] =
false;
181 v[jss::type] =
"Unknown";
183 defs_[jss::FIELDS][i++] = a;
188 a[0U] =
"ObjectEndMarker";
191 v[jss::isVLEncoded] =
false;
192 v[jss::isSerialized] =
true;
193 v[jss::isSigningField] =
true;
194 v[jss::type] =
"STObject";
196 defs_[jss::FIELDS][i++] = a;
201 a[0U] =
"ArrayEndMarker";
204 v[jss::isVLEncoded] =
false;
205 v[jss::isSerialized] =
true;
206 v[jss::isSigningField] =
true;
207 v[jss::type] =
"STArray";
209 defs_[jss::FIELDS][i++] = a;
214 a[0U] =
"taker_gets_funded";
217 v[jss::isVLEncoded] =
false;
218 v[jss::isSerialized] =
false;
219 v[jss::isSigningField] =
false;
220 v[jss::type] =
"Amount";
222 defs_[jss::FIELDS][i++] = a;
227 a[0U] =
"taker_pays_funded";
230 v[jss::isVLEncoded] =
false;
231 v[jss::isSerialized] =
false;
232 v[jss::isSigningField] =
false;
233 v[jss::type] =
"Amount";
235 defs_[jss::FIELDS][i++] = a;
240 if (f->fieldName ==
"")
245 uint32_t type = f->fieldType;
247 innerObj[jss::nth] = f->fieldValue;
251 innerObj[jss::isVLEncoded] =
252 (type == 7U || type == 8U ||
256 innerObj[jss::isSerialized] =
257 (type < 10000 && f->fieldName !=
"hash" &&
258 f->fieldName !=
"index");
262 innerObj[jss::isSigningField] = f->shouldInclude(
false);
264 innerObj[jss::type] = typeMap[type];
267 innerArray[0U] = f->fieldName;
268 innerArray[1U] = innerObj;
270 defs_[jss::FIELDS][i++] = innerArray;
278 defs_[jss::TRANSACTION_RESULTS][terInfo.first] = code;
283 defs_[jss::TRANSACTION_TYPES][jss::Invalid] = -1;
286 defs_[jss::TRANSACTION_TYPES][f.getName()] = f.getType();
302 auto& params = context.
params;
305 if (params.isMember(jss::hash))
307 if (!params[jss::hash].isString() ||
308 !hash.
parseHex(params[jss::hash].asString()))
313 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.