24#include <boost/json.hpp>
25#include <boost/json/object.hpp>
26#include <xrpl/beast/core/LexicalCast.h>
50 std::ranges::transform(str, std::begin(str), [](
unsigned char c) {
return std::tolower(c); });
63 std::ranges::transform(str, std::begin(str), [](
unsigned char c) {
return std::toupper(c); });
73inline boost::json::object
76 auto newObject = object;
77 auto const secretFields = {
"secret",
"seed",
"seed_hex",
"passphrase"};
79 if (newObject.contains(
"params") and newObject.at(
"params").is_array() and
80 not newObject.at(
"params").as_array().empty() and newObject.at(
"params").as_array()[0].is_object()) {
81 for (
auto const& secretField : secretFields) {
82 if (newObject.at(
"params").as_array()[0].as_object().contains(secretField))
83 newObject.at(
"params").as_array()[0].as_object()[secretField] =
"*";
88 for (
auto const& secretField : secretFields) {
89 if (newObject.contains(secretField))
90 newObject[secretField] =
"*";
104template <std::
integral Type>
105std::expected<Type, std::string>
108 if (value.is_uint64())
109 return static_cast<Type
>(value.as_uint64());
111 if (value.is_int64())
112 return static_cast<Type
>(value.as_int64());
114 return std::unexpected(
"Value neither uint64 nor int64");
126template <std::
integral Type>
131 if (expectedResult.has_value())
132 return *expectedResult;
134 throw std::logic_error(std::move(expectedResult).error());
143[[nodiscard]]
inline std::expected<uint32_t, std::string>
146 if (not value.is_string()) {
149 if (value.as_string() !=
"validated") {
150 uint32_t ledgerIndex{};
151 if (beast::lexicalCastChecked(ledgerIndex, value.as_string().c_str())) {
154 return std::unexpected(
"Invalid ledger index string");
156 return std::unexpected(
"'validated' ledger index is requested");
This namespace contains various utilities.
Definition AccountUtils.hpp:30
Type integralValueAs(boost::json::value const &value)
Detects the type of number stored in value and casts it back to the requested Type.
Definition JsonUtils.hpp:128
std::string toUpper(std::string str)
Convert a string to uppercase.
Definition JsonUtils.hpp:61
std::expected< Type, std::string > tryIntegralValueAs(boost::json::value const &value)
Detects the type of number stored in value and casts it back to the requested Type.
Definition JsonUtils.hpp:106
boost::json::object removeSecret(boost::json::object const &object)
Removes any detected secret information from a response JSON object.
Definition JsonUtils.hpp:74
std::string toLower(std::string str)
Convert a string to lowercase.
Definition JsonUtils.hpp:48
std::expected< uint32_t, std::string > getLedgerIndex(boost::json::value const &value)
Extracts ledger index from a JSON value which can be either a number or a string.
Definition JsonUtils.hpp:144