20#include <xrpl/basics/Log.h>
21#include <xrpl/protocol/Feature.h>
22#include <xrpl/protocol/InnerObjectFormats.h>
23#include <xrpl/protocol/Rules.h>
24#include <xrpl/protocol/STAccount.h>
25#include <xrpl/protocol/STArray.h>
26#include <xrpl/protocol/STBlob.h>
27#include <xrpl/protocol/STCurrency.h>
28#include <xrpl/protocol/STNumber.h>
29#include <xrpl/protocol/STObject.h>
34 :
STBase(other.getFName()), v_(
std::move(other.v_)), mType(other.mType)
57 :
STBase(name), mType(
nullptr)
60 Throw<std::runtime_error>(
"Maximum nesting depth of STObject exceeded");
75 bool const isAMMObj = name == sfAuctionSlot || name == sfVoteEntry;
76 if (!rules || (rules->enabled(fixInnerObjTemplate) && isAMMObj) ||
77 (rules->enabled(fixInnerObjTemplate2) && !isAMMObj))
95 return emplace(n, buf, std::move(*
this));
121 v_ = std::move(other.v_);
132 for (
auto const& elem : type)
144 auto throwFieldErr = [](
std::string const& field,
char const* description) {
146 ss <<
"Field '" << field <<
"' " << description;
148 JLOG(
debugLog().error()) <<
"STObject::applyTemplate failed: " << text;
149 Throw<FieldErr>(text);
154 v.reserve(type.size());
155 for (
auto const& e : type)
159 return b.get().getFName() == e.sField();
161 if (iter !=
v_.
end())
163 if ((e.style() ==
soeDEFAULT) && iter->get().isDefault())
166 e.sField().fieldName,
167 "may not be explicitly set to default.");
169 v.emplace_back(std::move(*iter));
176 throwFieldErr(e.sField().fieldName,
"is required but missing.");
181 for (
auto const& e :
v_)
184 if (!e->getFName().isDiscardable())
187 e->getFName().getName(),
"found in disallowed location.");
208 bool reachedEndOfObject =
false;
223 if (type == STI_OBJECT && field == 1)
225 reachedEndOfObject =
true;
229 if (type == STI_ARRAY && field == 1)
232 <<
"Encountered object with embedded end-of-array marker";
233 Throw<std::runtime_error>(
"Illegal end-of-array marker in object");
240 JLOG(
debugLog().error()) <<
"Unknown field: field_type=" << type
241 <<
", field_name=" << field;
242 Throw<std::runtime_error>(
"Unknown field");
250 obj->applyTemplateFromSField(fn);
258 sf.cbegin(), sf.cend(), [](
STBase const* lhs,
STBase const* rhs) {
259 return lhs->getFName() == rhs->getFName();
262 if (dup != sf.cend())
263 Throw<std::runtime_error>(
"Duplicate field detected");
265 return reachedEndOfObject;
293 for (
auto const& elem :
v_)
295 if (elem->getSType() != STI_NOTPRESENT)
302 ret += elem->getFullText();
315 for (
auto const& elem :
v_)
323 ret += elem->getText();
345 return (st1.getSType() == st2.getSType()) &&
346 st1.isEquivalent(st2);
359 return (st1->getSType() == st2->getSType()) &&
360 st1->isEquivalent(*st2);
385 if (
mType !=
nullptr)
389 for (
auto const& elem :
v_)
391 if (elem->getFName() == field)
423 return v_[index]->getFName();
444 if (createOkay &&
isFree())
467 return peekField<STObject>(field);
473 return peekField<STArray>(field);
532 if (f->
getSType() != STI_NOTPRESENT)
575 return getFieldByValue<STUInt8>(field);
581 return getFieldByValue<STUInt16>(field);
587 return getFieldByValue<STUInt32>(field);
593 return getFieldByValue<STUInt64>(field);
599 return getFieldByValue<STUInt128>(field);
605 return getFieldByValue<STUInt160>(field);
611 return getFieldByValue<STUInt192>(field);
617 return getFieldByValue<STUInt256>(field);
623 return getFieldByValue<STAccount>(field);
630 STBlob const& b = getFieldByConstRef<STBlob>(field,
empty);
638 return getFieldByConstRef<STAmount>(field,
empty);
645 return getFieldByConstRef<STPathSet>(field,
empty);
652 return getFieldByConstRef<STVector256>(field,
empty);
659 return getFieldByConstRef<STArray>(field,
empty);
666 return getFieldByConstRef<STCurrency>(field,
empty);
673 return getFieldByConstRef<STNumber>(field,
empty);
688 v_[i] = std::move(v);
693 Throw<std::runtime_error>(
"missing field in templated STObject");
701 setFieldUsingSetValue<STUInt8>(field, v);
707 setFieldUsingSetValue<STUInt16>(field, v);
713 setFieldUsingSetValue<STUInt32>(field, v);
719 setFieldUsingSetValue<STUInt64>(field, v);
725 setFieldUsingSetValue<STUInt128>(field, v);
731 setFieldUsingSetValue<STUInt256>(field, v);
737 setFieldUsingSetValue<STVector256>(field, v);
743 setFieldUsingSetValue<STAccount>(field, v);
799 for (
auto const& elem :
v_)
801 if (elem->getSType() != STI_NOTPRESENT)
802 ret[elem->getFName().getJsonName()] = elem->getJson(options);
813 for (
auto const& t1 :
v_)
815 if ((t1->getSType() != STI_NOTPRESENT) && t1->getFName().isBinary())
819 for (
auto const& t2 : obj.
v_)
821 if (t1->getFName() == t2->getFName())
838 for (
auto const& t2 : obj.
v_)
840 if ((t2->getSType() != STI_NOTPRESENT) && t2->getFName().isBinary())
859 for (
STBase const*
const field : fields)
866 (sType != STI_OBJECT) ||
867 (field->getFName().fieldType == STI_OBJECT),
868 "ripple::STObject::add : valid field type");
869 field->addFieldID(s);
871 if (sType == STI_ARRAY || sType == STI_OBJECT)
886 if ((base.
getSType() != STI_NOTPRESENT) &&
895 return lhs->getFName().fieldCode < rhs->getFName().fieldCode;
T adjacent_find(T... args)
Like std::vector<char> but better.
std::string const & getName() const
bool shouldInclude(bool withSigningField) const
static const SField & getField(int fieldCode)
Defines the fields and their attributes within a STObject.
int getIndex(SField const &) const
Retrieve the position of a named field.
A type which can be exported to a well known binary format.
void setFName(SField const &n)
A STBase is a field.
virtual SerializedTypeID getSType() const
SField const & getFName() const
static STBase * emplace(std::size_t n, void *buf, T &&val)
std::uint8_t const * data() const
value_type value() const noexcept
STPathSet const & getFieldPathSet(SField const &field) const
unsigned char getFieldU8(SField const &field) const
uint192 getFieldH192(SField const &field) const
STBase * getPField(SField const &field, bool createOkay=false)
void setFieldIssue(SField const &field, STIssue const &)
Blob getFieldVL(SField const &field) const
bool clearFlag(std::uint32_t)
AccountID getAccountID(SField const &field) const
static std::vector< STBase const * > getSortedFields(STObject const &objToSort, WhichFields whichFields)
uint160 getFieldH160(SField const &field) const
void setFieldCurrency(SField const &field, STCurrency const &)
const STArray & getFieldArray(SField const &field) const
void setFieldArray(SField const &field, STArray const &v)
const STBase * peekAtPField(SField const &field) const
void setFieldPathSet(SField const &field, STPathSet const &)
SField const & getFieldSType(int index) const
STObject(STObject const &)=default
bool isEquivalent(const STBase &t) const override
bool isFlag(std::uint32_t) const
std::uint16_t getFieldU16(SField const &field) const
void setFieldH256(SField const &field, uint256 const &)
void setFieldNumber(SField const &field, STNumber const &)
bool setFlag(std::uint32_t)
std::uint32_t getFieldU32(SField const &field) const
const STVector256 & getFieldV256(SField const &field) const
STBase * copy(std::size_t n, void *buf) const override
void makeFieldAbsent(SField const &field)
const STBase & peekAtIndex(int offset) const
STObject & peekFieldObject(SField const &field)
void setFieldU16(SField const &field, std::uint16_t)
const STBase * peekAtPIndex(int offset) const
std::uint64_t getFieldU64(SField const &field) const
STBase * makeFieldPresent(SField const &field)
void setFieldU8(SField const &field, unsigned char)
bool operator==(const STObject &o) const
void add(Serializer &s) const override
void setFieldAmount(SField const &field, STAmount const &)
bool delField(SField const &field)
bool hasMatchingEntry(const STBase &)
STBase & getField(SField const &field)
STAmount const & getFieldAmount(SField const &field) const
uint256 getSigningHash(HashPrefix prefix) const
uint256 getHash(HashPrefix prefix) const
void set(const SOTemplate &)
int getFieldIndex(SField const &field) const
STBase & getIndex(int offset)
void setFieldUsingAssignment(SField const &field, T const &value)
SerializedTypeID getSType() const override
std::string getFullText() const override
std::string getText() const override
const STBase & peekAtField(SField const &field) const
bool isFieldPresent(SField const &field) const
static STObject makeInnerObject(SField const &name)
const STCurrency & getFieldCurrency(SField const &field) const
void setAccountID(SField const &field, AccountID const &)
uint128 getFieldH128(SField const &field) const
void applyTemplateFromSField(SField const &)
void setFieldV256(SField const &field, STVector256 const &v)
void setFieldH128(SField const &field, uint128 const &)
void setFieldU64(SField const &field, std::uint64_t)
Json::Value getJson(JsonOptions options) const override
void setFieldU32(SField const &field, std::uint32_t)
STBase * move(std::size_t n, void *buf) override
std::size_t emplace_back(Args &&... args)
STBase * getPIndex(int offset)
void applyTemplate(const SOTemplate &type)
STArray & peekFieldArray(SField const &field)
STNumber const & getFieldNumber(SField const &field) const
STObject & operator=(STObject const &)=default
void setFieldVL(SField const &field, Blob const &)
std::uint32_t getFlags() const
uint256 getFieldH256(SField const &field) const
bool isDefault() const override
void getFieldID(int &type, int &name)
std::size_t empty() const noexcept
int addFieldID(int type, int name)
uint256 getSHA512Half() const
An immutable linear range of bytes.
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
std::size_t size() const noexcept
Returns the number of bytes in the storage.
T emplace_back(T... args)
@ objectValue
object value (collection of name/value pairs).
nonPresentObject_t nonPresentObject
defaultObject_t defaultObject
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
beast::Journal debugLog()
Returns a debug journal.
std::vector< unsigned char > Blob
Storage for linear binary data.
std::optional< Rules > const & getCurrentTransactionRules()
HashPrefix
Prefix for hashing functions.
bool matches(char const *string, char const *regex)
Return true if the string loosely matches the regex.
void throwFieldNotFound(SField const &field)
Note, should be treated as flags that can be | and &.