20#include <xrpl/basics/Blob.h> 
   21#include <xrpl/basics/Log.h> 
   22#include <xrpl/basics/Slice.h> 
   23#include <xrpl/basics/base_uint.h> 
   24#include <xrpl/basics/contract.h> 
   25#include <xrpl/beast/utility/instrumentation.h> 
   26#include <xrpl/json/json_value.h> 
   27#include <xrpl/protocol/AccountID.h> 
   28#include <xrpl/protocol/Feature.h> 
   29#include <xrpl/protocol/HashPrefix.h> 
   30#include <xrpl/protocol/InnerObjectFormats.h> 
   31#include <xrpl/protocol/Rules.h> 
   32#include <xrpl/protocol/SField.h> 
   33#include <xrpl/protocol/SOTemplate.h> 
   34#include <xrpl/protocol/STAccount.h> 
   35#include <xrpl/protocol/STAmount.h> 
   36#include <xrpl/protocol/STArray.h> 
   37#include <xrpl/protocol/STBase.h> 
   38#include <xrpl/protocol/STBitString.h> 
   39#include <xrpl/protocol/STBlob.h> 
   40#include <xrpl/protocol/STCurrency.h> 
   41#include <xrpl/protocol/STInteger.h> 
   42#include <xrpl/protocol/STIssue.h> 
   43#include <xrpl/protocol/STNumber.h> 
   44#include <xrpl/protocol/STObject.h> 
   45#include <xrpl/protocol/STPathSet.h> 
   46#include <xrpl/protocol/STVector256.h> 
   47#include <xrpl/protocol/Serializer.h> 
   48#include <xrpl/protocol/detail/STVar.h> 
   64    : 
STBase(other.getFName()), v_(
std::move(other.v_)), mType(other.mType)
 
 
   87    : 
STBase(name), mType(nullptr)
 
   90        Throw<std::runtime_error>(
"Maximum nesting depth of STObject exceeded");
 
 
  105    bool const isAMMObj = name == sfAuctionSlot || name == sfVoteEntry;
 
  106    if (!rules || (rules->enabled(fixInnerObjTemplate) && isAMMObj) ||
 
  107        (rules->enabled(fixInnerObjTemplate2) && !isAMMObj))
 
 
  125    return emplace(n, buf, std::move(*
this));
 
 
  151    v_ = std::move(other.v_);
 
 
  162    for (
auto const& elem : type)
 
 
  174    auto throwFieldErr = [](
std::string const& field, 
char const* description) {
 
  176        ss << 
"Field '" << field << 
"' " << description;
 
  178        JLOG(
debugLog().error()) << 
"STObject::applyTemplate failed: " << text;
 
  179        Throw<FieldErr>(text);
 
  184    v.reserve(type.size());
 
  185    for (
auto const& e : type)
 
  189                return b.get().getFName() == e.sField();
 
  191        if (iter != 
v_.
end())
 
  193            if ((e.style() == 
soeDEFAULT) && iter->get().isDefault())
 
  196                    e.sField().fieldName,
 
  197                    "may not be explicitly set to default.");
 
  199            v.emplace_back(std::move(*iter));
 
  206                throwFieldErr(e.sField().fieldName, 
"is required but missing.");
 
  211    for (
auto const& e : 
v_)
 
  214        if (!e->getFName().isDiscardable())
 
  217                e->getFName().getName(), 
"found in disallowed location.");
 
 
  238    bool reachedEndOfObject = 
false;
 
  253        if (type == STI_OBJECT && field == 1)
 
  255            reachedEndOfObject = 
true;
 
  259        if (type == STI_ARRAY && field == 1)
 
  262                << 
"Encountered object with embedded end-of-array marker";
 
  263            Throw<std::runtime_error>(
"Illegal end-of-array marker in object");
 
  270            JLOG(
debugLog().error()) << 
"Unknown field: field_type=" << type
 
  271                                     << 
", field_name=" << field;
 
  272            Throw<std::runtime_error>(
"Unknown field");
 
  280            obj->applyTemplateFromSField(fn);  
 
  288        sf.cbegin(), sf.cend(), [](
STBase const* lhs, 
STBase const* rhs) {
 
  289            return lhs->getFName() == rhs->getFName();
 
  292    if (dup != sf.cend())
 
  293        Throw<std::runtime_error>(
"Duplicate field detected");
 
  295    return reachedEndOfObject;
 
 
  323    for (
auto const& elem : 
v_)
 
  325        if (elem->getSType() != STI_NOTPRESENT)
 
  332            ret += elem->getFullText();
 
 
  345    for (
auto const& elem : 
v_)
 
  353        ret += elem->getText();
 
 
  375                return (st1.getSType() == st2.getSType()) &&
 
  376                    st1.isEquivalent(st2);
 
  389            return (st1->getSType() == st2->getSType()) &&
 
  390                st1->isEquivalent(*st2);
 
 
  415    if (
mType != 
nullptr)
 
  419    for (
auto const& elem : 
v_)
 
  421        if (elem->getFName() == field)
 
 
  453    return v_[index]->getFName();
 
 
  474        if (createOkay && 
isFree())
 
 
  497    return peekField<STObject>(field);
 
 
  503    return peekField<STArray>(field);
 
 
  562    if (f->
getSType() != STI_NOTPRESENT)
 
 
  605    return getFieldByValue<STUInt8>(field);
 
 
  611    return getFieldByValue<STUInt16>(field);
 
 
  617    return getFieldByValue<STUInt32>(field);
 
 
  623    return getFieldByValue<STUInt64>(field);
 
 
  629    return getFieldByValue<STUInt128>(field);
 
 
  635    return getFieldByValue<STUInt160>(field);
 
 
  641    return getFieldByValue<STUInt192>(field);
 
 
  647    return getFieldByValue<STUInt256>(field);
 
 
  653    return getFieldByValue<STInt32>(field);
 
 
  659    return getFieldByValue<STAccount>(field);
 
 
  666    STBlob const& b = getFieldByConstRef<STBlob>(field, 
empty);
 
 
  674    return getFieldByConstRef<STAmount>(field, 
empty);
 
 
  681    return getFieldByConstRef<STPathSet>(field, 
empty);
 
 
  688    return getFieldByConstRef<STVector256>(field, 
empty);
 
 
  695    auto ret = getFieldByConstRef<STObject>(field, 
empty);
 
  697        ret.applyTemplateFromSField(field);
 
 
  705    return getFieldByConstRef<STArray>(field, 
empty);
 
 
  712    return getFieldByConstRef<STCurrency>(field, 
empty);
 
 
  719    return getFieldByConstRef<STNumber>(field, 
empty);
 
 
  734        v_[i] = std::move(v);
 
  739            Throw<std::runtime_error>(
"missing field in templated STObject");
 
 
  747    setFieldUsingSetValue<STUInt8>(field, v);
 
 
  753    setFieldUsingSetValue<STUInt16>(field, v);
 
 
  759    setFieldUsingSetValue<STUInt32>(field, v);
 
 
  765    setFieldUsingSetValue<STUInt64>(field, v);
 
 
  771    setFieldUsingSetValue<STUInt128>(field, v);
 
 
  777    setFieldUsingSetValue<STUInt256>(field, v);
 
 
  783    setFieldUsingSetValue<STInt32>(field, v);
 
 
  789    setFieldUsingSetValue<STVector256>(field, v);
 
 
  795    setFieldUsingSetValue<STAccount>(field, v);
 
 
  857    for (
auto const& elem : 
v_)
 
  859        if (elem->getSType() != STI_NOTPRESENT)
 
  860            ret[elem->getFName().getJsonName()] = elem->getJson(options);
 
 
  871    for (
auto const& t1 : 
v_)
 
  873        if ((t1->getSType() != STI_NOTPRESENT) && t1->getFName().isBinary())
 
  877            for (
auto const& t2 : obj.
v_)
 
  879                if (t1->getFName() == t2->getFName())
 
  896    for (
auto const& t2 : obj.
v_)
 
  898        if ((t2->getSType() != STI_NOTPRESENT) && t2->getFName().isBinary())
 
 
  917    for (
STBase const* 
const field : fields)
 
  924            (sType != STI_OBJECT) ||
 
  925                (field->getFName().fieldType == STI_OBJECT),
 
  926            "ripple::STObject::add : valid field type");
 
  927        field->addFieldID(s);
 
  929        if (sType == STI_ARRAY || sType == STI_OBJECT)
 
 
  943        STBase const& base = elem.get();
 
  944        if ((base.
getSType() != STI_NOTPRESENT) &&
 
  953        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 SField const & 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 &)
 
void applyTemplate(SOTemplate const &type)
 
Blob getFieldVL(SField const &field) const
 
STObject getFieldObject(SField const &field) const
 
bool hasMatchingEntry(STBase const &)
 
bool clearFlag(std::uint32_t)
 
AccountID getAccountID(SField const &field) const
 
static std::vector< STBase const * > getSortedFields(STObject const &objToSort, WhichFields whichFields)
 
STArray const & getFieldArray(SField const &field) const
 
uint160 getFieldH160(SField const &field) const
 
void setFieldCurrency(SField const &field, STCurrency const &)
 
STBase const * peekAtPField(SField const &field) const
 
STBase const * peekAtPIndex(int offset) const
 
void setFieldArray(SField const &field, STArray const &v)
 
void setFieldPathSet(SField const &field, STPathSet const &)
 
SField const & getFieldSType(int index) const
 
void setFieldObject(SField const &field, STObject const &v)
 
STObject(STObject const &)=default
 
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
 
void setFieldI32(SField const &field, std::int32_t)
 
STBase * copy(std::size_t n, void *buf) const override
 
void makeFieldAbsent(SField const &field)
 
STObject & peekFieldObject(SField const &field)
 
void setFieldU16(SField const &field, std::uint16_t)
 
std::uint64_t getFieldU64(SField const &field) const
 
STBase * makeFieldPresent(SField const &field)
 
void setFieldU8(SField const &field, unsigned char)
 
void set(SOTemplate const &)
 
void add(Serializer &s) const override
 
void setFieldAmount(SField const &field, STAmount const &)
 
bool delField(SField const &field)
 
STBase const & peekAtIndex(int offset) const
 
STBase & getField(SField const &field)
 
STAmount const & getFieldAmount(SField const &field) const
 
std::int32_t getFieldI32(SField const &field) const
 
uint256 getSigningHash(HashPrefix prefix) const
 
uint256 getHash(HashPrefix prefix) const
 
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
 
bool isFieldPresent(SField const &field) const
 
static STObject makeInnerObject(SField const &name)
 
STCurrency const & getFieldCurrency(SField const &field) const
 
bool operator==(STObject const &o) 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)
 
Json::Value getJson(JsonOptions=JsonOptions::none) const override
 
void setFieldH128(SField const &field, uint128 const &)
 
void setFieldU64(SField const &field, std::uint64_t)
 
bool isEquivalent(STBase const &t) const override
 
void setFieldU32(SField const &field, std::uint32_t)
 
STBase const & peekAtField(SField const &field) const
 
STBase * move(std::size_t n, void *buf) override
 
std::size_t emplace_back(Args &&... args)
 
STBase * getPIndex(int offset)
 
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
 
STVector256 const & getFieldV256(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 &.