mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-27 22:15:49 +00:00
Reduce likelihood of malformed SOTemplate:
Formerly an SOTemplate was default constructed and its elements added using push_back(). This left open the possibility of a malformed SOTemplate if adding one of the elements caused a throw. With this commit the SOTemplate requires an initializer_list of its elements at construction. Elements may not be added after construction. With this approach either the SOTemplate is fully constructed with all of its elements or the constructor throws, which prevents an invalid SOTemplate from even existing. This change requires all SOTemplate construction to be adjusted at the call site. Those changes are also in this commit. The SOE_Flags enum is also renamed to SOEStyle, which harmonizes the name with other uses in the code base. SOEStyle elements are renamed (slightly) to have an "soe" prefix rather than "SOE_". This heads toward reserving identifiers with all upper case for macros. The new style also aligns with other prominent enums in the code base like the collection of TER identifiers. SOElement is adjusted so it can be stored directly in an STL container, rather than requiring storage in a unique_ptr. Correspondingly, unique_ptr usage is removed from both SOTemplate and KnownFormats.
This commit is contained in:
committed by
Nik Bougalis
parent
57fe197d3e
commit
afcc4ff296
@@ -39,32 +39,30 @@ boost::optional<Manifest> deserializeManifest(Slice s)
|
|||||||
if (s.empty())
|
if (s.empty())
|
||||||
return boost::none;
|
return boost::none;
|
||||||
|
|
||||||
static SOTemplate const manifestFormat (
|
static SOTemplate const manifestFormat {
|
||||||
[](SOTemplate& t)
|
|
||||||
{
|
|
||||||
// A manifest must include:
|
// A manifest must include:
|
||||||
// - the master public key
|
// - the master public key
|
||||||
t.push_back (SOElement (sfPublicKey, SOE_REQUIRED));
|
{sfPublicKey, soeREQUIRED},
|
||||||
|
|
||||||
// - a signature with that public key
|
// - a signature with that public key
|
||||||
t.push_back (SOElement (sfMasterSignature, SOE_REQUIRED));
|
{sfMasterSignature, soeREQUIRED},
|
||||||
|
|
||||||
// - a sequence number
|
// - a sequence number
|
||||||
t.push_back (SOElement (sfSequence, SOE_REQUIRED));
|
{sfSequence, soeREQUIRED},
|
||||||
|
|
||||||
// It may, optionally, contain:
|
// It may, optionally, contain:
|
||||||
// - a version number which defaults to 0
|
// - a version number which defaults to 0
|
||||||
t.push_back (SOElement (sfVersion, SOE_DEFAULT));
|
{sfVersion, soeDEFAULT},
|
||||||
|
|
||||||
// - a domain name
|
// - a domain name
|
||||||
t.push_back (SOElement (sfDomain, SOE_OPTIONAL));
|
{sfDomain, soeOPTIONAL},
|
||||||
|
|
||||||
// - an ephemeral signing key that can be changed as necessary
|
// - an ephemeral signing key that can be changed as necessary
|
||||||
t.push_back (SOElement (sfSigningPubKey, SOE_OPTIONAL));
|
{sfSigningPubKey, soeOPTIONAL},
|
||||||
|
|
||||||
// - a signature using the ephemeral signing key, if it is present
|
// - a signature using the ephemeral signing key, if it is present
|
||||||
t.push_back (SOElement (sfSignature, SOE_OPTIONAL));
|
{sfSignature, soeOPTIONAL},
|
||||||
});
|
};
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,18 +29,12 @@ namespace ripple {
|
|||||||
class InnerObjectFormats : public KnownFormats <int>
|
class InnerObjectFormats : public KnownFormats <int>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
void addCommonFields (Item& item) override;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual ~InnerObjectFormats () = default;
|
|
||||||
InnerObjectFormats(InnerObjectFormats const&) = delete;
|
|
||||||
InnerObjectFormats& operator=(InnerObjectFormats const&) = delete;
|
|
||||||
|
|
||||||
/** Create the object.
|
/** Create the object.
|
||||||
This will load the object will all the known inner object formats.
|
This will load the object with all the known inner object formats.
|
||||||
*/
|
*/
|
||||||
InnerObjectFormats ();
|
InnerObjectFormats ();
|
||||||
|
|
||||||
|
public:
|
||||||
static InnerObjectFormats const& getInstance ();
|
static InnerObjectFormats const& getInstance ();
|
||||||
|
|
||||||
SOTemplate const* findSOTemplateBySField (SField const& sField) const;
|
SOTemplate const* findSOTemplateBySField (SField const& sField) const;
|
||||||
|
|||||||
@@ -22,7 +22,9 @@
|
|||||||
|
|
||||||
#include <ripple/basics/contract.h>
|
#include <ripple/basics/contract.h>
|
||||||
#include <ripple/protocol/SOTemplate.h>
|
#include <ripple/protocol/SOTemplate.h>
|
||||||
#include <memory>
|
#include <boost/container/flat_map.hpp>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <forward_list>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|
||||||
@@ -42,50 +44,49 @@ public:
|
|||||||
class Item
|
class Item
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Item (char const* name, KeyType type)
|
Item (char const* name,
|
||||||
: m_name (name)
|
KeyType type,
|
||||||
, m_type (type)
|
std::initializer_list<SOElement> uniqueFields,
|
||||||
|
std::initializer_list<SOElement> commonFields)
|
||||||
|
: soTemplate_ (uniqueFields, commonFields)
|
||||||
|
, name_ (name)
|
||||||
|
, type_ (type)
|
||||||
{
|
{
|
||||||
}
|
// Verify that KeyType is appropriate.
|
||||||
|
static_assert (
|
||||||
Item& operator<< (SOElement const& el)
|
std::is_enum<KeyType>::value ||
|
||||||
{
|
std::is_integral<KeyType>::value,
|
||||||
elements.push_back (el);
|
"KnownFormats KeyType must be integral or enum.");
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Retrieve the name of the format.
|
/** Retrieve the name of the format.
|
||||||
*/
|
*/
|
||||||
std::string const& getName () const noexcept
|
std::string const& getName () const
|
||||||
{
|
{
|
||||||
return m_name;
|
return name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Retrieve the transaction type this format represents.
|
/** Retrieve the transaction type this format represents.
|
||||||
*/
|
*/
|
||||||
KeyType getType () const noexcept
|
KeyType getType () const
|
||||||
{
|
{
|
||||||
return m_type;
|
return type_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
SOTemplate const& getSOTemplate() const
|
||||||
// VFALCO TODO make an accessor for this
|
{
|
||||||
SOTemplate elements;
|
return soTemplate_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string const m_name;
|
SOTemplate soTemplate_;
|
||||||
KeyType const m_type;
|
std::string const name_;
|
||||||
|
KeyType const type_;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
|
||||||
using NameMap = std::map <std::string, Item*>;
|
|
||||||
using TypeMap = std::map <KeyType, Item*>;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/** Create the known formats object.
|
/** Create the known formats object.
|
||||||
|
|
||||||
Derived classes will load the object will all the known formats.
|
Derived classes will load the object with all the known formats.
|
||||||
*/
|
*/
|
||||||
KnownFormats () = default;
|
KnownFormats () = default;
|
||||||
|
|
||||||
@@ -104,7 +105,7 @@ public:
|
|||||||
@param name The name of the type.
|
@param name The name of the type.
|
||||||
@return The type.
|
@return The type.
|
||||||
*/
|
*/
|
||||||
KeyType findTypeByName (std::string const name) const
|
KeyType findTypeByName (std::string const& name) const
|
||||||
{
|
{
|
||||||
Item const* const result = findByName (name);
|
Item const* const result = findByName (name);
|
||||||
|
|
||||||
@@ -116,71 +117,55 @@ public:
|
|||||||
|
|
||||||
/** Retrieve a format based on its type.
|
/** Retrieve a format based on its type.
|
||||||
*/
|
*/
|
||||||
// VFALCO TODO Can we just return the SOElement& ?
|
Item const* findByType (KeyType type) const
|
||||||
Item const* findByType (KeyType type) const noexcept
|
|
||||||
{
|
{
|
||||||
Item* result = nullptr;
|
auto const itr = types_.find (type);
|
||||||
|
if (itr == types_.end())
|
||||||
typename TypeMap::const_iterator const iter = m_types.find (type);
|
return nullptr;
|
||||||
|
return itr->second;
|
||||||
if (iter != m_types.end ())
|
|
||||||
{
|
|
||||||
result = iter->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Retrieve a format based on its name.
|
/** Retrieve a format based on its name.
|
||||||
*/
|
*/
|
||||||
Item const* findByName (std::string const& name) const noexcept
|
Item const* findByName (std::string const& name) const
|
||||||
{
|
{
|
||||||
Item* result = nullptr;
|
auto const itr = names_.find (name);
|
||||||
|
if (itr == names_.end())
|
||||||
typename NameMap::const_iterator const iter = m_names.find (name);
|
return nullptr;
|
||||||
|
return itr->second;
|
||||||
if (iter != m_names.end ())
|
|
||||||
{
|
|
||||||
result = iter->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add a new format.
|
/** Add a new format.
|
||||||
|
|
||||||
The new format has the set of common fields already added.
|
|
||||||
|
|
||||||
@param name The name of this format.
|
@param name The name of this format.
|
||||||
@param type The type of this format.
|
@param type The type of this format.
|
||||||
|
@param uniqueFields An std::initializer_list of unique fields
|
||||||
|
@param commonFields An std::initializer_list of common fields
|
||||||
|
|
||||||
@return The created format.
|
@return The created format.
|
||||||
*/
|
*/
|
||||||
Item& add (char const* name, KeyType type)
|
Item const& add (char const* name, KeyType type,
|
||||||
|
std::initializer_list<SOElement> uniqueFields,
|
||||||
|
std::initializer_list<SOElement> commonFields = {})
|
||||||
{
|
{
|
||||||
m_formats.emplace_back (
|
formats_.emplace_front (name, type, uniqueFields, commonFields);
|
||||||
std::make_unique <Item> (name, type));
|
Item const& item {formats_.front()};
|
||||||
auto& item (*m_formats.back());
|
|
||||||
|
|
||||||
addCommonFields (item);
|
names_[name] = &item;
|
||||||
|
types_[type] = &item;
|
||||||
m_types [item.getType ()] = &item;
|
|
||||||
m_names [item.getName ()] = &item;
|
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds common fields.
|
|
||||||
|
|
||||||
This is called for every new item.
|
|
||||||
*/
|
|
||||||
virtual void addCommonFields (Item& item) = 0;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector <std::unique_ptr <Item>> m_formats;
|
// One of the situations where a std::forward_list is useful. We want to
|
||||||
NameMap m_names;
|
// store each Item in a place where its address won't change. So a node-
|
||||||
TypeMap m_types;
|
// based container is appropriate. But we don't need searchability.
|
||||||
|
std::forward_list<Item> formats_;
|
||||||
|
|
||||||
|
boost::container::flat_map<std::string, Item const*> names_;
|
||||||
|
boost::container::flat_map<KeyType, Item const*> types_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // ripple
|
} // ripple
|
||||||
|
|||||||
@@ -164,13 +164,13 @@ enum LedgerSpecificFlags
|
|||||||
class LedgerFormats : public KnownFormats <LedgerEntryType>
|
class LedgerFormats : public KnownFormats <LedgerEntryType>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
/** Create the object.
|
||||||
|
This will load the object with all the known ledger formats.
|
||||||
|
*/
|
||||||
LedgerFormats ();
|
LedgerFormats ();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static LedgerFormats const& getInstance ();
|
static LedgerFormats const& getInstance ();
|
||||||
|
|
||||||
private:
|
|
||||||
void addCommonFields (Item& item) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // ripple
|
} // ripple
|
||||||
|
|||||||
@@ -22,19 +22,19 @@
|
|||||||
|
|
||||||
#include <ripple/basics/contract.h>
|
#include <ripple/basics/contract.h>
|
||||||
#include <ripple/protocol/SField.h>
|
#include <ripple/protocol/SField.h>
|
||||||
#include <boost/range.hpp>
|
#include <functional>
|
||||||
|
#include <initializer_list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|
||||||
/** Flags for elements in a SOTemplate. */
|
/** Kind of element in each entry of an SOTemplate. */
|
||||||
// VFALCO NOTE these don't look like bit-flags...
|
enum SOEStyle
|
||||||
enum SOE_Flags
|
|
||||||
{
|
{
|
||||||
SOE_INVALID = -1,
|
soeINVALID = -1,
|
||||||
SOE_REQUIRED = 0, // required
|
soeREQUIRED = 0, // required
|
||||||
SOE_OPTIONAL = 1, // optional, may be present with default value
|
soeOPTIONAL = 1, // optional, may be present with default value
|
||||||
SOE_DEFAULT = 2, // optional, if present, must not have default value
|
soeDEFAULT = 2, // optional, if present, must not have default value
|
||||||
};
|
};
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -42,17 +42,28 @@ enum SOE_Flags
|
|||||||
/** An element in a SOTemplate. */
|
/** An element in a SOTemplate. */
|
||||||
class SOElement
|
class SOElement
|
||||||
{
|
{
|
||||||
public:
|
// Use std::reference_wrapper so SOElement can be stored in a std::vector.
|
||||||
SField const& e_field;
|
std::reference_wrapper<SField const> sField_;
|
||||||
SOE_Flags const flags;
|
SOEStyle style_;
|
||||||
|
|
||||||
SOElement (SField const& fieldName, SOE_Flags flags)
|
public:
|
||||||
: e_field (fieldName)
|
SOElement (SField const& fieldName, SOEStyle style)
|
||||||
, flags (flags)
|
: sField_ (fieldName)
|
||||||
|
, style_ (style)
|
||||||
{
|
{
|
||||||
if (! e_field.isUseful())
|
if (! sField_.get().isUseful())
|
||||||
Throw<std::runtime_error> ("SField in SOElement must be useful.");
|
Throw<std::runtime_error> ("SField in SOElement must be useful.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SField const& sField () const
|
||||||
|
{
|
||||||
|
return sField_.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
SOEStyle style () const
|
||||||
|
{
|
||||||
|
return style_;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -64,64 +75,57 @@ public:
|
|||||||
class SOTemplate
|
class SOTemplate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using list_type = std::vector <std::unique_ptr <SOElement const>>;
|
// Copying vectors is expensive. Make this a move-only type until
|
||||||
using iterator_range = boost::iterator_range<list_type::const_iterator>;
|
// there is motivation to change that.
|
||||||
|
SOTemplate(SOTemplate&& other) = default;
|
||||||
|
SOTemplate& operator=(SOTemplate&& other) = default;
|
||||||
|
|
||||||
/** Create an empty template.
|
/** Create a template populated with all fields.
|
||||||
After creating the template, call @ref push_back with the
|
After creating the template fields cannot be
|
||||||
desired fields.
|
added, modified, or removed.
|
||||||
@see push_back
|
|
||||||
*/
|
*/
|
||||||
SOTemplate () = default;
|
SOTemplate (std::initializer_list<SOElement> uniqueFields,
|
||||||
|
std::initializer_list<SOElement> commonFields = {});
|
||||||
SOTemplate(SOTemplate&& other)
|
|
||||||
: mTypes(std::move(other.mTypes))
|
|
||||||
, mIndex(std::move(other.mIndex))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Create a template and pass it to the callback to be populated.
|
|
||||||
|
|
||||||
The callback will typically consist of one or more calls to the
|
|
||||||
@ref push_back member function on the object that it is passed.
|
|
||||||
|
|
||||||
@see push_back
|
|
||||||
*/
|
|
||||||
SOTemplate(std::function<void(SOTemplate&)> callback)
|
|
||||||
: SOTemplate()
|
|
||||||
{
|
|
||||||
if (callback)
|
|
||||||
callback(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Provide for the enumeration of fields */
|
/* Provide for the enumeration of fields */
|
||||||
iterator_range all () const
|
std::vector<SOElement>::const_iterator begin() const
|
||||||
{
|
{
|
||||||
return boost::make_iterator_range(mTypes);
|
return elements_.cbegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<SOElement>::const_iterator cbegin() const
|
||||||
|
{
|
||||||
|
return begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<SOElement>::const_iterator end() const
|
||||||
|
{
|
||||||
|
return elements_.cend();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<SOElement>::const_iterator cend() const
|
||||||
|
{
|
||||||
|
return end();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The number of entries in this template */
|
/** The number of entries in this template */
|
||||||
std::size_t size () const
|
std::size_t size () const
|
||||||
{
|
{
|
||||||
return mTypes.size ();
|
return elements_.size ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add an element to the template. */
|
|
||||||
void push_back (SOElement const& r);
|
|
||||||
|
|
||||||
/** Retrieve the position of a named field. */
|
/** Retrieve the position of a named field. */
|
||||||
int getIndex (SField const&) const;
|
int getIndex (SField const&) const;
|
||||||
|
|
||||||
SOE_Flags
|
SOEStyle
|
||||||
style(SField const& sf) const
|
style(SField const& sf) const
|
||||||
{
|
{
|
||||||
return mTypes[mIndex[sf.getNum()]]->flags;
|
return elements_[indices_[sf.getNum()]].style();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
list_type mTypes;
|
std::vector<SOElement> elements_;
|
||||||
|
std::vector<int> indices_; // field num -> index
|
||||||
std::vector <int> mIndex; // field num -> index
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // ripple
|
} // ripple
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ private:
|
|||||||
typename T::value_type;
|
typename T::value_type;
|
||||||
|
|
||||||
STObject* st_;
|
STObject* st_;
|
||||||
SOE_Flags style_;
|
SOEStyle style_;
|
||||||
TypedField<T> const* f_;
|
TypedField<T> const* f_;
|
||||||
|
|
||||||
Proxy (Proxy const&) = default;
|
Proxy (Proxy const&) = default;
|
||||||
@@ -109,7 +109,7 @@ private:
|
|||||||
|
|
||||||
/** Returns `true` if the field is set.
|
/** Returns `true` if the field is set.
|
||||||
|
|
||||||
Fields with SOE_DEFAULT and set to the
|
Fields with soeDEFAULT and set to the
|
||||||
default value will return `true`
|
default value will return `true`
|
||||||
*/
|
*/
|
||||||
explicit operator bool() const noexcept;
|
explicit operator bool() const noexcept;
|
||||||
@@ -672,7 +672,7 @@ STObject::Proxy<T>::Proxy (STObject* st, TypedField<T> const* f)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
style_ = SOE_INVALID;
|
style_ = soeINVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -684,7 +684,7 @@ STObject::Proxy<T>::value() const ->
|
|||||||
auto const t = find();
|
auto const t = find();
|
||||||
if (t)
|
if (t)
|
||||||
return t->value();
|
return t->value();
|
||||||
if (style_ != SOE_DEFAULT)
|
if (style_ != soeDEFAULT)
|
||||||
Throw<STObject::FieldErr> (
|
Throw<STObject::FieldErr> (
|
||||||
"Missing field '" + this->f_->getName() + "'");
|
"Missing field '" + this->f_->getName() + "'");
|
||||||
return value_type{};
|
return value_type{};
|
||||||
@@ -704,14 +704,14 @@ template <class U>
|
|||||||
void
|
void
|
||||||
STObject::Proxy<T>::assign(U&& u)
|
STObject::Proxy<T>::assign(U&& u)
|
||||||
{
|
{
|
||||||
if (style_ == SOE_DEFAULT &&
|
if (style_ == soeDEFAULT &&
|
||||||
u == value_type{})
|
u == value_type{})
|
||||||
{
|
{
|
||||||
st_->makeFieldAbsent(*f_);
|
st_->makeFieldAbsent(*f_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
T* t;
|
T* t;
|
||||||
if (style_ == SOE_INVALID)
|
if (style_ == soeINVALID)
|
||||||
t = dynamic_cast<T*>(
|
t = dynamic_cast<T*>(
|
||||||
st_->getPField(*f_, true));
|
st_->getPField(*f_, true));
|
||||||
else
|
else
|
||||||
@@ -832,7 +832,7 @@ template <class T>
|
|||||||
bool
|
bool
|
||||||
STObject::OptionalProxy<T>::engaged() const noexcept
|
STObject::OptionalProxy<T>::engaged() const noexcept
|
||||||
{
|
{
|
||||||
return this->style_ == SOE_DEFAULT
|
return this->style_ == soeDEFAULT
|
||||||
|| this->find() != nullptr;
|
|| this->find() != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -840,11 +840,11 @@ template <class T>
|
|||||||
void
|
void
|
||||||
STObject::OptionalProxy<T>::disengage()
|
STObject::OptionalProxy<T>::disengage()
|
||||||
{
|
{
|
||||||
if (this->style_ == SOE_REQUIRED ||
|
if (this->style_ == soeREQUIRED ||
|
||||||
this->style_ == SOE_DEFAULT)
|
this->style_ == soeDEFAULT)
|
||||||
Throw<STObject::FieldErr> (
|
Throw<STObject::FieldErr> (
|
||||||
"Template field error '" + this->f_->getName() + "'");
|
"Template field error '" + this->f_->getName() + "'");
|
||||||
if (this->style_ == SOE_INVALID)
|
if (this->style_ == soeINVALID)
|
||||||
this->st_->delField(*this->f_);
|
this->st_->delField(*this->f_);
|
||||||
else
|
else
|
||||||
this->st_->makeFieldAbsent(*this->f_);
|
this->st_->makeFieldAbsent(*this->f_);
|
||||||
@@ -878,10 +878,10 @@ STObject::operator[](TypedField<T> const& f) const
|
|||||||
{
|
{
|
||||||
assert(mType);
|
assert(mType);
|
||||||
assert(b->getSType() == STI_NOTPRESENT);
|
assert(b->getSType() == STI_NOTPRESENT);
|
||||||
if(mType->style(f) == SOE_OPTIONAL)
|
if(mType->style(f) == soeOPTIONAL)
|
||||||
Throw<STObject::FieldErr> (
|
Throw<STObject::FieldErr> (
|
||||||
"Missing field '" + f.getName() + "'");
|
"Missing field '" + f.getName() + "'");
|
||||||
assert(mType->style(f) == SOE_DEFAULT);
|
assert(mType->style(f) == soeDEFAULT);
|
||||||
// Handle the case where value_type is a
|
// Handle the case where value_type is a
|
||||||
// const reference, otherwise we return
|
// const reference, otherwise we return
|
||||||
// the address of a temporary.
|
// the address of a temporary.
|
||||||
@@ -905,9 +905,9 @@ STObject::operator[](OptionaledField<T> const& of) const
|
|||||||
{
|
{
|
||||||
assert(mType);
|
assert(mType);
|
||||||
assert(b->getSType() == STI_NOTPRESENT);
|
assert(b->getSType() == STI_NOTPRESENT);
|
||||||
if(mType->style(*of.f) == SOE_OPTIONAL)
|
if(mType->style(*of.f) == soeOPTIONAL)
|
||||||
return boost::none;
|
return boost::none;
|
||||||
assert(mType->style(*of.f) == SOE_DEFAULT);
|
assert(mType->style(*of.f) == soeDEFAULT);
|
||||||
return typename T::value_type{};
|
return typename T::value_type{};
|
||||||
}
|
}
|
||||||
return u->value();
|
return u->value();
|
||||||
|
|||||||
@@ -65,14 +65,12 @@ enum TxType
|
|||||||
class TxFormats : public KnownFormats <TxType>
|
class TxFormats : public KnownFormats <TxType>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
void addCommonFields (Item& item) override;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/** Create the object.
|
/** Create the object.
|
||||||
This will load the object will all the known transaction formats.
|
This will load the object with all the known transaction formats.
|
||||||
*/
|
*/
|
||||||
TxFormats ();
|
TxFormats ();
|
||||||
|
|
||||||
|
public:
|
||||||
static TxFormats const& getInstance ();
|
static TxFormats const& getInstance ();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -23,20 +23,18 @@ namespace ripple {
|
|||||||
|
|
||||||
InnerObjectFormats::InnerObjectFormats ()
|
InnerObjectFormats::InnerObjectFormats ()
|
||||||
{
|
{
|
||||||
add (sfSignerEntry.getJsonName ().c_str (), sfSignerEntry.getCode ())
|
add (sfSignerEntry.jsonName.c_str(), sfSignerEntry.getCode(),
|
||||||
<< SOElement (sfAccount, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfSignerWeight, SOE_REQUIRED)
|
|
||||||
;
|
|
||||||
|
|
||||||
add (sfSigner.getJsonName ().c_str (), sfSigner.getCode ())
|
|
||||||
<< SOElement (sfAccount, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfSigningPubKey, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfTxnSignature, SOE_REQUIRED)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InnerObjectFormats::addCommonFields (Item& item)
|
|
||||||
{
|
{
|
||||||
|
{sfAccount, soeREQUIRED},
|
||||||
|
{sfSignerWeight, soeREQUIRED},
|
||||||
|
});
|
||||||
|
|
||||||
|
add (sfSigner.jsonName.c_str(), sfSigner.getCode(),
|
||||||
|
{
|
||||||
|
{sfAccount, soeREQUIRED},
|
||||||
|
{sfSigningPubKey, soeREQUIRED},
|
||||||
|
{sfTxnSignature, soeREQUIRED},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
InnerObjectFormats const&
|
InnerObjectFormats const&
|
||||||
@@ -49,12 +47,11 @@ InnerObjectFormats::getInstance ()
|
|||||||
SOTemplate const*
|
SOTemplate const*
|
||||||
InnerObjectFormats::findSOTemplateBySField (SField const& sField) const
|
InnerObjectFormats::findSOTemplateBySField (SField const& sField) const
|
||||||
{
|
{
|
||||||
SOTemplate const* ret = nullptr;
|
|
||||||
auto itemPtr = findByType (sField.getCode ());
|
auto itemPtr = findByType (sField.getCode ());
|
||||||
if (itemPtr)
|
if (itemPtr)
|
||||||
ret = &(itemPtr->elements);
|
return &(itemPtr->getSOTemplate());
|
||||||
|
|
||||||
return ret;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // ripple
|
} // ripple
|
||||||
|
|||||||
@@ -28,163 +28,188 @@ namespace ripple {
|
|||||||
|
|
||||||
LedgerFormats::LedgerFormats ()
|
LedgerFormats::LedgerFormats ()
|
||||||
{
|
{
|
||||||
add ("AccountRoot", ltACCOUNT_ROOT)
|
// Fields shared by all ledger formats:
|
||||||
<< SOElement (sfAccount, SOE_REQUIRED)
|
static const std::initializer_list<SOElement> commonFields
|
||||||
<< SOElement (sfSequence, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfBalance, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfOwnerCount, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnID, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfAccountTxnID, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfRegularKey, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfEmailHash, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfWalletLocator, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfWalletSize, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfMessageKey, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfTransferRate, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfDomain, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfTickSize, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("DirectoryNode", ltDIR_NODE)
|
|
||||||
<< SOElement (sfOwner, SOE_OPTIONAL) // for owner directories
|
|
||||||
<< SOElement (sfTakerPaysCurrency, SOE_OPTIONAL) // for order book directories
|
|
||||||
<< SOElement (sfTakerPaysIssuer, SOE_OPTIONAL) // for order book directories
|
|
||||||
<< SOElement (sfTakerGetsCurrency, SOE_OPTIONAL) // for order book directories
|
|
||||||
<< SOElement (sfTakerGetsIssuer, SOE_OPTIONAL) // for order book directories
|
|
||||||
<< SOElement (sfExchangeRate, SOE_OPTIONAL) // for order book directories
|
|
||||||
<< SOElement (sfIndexes, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfRootIndex, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfIndexNext, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfIndexPrevious, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("Offer", ltOFFER)
|
|
||||||
<< SOElement (sfAccount, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfSequence, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfTakerPays, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfTakerGets, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfBookDirectory, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfBookNode, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfOwnerNode, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnID, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfExpiration, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("RippleState", ltRIPPLE_STATE)
|
|
||||||
<< SOElement (sfBalance, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfLowLimit, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfHighLimit, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnID, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfLowNode, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfLowQualityIn, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfLowQualityOut, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfHighNode, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfHighQualityIn, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfHighQualityOut, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("Escrow", ltESCROW)
|
|
||||||
<< SOElement (sfAccount, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfDestination, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfAmount, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfCondition, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfCancelAfter, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfFinishAfter, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfSourceTag, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfOwnerNode, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnID, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfDestinationNode, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("LedgerHashes", ltLEDGER_HASHES)
|
|
||||||
<< SOElement (sfFirstLedgerSequence, SOE_OPTIONAL) // Remove if we do a ledger restart
|
|
||||||
<< SOElement (sfLastLedgerSequence, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfHashes, SOE_REQUIRED)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("Amendments", ltAMENDMENTS)
|
|
||||||
<< SOElement (sfAmendments, SOE_OPTIONAL) // Enabled
|
|
||||||
<< SOElement (sfMajorities, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("FeeSettings", ltFEE_SETTINGS)
|
|
||||||
<< SOElement (sfBaseFee, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfReferenceFeeUnits, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfReserveBase, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfReserveIncrement, SOE_REQUIRED)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("Ticket", ltTICKET)
|
|
||||||
<< SOElement (sfAccount, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfSequence, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfOwnerNode, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfTarget, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfExpiration, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
// All fields are SOE_REQUIRED because there is always a
|
|
||||||
// SignerEntries. If there are no SignerEntries the node is deleted.
|
|
||||||
add ("SignerList", ltSIGNER_LIST)
|
|
||||||
<< SOElement (sfOwnerNode, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfSignerQuorum, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfSignerEntries, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfSignerListID, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnID, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("PayChannel", ltPAYCHAN)
|
|
||||||
<< SOElement (sfAccount, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfDestination, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfAmount, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfBalance, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPublicKey, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfSettleDelay, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfExpiration, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfCancelAfter, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfSourceTag, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfOwnerNode, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnID, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("Check", ltCHECK)
|
|
||||||
<< SOElement (sfAccount, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfDestination, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfSendMax, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfSequence, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfOwnerNode, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfDestinationNode, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfExpiration, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfInvoiceID, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfSourceTag, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfPreviousTxnID, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("DepositPreauth", ltDEPOSIT_PREAUTH)
|
|
||||||
<< SOElement (sfAccount, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfAuthorize, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfOwnerNode, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnID, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LedgerFormats::addCommonFields (Item& item)
|
|
||||||
{
|
{
|
||||||
item
|
{ sfLedgerIndex, soeOPTIONAL },
|
||||||
<< SOElement(sfLedgerIndex, SOE_OPTIONAL)
|
{ sfLedgerEntryType, soeREQUIRED },
|
||||||
<< SOElement(sfLedgerEntryType, SOE_REQUIRED)
|
{ sfFlags, soeREQUIRED },
|
||||||
<< SOElement(sfFlags, SOE_REQUIRED)
|
};
|
||||||
;
|
|
||||||
|
add ("AccountRoot", ltACCOUNT_ROOT,
|
||||||
|
{
|
||||||
|
{ sfAccount, soeREQUIRED },
|
||||||
|
{ sfSequence, soeREQUIRED },
|
||||||
|
{ sfBalance, soeREQUIRED },
|
||||||
|
{ sfOwnerCount, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnID, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnLgrSeq, soeREQUIRED },
|
||||||
|
{ sfAccountTxnID, soeOPTIONAL },
|
||||||
|
{ sfRegularKey, soeOPTIONAL },
|
||||||
|
{ sfEmailHash, soeOPTIONAL },
|
||||||
|
{ sfWalletLocator, soeOPTIONAL },
|
||||||
|
{ sfWalletSize, soeOPTIONAL },
|
||||||
|
{ sfMessageKey, soeOPTIONAL },
|
||||||
|
{ sfTransferRate, soeOPTIONAL },
|
||||||
|
{ sfDomain, soeOPTIONAL },
|
||||||
|
{ sfTickSize, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("DirectoryNode", ltDIR_NODE,
|
||||||
|
{
|
||||||
|
{ sfOwner, soeOPTIONAL }, // for owner directories
|
||||||
|
{ sfTakerPaysCurrency, soeOPTIONAL }, // for order book directories
|
||||||
|
{ sfTakerPaysIssuer, soeOPTIONAL }, // for order book directories
|
||||||
|
{ sfTakerGetsCurrency, soeOPTIONAL }, // for order book directories
|
||||||
|
{ sfTakerGetsIssuer, soeOPTIONAL }, // for order book directories
|
||||||
|
{ sfExchangeRate, soeOPTIONAL }, // for order book directories
|
||||||
|
{ sfIndexes, soeREQUIRED },
|
||||||
|
{ sfRootIndex, soeREQUIRED },
|
||||||
|
{ sfIndexNext, soeOPTIONAL },
|
||||||
|
{ sfIndexPrevious, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("Offer", ltOFFER,
|
||||||
|
{
|
||||||
|
{ sfAccount, soeREQUIRED },
|
||||||
|
{ sfSequence, soeREQUIRED },
|
||||||
|
{ sfTakerPays, soeREQUIRED },
|
||||||
|
{ sfTakerGets, soeREQUIRED },
|
||||||
|
{ sfBookDirectory, soeREQUIRED },
|
||||||
|
{ sfBookNode, soeREQUIRED },
|
||||||
|
{ sfOwnerNode, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnID, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnLgrSeq, soeREQUIRED },
|
||||||
|
{ sfExpiration, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("RippleState", ltRIPPLE_STATE,
|
||||||
|
{
|
||||||
|
{ sfBalance, soeREQUIRED },
|
||||||
|
{ sfLowLimit, soeREQUIRED },
|
||||||
|
{ sfHighLimit, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnID, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnLgrSeq, soeREQUIRED },
|
||||||
|
{ sfLowNode, soeOPTIONAL },
|
||||||
|
{ sfLowQualityIn, soeOPTIONAL },
|
||||||
|
{ sfLowQualityOut, soeOPTIONAL },
|
||||||
|
{ sfHighNode, soeOPTIONAL },
|
||||||
|
{ sfHighQualityIn, soeOPTIONAL },
|
||||||
|
{ sfHighQualityOut, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("Escrow", ltESCROW,
|
||||||
|
{
|
||||||
|
{ sfAccount, soeREQUIRED },
|
||||||
|
{ sfDestination, soeREQUIRED },
|
||||||
|
{ sfAmount, soeREQUIRED },
|
||||||
|
{ sfCondition, soeOPTIONAL },
|
||||||
|
{ sfCancelAfter, soeOPTIONAL },
|
||||||
|
{ sfFinishAfter, soeOPTIONAL },
|
||||||
|
{ sfSourceTag, soeOPTIONAL },
|
||||||
|
{ sfDestinationTag, soeOPTIONAL },
|
||||||
|
{ sfOwnerNode, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnID, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnLgrSeq, soeREQUIRED },
|
||||||
|
{ sfDestinationNode, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("LedgerHashes", ltLEDGER_HASHES,
|
||||||
|
{
|
||||||
|
{ sfFirstLedgerSequence, soeOPTIONAL }, // Remove if we do a ledger restart
|
||||||
|
{ sfLastLedgerSequence, soeOPTIONAL },
|
||||||
|
{ sfHashes, soeREQUIRED },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("Amendments", ltAMENDMENTS,
|
||||||
|
{
|
||||||
|
{ sfAmendments, soeOPTIONAL }, // Enabled
|
||||||
|
{ sfMajorities, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("FeeSettings", ltFEE_SETTINGS,
|
||||||
|
{
|
||||||
|
{ sfBaseFee, soeREQUIRED },
|
||||||
|
{ sfReferenceFeeUnits, soeREQUIRED },
|
||||||
|
{ sfReserveBase, soeREQUIRED },
|
||||||
|
{ sfReserveIncrement, soeREQUIRED },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("Ticket", ltTICKET,
|
||||||
|
{
|
||||||
|
{ sfAccount, soeREQUIRED },
|
||||||
|
{ sfSequence, soeREQUIRED },
|
||||||
|
{ sfOwnerNode, soeREQUIRED },
|
||||||
|
{ sfTarget, soeOPTIONAL },
|
||||||
|
{ sfExpiration, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
// All fields are soeREQUIRED because there is always a
|
||||||
|
// SignerEntries. If there are no SignerEntries the node is deleted.
|
||||||
|
add ("SignerList", ltSIGNER_LIST,
|
||||||
|
{
|
||||||
|
{ sfOwnerNode, soeREQUIRED },
|
||||||
|
{ sfSignerQuorum, soeREQUIRED },
|
||||||
|
{ sfSignerEntries, soeREQUIRED },
|
||||||
|
{ sfSignerListID, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnID, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnLgrSeq, soeREQUIRED },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("PayChannel", ltPAYCHAN,
|
||||||
|
{
|
||||||
|
{ sfAccount, soeREQUIRED },
|
||||||
|
{ sfDestination, soeREQUIRED },
|
||||||
|
{ sfAmount, soeREQUIRED },
|
||||||
|
{ sfBalance, soeREQUIRED },
|
||||||
|
{ sfPublicKey, soeREQUIRED },
|
||||||
|
{ sfSettleDelay, soeREQUIRED },
|
||||||
|
{ sfExpiration, soeOPTIONAL },
|
||||||
|
{ sfCancelAfter, soeOPTIONAL },
|
||||||
|
{ sfSourceTag, soeOPTIONAL },
|
||||||
|
{ sfDestinationTag, soeOPTIONAL },
|
||||||
|
{ sfOwnerNode, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnID, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnLgrSeq, soeREQUIRED },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("Check", ltCHECK,
|
||||||
|
{
|
||||||
|
{ sfAccount, soeREQUIRED },
|
||||||
|
{ sfDestination, soeREQUIRED },
|
||||||
|
{ sfSendMax, soeREQUIRED },
|
||||||
|
{ sfSequence, soeREQUIRED },
|
||||||
|
{ sfOwnerNode, soeREQUIRED },
|
||||||
|
{ sfDestinationNode, soeREQUIRED },
|
||||||
|
{ sfExpiration, soeOPTIONAL },
|
||||||
|
{ sfInvoiceID, soeOPTIONAL },
|
||||||
|
{ sfSourceTag, soeOPTIONAL },
|
||||||
|
{ sfDestinationTag, soeOPTIONAL },
|
||||||
|
{ sfPreviousTxnID, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnLgrSeq, soeREQUIRED },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("DepositPreauth", ltDEPOSIT_PREAUTH,
|
||||||
|
{
|
||||||
|
{ sfAccount, soeREQUIRED },
|
||||||
|
{ sfAuthorize, soeREQUIRED },
|
||||||
|
{ sfOwnerNode, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnID, soeREQUIRED },
|
||||||
|
{ sfPreviousTxnLgrSeq, soeREQUIRED },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
LedgerFormats const&
|
LedgerFormats const&
|
||||||
|
|||||||
@@ -21,44 +21,45 @@
|
|||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|
||||||
void SOTemplate::push_back (SOElement const& r)
|
SOTemplate::SOTemplate (
|
||||||
|
std::initializer_list<SOElement> uniqueFields,
|
||||||
|
std::initializer_list<SOElement> commonFields)
|
||||||
|
: indices_ (SField::getNumFields () + 1, -1) // Unmapped indices == -1
|
||||||
{
|
{
|
||||||
// Ensure there is the enough space in the index mapping
|
// Add all SOElements.
|
||||||
// table for all possible fields.
|
elements_.reserve (uniqueFields.size() + commonFields.size());
|
||||||
//
|
elements_.assign (uniqueFields);
|
||||||
if (mIndex.empty ())
|
elements_.insert (elements_.end(), commonFields);
|
||||||
|
|
||||||
|
// Validate and index elements_.
|
||||||
|
for (std::size_t i = 0; i < elements_.size(); ++i)
|
||||||
{
|
{
|
||||||
// Unmapped indices are initialized to -1
|
SField const& sField {elements_[i].sField()};
|
||||||
//
|
|
||||||
mIndex.resize (SField::getNumFields () + 1, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure the field's index is in range
|
// Make sure the field's index is in range
|
||||||
//
|
//
|
||||||
if (r.e_field.getNum() <= 0 || r.e_field.getNum() >= mIndex.size())
|
if (sField.getNum() <= 0 || sField.getNum() >= indices_.size())
|
||||||
Throw<std::runtime_error> ("Invalid field index for SOTemplate.");
|
Throw<std::runtime_error> ("Invalid field index for SOTemplate.");
|
||||||
|
|
||||||
// Make sure that this field hasn't already been assigned
|
// Make sure that this field hasn't already been assigned
|
||||||
//
|
//
|
||||||
if (getIndex (r.e_field) != -1)
|
if (getIndex (sField) != -1)
|
||||||
Throw<std::runtime_error> ("Duplicate field index for SOTemplate.");
|
Throw<std::runtime_error> ("Duplicate field index for SOTemplate.");
|
||||||
|
|
||||||
// Add the field to the index mapping table
|
// Add the field to the index mapping table
|
||||||
//
|
//
|
||||||
mIndex [r.e_field.getNum ()] = mTypes.size ();
|
indices_[sField.getNum ()] = i;
|
||||||
|
}
|
||||||
// Append the new element.
|
|
||||||
//
|
|
||||||
mTypes.push_back (std::make_unique<SOElement const> (r));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int SOTemplate::getIndex (SField const& f) const
|
int SOTemplate::getIndex (SField const& sField) const
|
||||||
{
|
{
|
||||||
// The mapping table should be large enough for any possible field
|
// The mapping table should be large enough for any possible field
|
||||||
//
|
//
|
||||||
assert (f.getNum () < mIndex.size ());
|
if (sField.getNum() <= 0 || sField.getNum() >= indices_.size())
|
||||||
|
Throw<std::runtime_error> ("Invalid field index for getIndex().");
|
||||||
|
|
||||||
return mIndex[f.getNum ()];
|
return indices_[sField.getNum()];
|
||||||
}
|
}
|
||||||
|
|
||||||
} // ripple
|
} // ripple
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ STLedgerEntry::STLedgerEntry (Keylet const& k)
|
|||||||
if (format == nullptr)
|
if (format == nullptr)
|
||||||
Throw<std::runtime_error> ("invalid ledger entry type");
|
Throw<std::runtime_error> ("invalid ledger entry type");
|
||||||
|
|
||||||
set (format->elements);
|
set (format->getSOTemplate());
|
||||||
|
|
||||||
setFieldU16 (sfLedgerEntryType,
|
setFieldU16 (sfLedgerEntryType,
|
||||||
static_cast <std::uint16_t> (type_));
|
static_cast <std::uint16_t> (type_));
|
||||||
@@ -78,7 +78,7 @@ void STLedgerEntry::setSLEType ()
|
|||||||
Throw<std::runtime_error> ("invalid ledger entry type");
|
Throw<std::runtime_error> ("invalid ledger entry type");
|
||||||
|
|
||||||
type_ = format->getType ();
|
type_ = format->getType ();
|
||||||
applyTemplate (format->elements); // May throw
|
applyTemplate (format->getSOTemplate()); // May throw
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string STLedgerEntry::getFullText () const
|
std::string STLedgerEntry::getFullText () const
|
||||||
|
|||||||
@@ -91,12 +91,12 @@ void STObject::set (const SOTemplate& type)
|
|||||||
v_.reserve(type.size());
|
v_.reserve(type.size());
|
||||||
mType = &type;
|
mType = &type;
|
||||||
|
|
||||||
for (auto const& elem : type.all())
|
for (auto const& elem : type)
|
||||||
{
|
{
|
||||||
if (elem->flags != SOE_REQUIRED)
|
if (elem.style() != soeREQUIRED)
|
||||||
v_.emplace_back(detail::nonPresentObject, elem->e_field);
|
v_.emplace_back(detail::nonPresentObject, elem.sField());
|
||||||
else
|
else
|
||||||
v_.emplace_back(detail::defaultObject, elem->e_field);
|
v_.emplace_back(detail::defaultObject, elem.sField());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,16 +114,16 @@ void STObject::applyTemplate (const SOTemplate& type) noexcept (false)
|
|||||||
mType = &type;
|
mType = &type;
|
||||||
decltype(v_) v;
|
decltype(v_) v;
|
||||||
v.reserve(type.size());
|
v.reserve(type.size());
|
||||||
for (auto const& e : type.all())
|
for (auto const& e : type)
|
||||||
{
|
{
|
||||||
auto const iter = std::find_if(
|
auto const iter = std::find_if(
|
||||||
v_.begin(), v_.end(), [&](detail::STVar const& b)
|
v_.begin(), v_.end(), [&](detail::STVar const& b)
|
||||||
{ return b.get().getFName() == e->e_field; });
|
{ return b.get().getFName() == e.sField(); });
|
||||||
if (iter != v_.end())
|
if (iter != v_.end())
|
||||||
{
|
{
|
||||||
if ((e->flags == SOE_DEFAULT) && iter->get().isDefault())
|
if ((e.style() == soeDEFAULT) && iter->get().isDefault())
|
||||||
{
|
{
|
||||||
throwFieldErr (e->e_field.fieldName,
|
throwFieldErr (e.sField().fieldName,
|
||||||
"may not be explicitly set to default.");
|
"may not be explicitly set to default.");
|
||||||
}
|
}
|
||||||
v.emplace_back(std::move(*iter));
|
v.emplace_back(std::move(*iter));
|
||||||
@@ -131,12 +131,12 @@ void STObject::applyTemplate (const SOTemplate& type) noexcept (false)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (e->flags == SOE_REQUIRED)
|
if (e.style() == soeREQUIRED)
|
||||||
{
|
{
|
||||||
throwFieldErr (e->e_field.fieldName,
|
throwFieldErr (e.sField().fieldName,
|
||||||
"is required but missing.");
|
"is required but missing.");
|
||||||
}
|
}
|
||||||
v.emplace_back(detail::nonPresentObject, e->e_field);
|
v.emplace_back(detail::nonPresentObject, e.sField());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto const& e : v_)
|
for (auto const& e : v_)
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ STTx::STTx (STObject&& object) noexcept (false)
|
|||||||
: STObject (std::move (object))
|
: STObject (std::move (object))
|
||||||
{
|
{
|
||||||
tx_type_ = safe_cast<TxType> (getFieldU16 (sfTransactionType));
|
tx_type_ = safe_cast<TxType> (getFieldU16 (sfTransactionType));
|
||||||
applyTemplate (getTxFormat (tx_type_)->elements); // may throw
|
applyTemplate (getTxFormat (tx_type_)->getSOTemplate()); // may throw
|
||||||
tid_ = getHash(HashPrefix::transactionID);
|
tid_ = getHash(HashPrefix::transactionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ STTx::STTx (SerialIter& sit) noexcept (false)
|
|||||||
|
|
||||||
tx_type_ = safe_cast<TxType> (getFieldU16 (sfTransactionType));
|
tx_type_ = safe_cast<TxType> (getFieldU16 (sfTransactionType));
|
||||||
|
|
||||||
applyTemplate (getTxFormat (tx_type_)->elements); // May throw
|
applyTemplate (getTxFormat (tx_type_)->getSOTemplate()); // May throw
|
||||||
tid_ = getHash(HashPrefix::transactionID);
|
tid_ = getHash(HashPrefix::transactionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ STTx::STTx (
|
|||||||
{
|
{
|
||||||
auto format = getTxFormat (type);
|
auto format = getTxFormat (type);
|
||||||
|
|
||||||
set (format->elements);
|
set (format->getSOTemplate());
|
||||||
setFieldU16 (sfTransactionType, format->getType ());
|
setFieldU16 (sfTransactionType, format->getType ());
|
||||||
|
|
||||||
assembler (*this);
|
assembler (*this);
|
||||||
|
|||||||
@@ -147,26 +147,23 @@ SOTemplate const& STValidation::getFormat ()
|
|||||||
{
|
{
|
||||||
struct FormatHolder
|
struct FormatHolder
|
||||||
{
|
{
|
||||||
SOTemplate format;
|
SOTemplate format
|
||||||
|
|
||||||
FormatHolder ()
|
|
||||||
{
|
{
|
||||||
format.push_back (SOElement (sfFlags, SOE_REQUIRED));
|
{ sfFlags, soeREQUIRED },
|
||||||
format.push_back (SOElement (sfLedgerHash, SOE_REQUIRED));
|
{ sfLedgerHash, soeREQUIRED },
|
||||||
format.push_back (SOElement (sfLedgerSequence, SOE_OPTIONAL));
|
{ sfLedgerSequence, soeOPTIONAL },
|
||||||
format.push_back (SOElement (sfCloseTime, SOE_OPTIONAL));
|
{ sfCloseTime, soeOPTIONAL },
|
||||||
format.push_back (SOElement (sfLoadFee, SOE_OPTIONAL));
|
{ sfLoadFee, soeOPTIONAL },
|
||||||
format.push_back (SOElement (sfAmendments, SOE_OPTIONAL));
|
{ sfAmendments, soeOPTIONAL },
|
||||||
format.push_back (SOElement (sfBaseFee, SOE_OPTIONAL));
|
{ sfBaseFee, soeOPTIONAL },
|
||||||
format.push_back (SOElement (sfReserveBase, SOE_OPTIONAL));
|
{ sfReserveBase, soeOPTIONAL },
|
||||||
format.push_back (SOElement (sfReserveIncrement, SOE_OPTIONAL));
|
{ sfReserveIncrement, soeOPTIONAL },
|
||||||
format.push_back (SOElement (sfSigningTime, SOE_REQUIRED));
|
{ sfSigningTime, soeREQUIRED },
|
||||||
format.push_back (SOElement (sfSigningPubKey, SOE_REQUIRED));
|
{ sfSigningPubKey, soeREQUIRED },
|
||||||
format.push_back (SOElement (sfSignature, SOE_OPTIONAL));
|
{ sfSignature, soeOPTIONAL },
|
||||||
format.push_back (SOElement (sfConsensusHash, SOE_OPTIONAL));
|
{ sfConsensusHash, soeOPTIONAL },
|
||||||
format.push_back (SOElement (sfCookie, SOE_OPTIONAL));
|
{ sfCookie, soeOPTIONAL },
|
||||||
|
};
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const FormatHolder holder;
|
static const FormatHolder holder;
|
||||||
|
|||||||
@@ -23,164 +23,205 @@ namespace ripple {
|
|||||||
|
|
||||||
TxFormats::TxFormats ()
|
TxFormats::TxFormats ()
|
||||||
{
|
{
|
||||||
add ("AccountSet", ttACCOUNT_SET)
|
// Fields shared by all txFormats:
|
||||||
<< SOElement (sfEmailHash, SOE_OPTIONAL)
|
static const std::initializer_list<SOElement> commonFields
|
||||||
<< SOElement (sfWalletLocator, SOE_OPTIONAL)
|
{
|
||||||
<< SOElement (sfWalletSize, SOE_OPTIONAL)
|
{ sfTransactionType, soeREQUIRED },
|
||||||
<< SOElement (sfMessageKey, SOE_OPTIONAL)
|
{ sfFlags, soeOPTIONAL },
|
||||||
<< SOElement (sfDomain, SOE_OPTIONAL)
|
{ sfSourceTag, soeOPTIONAL },
|
||||||
<< SOElement (sfTransferRate, SOE_OPTIONAL)
|
{ sfAccount, soeREQUIRED },
|
||||||
<< SOElement (sfSetFlag, SOE_OPTIONAL)
|
{ sfSequence, soeREQUIRED },
|
||||||
<< SOElement (sfClearFlag, SOE_OPTIONAL)
|
{ sfPreviousTxnID, soeOPTIONAL }, // emulate027
|
||||||
<< SOElement (sfTickSize, SOE_OPTIONAL)
|
{ sfLastLedgerSequence, soeOPTIONAL },
|
||||||
;
|
{ sfAccountTxnID, soeOPTIONAL },
|
||||||
|
{ sfFee, soeREQUIRED },
|
||||||
|
{ sfOperationLimit, soeOPTIONAL },
|
||||||
|
{ sfMemos, soeOPTIONAL },
|
||||||
|
{ sfSigningPubKey, soeREQUIRED },
|
||||||
|
{ sfTxnSignature, soeOPTIONAL },
|
||||||
|
{ sfSigners, soeOPTIONAL }, // submit_multisigned
|
||||||
|
};
|
||||||
|
|
||||||
add ("TrustSet", ttTRUST_SET)
|
add ("AccountSet", ttACCOUNT_SET,
|
||||||
<< SOElement (sfLimitAmount, SOE_OPTIONAL)
|
{
|
||||||
<< SOElement (sfQualityIn, SOE_OPTIONAL)
|
{ sfEmailHash, soeOPTIONAL },
|
||||||
<< SOElement (sfQualityOut, SOE_OPTIONAL)
|
{ sfWalletLocator, soeOPTIONAL },
|
||||||
;
|
{ sfWalletSize, soeOPTIONAL },
|
||||||
|
{ sfMessageKey, soeOPTIONAL },
|
||||||
|
{ sfDomain, soeOPTIONAL },
|
||||||
|
{ sfTransferRate, soeOPTIONAL },
|
||||||
|
{ sfSetFlag, soeOPTIONAL },
|
||||||
|
{ sfClearFlag, soeOPTIONAL },
|
||||||
|
{ sfTickSize, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
add ("OfferCreate", ttOFFER_CREATE)
|
add ("TrustSet", ttTRUST_SET,
|
||||||
<< SOElement (sfTakerPays, SOE_REQUIRED)
|
{
|
||||||
<< SOElement (sfTakerGets, SOE_REQUIRED)
|
{ sfLimitAmount, soeOPTIONAL },
|
||||||
<< SOElement (sfExpiration, SOE_OPTIONAL)
|
{ sfQualityIn, soeOPTIONAL },
|
||||||
<< SOElement (sfOfferSequence, SOE_OPTIONAL)
|
{ sfQualityOut, soeOPTIONAL },
|
||||||
;
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
add ("OfferCancel", ttOFFER_CANCEL)
|
add ("OfferCreate", ttOFFER_CREATE,
|
||||||
<< SOElement (sfOfferSequence, SOE_REQUIRED)
|
{
|
||||||
;
|
{ sfTakerPays, soeREQUIRED },
|
||||||
|
{ sfTakerGets, soeREQUIRED },
|
||||||
|
{ sfExpiration, soeOPTIONAL },
|
||||||
|
{ sfOfferSequence, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
add ("SetRegularKey", ttREGULAR_KEY_SET)
|
add ("OfferCancel", ttOFFER_CANCEL,
|
||||||
<< SOElement (sfRegularKey, SOE_OPTIONAL)
|
{
|
||||||
;
|
{ sfOfferSequence, soeREQUIRED },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
add ("Payment", ttPAYMENT)
|
add ("SetRegularKey", ttREGULAR_KEY_SET,
|
||||||
<< SOElement (sfDestination, SOE_REQUIRED)
|
{
|
||||||
<< SOElement (sfAmount, SOE_REQUIRED)
|
{ sfRegularKey, soeOPTIONAL },
|
||||||
<< SOElement (sfSendMax, SOE_OPTIONAL)
|
},
|
||||||
<< SOElement (sfPaths, SOE_DEFAULT)
|
commonFields);
|
||||||
<< SOElement (sfInvoiceID, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfDeliverMin, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("EscrowCreate", ttESCROW_CREATE)
|
add ("Payment", ttPAYMENT,
|
||||||
<< SOElement (sfDestination, SOE_REQUIRED)
|
{
|
||||||
<< SOElement (sfAmount, SOE_REQUIRED)
|
{ sfDestination, soeREQUIRED },
|
||||||
<< SOElement (sfCondition, SOE_OPTIONAL)
|
{ sfAmount, soeREQUIRED },
|
||||||
<< SOElement (sfCancelAfter, SOE_OPTIONAL)
|
{ sfSendMax, soeOPTIONAL },
|
||||||
<< SOElement (sfFinishAfter, SOE_OPTIONAL)
|
{ sfPaths, soeDEFAULT },
|
||||||
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
|
{ sfInvoiceID, soeOPTIONAL },
|
||||||
;
|
{ sfDestinationTag, soeOPTIONAL },
|
||||||
|
{ sfDeliverMin, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
add ("EscrowFinish", ttESCROW_FINISH)
|
add ("EscrowCreate", ttESCROW_CREATE,
|
||||||
<< SOElement (sfOwner, SOE_REQUIRED)
|
{
|
||||||
<< SOElement (sfOfferSequence, SOE_REQUIRED)
|
{ sfDestination, soeREQUIRED },
|
||||||
<< SOElement (sfFulfillment, SOE_OPTIONAL)
|
{ sfAmount, soeREQUIRED },
|
||||||
<< SOElement (sfCondition, SOE_OPTIONAL)
|
{ sfCondition, soeOPTIONAL },
|
||||||
;
|
{ sfCancelAfter, soeOPTIONAL },
|
||||||
|
{ sfFinishAfter, soeOPTIONAL },
|
||||||
|
{ sfDestinationTag, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
add ("EscrowCancel", ttESCROW_CANCEL)
|
add ("EscrowFinish", ttESCROW_FINISH,
|
||||||
<< SOElement (sfOwner, SOE_REQUIRED)
|
{
|
||||||
<< SOElement (sfOfferSequence, SOE_REQUIRED)
|
{ sfOwner, soeREQUIRED },
|
||||||
;
|
{ sfOfferSequence, soeREQUIRED },
|
||||||
|
{ sfFulfillment, soeOPTIONAL },
|
||||||
|
{ sfCondition, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
add ("EnableAmendment", ttAMENDMENT)
|
add ("EscrowCancel", ttESCROW_CANCEL,
|
||||||
<< SOElement (sfLedgerSequence, SOE_REQUIRED)
|
{
|
||||||
<< SOElement (sfAmendment, SOE_REQUIRED)
|
{ sfOwner, soeREQUIRED },
|
||||||
;
|
{ sfOfferSequence, soeREQUIRED },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
add ("SetFee", ttFEE)
|
add ("EnableAmendment", ttAMENDMENT,
|
||||||
<< SOElement (sfLedgerSequence, SOE_OPTIONAL)
|
{
|
||||||
<< SOElement (sfBaseFee, SOE_REQUIRED)
|
{ sfLedgerSequence, soeREQUIRED },
|
||||||
<< SOElement (sfReferenceFeeUnits, SOE_REQUIRED)
|
{ sfAmendment, soeREQUIRED },
|
||||||
<< SOElement (sfReserveBase, SOE_REQUIRED)
|
},
|
||||||
<< SOElement (sfReserveIncrement, SOE_REQUIRED)
|
commonFields);
|
||||||
;
|
|
||||||
|
|
||||||
add ("TicketCreate", ttTICKET_CREATE)
|
add ("SetFee", ttFEE,
|
||||||
<< SOElement (sfTarget, SOE_OPTIONAL)
|
{
|
||||||
<< SOElement (sfExpiration, SOE_OPTIONAL)
|
{ sfLedgerSequence, soeOPTIONAL },
|
||||||
;
|
{ sfBaseFee, soeREQUIRED },
|
||||||
|
{ sfReferenceFeeUnits, soeREQUIRED },
|
||||||
|
{ sfReserveBase, soeREQUIRED },
|
||||||
|
{ sfReserveIncrement, soeREQUIRED },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
add ("TicketCancel", ttTICKET_CANCEL)
|
add ("TicketCreate", ttTICKET_CREATE,
|
||||||
<< SOElement (sfTicketID, SOE_REQUIRED)
|
{
|
||||||
;
|
{ sfTarget, soeOPTIONAL },
|
||||||
|
{ sfExpiration, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("TicketCancel", ttTICKET_CANCEL,
|
||||||
|
{
|
||||||
|
{ sfTicketID, soeREQUIRED },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
// The SignerEntries are optional because a SignerList is deleted by
|
// The SignerEntries are optional because a SignerList is deleted by
|
||||||
// setting the SignerQuorum to zero and omitting SignerEntries.
|
// setting the SignerQuorum to zero and omitting SignerEntries.
|
||||||
add ("SignerListSet", ttSIGNER_LIST_SET)
|
add ("SignerListSet", ttSIGNER_LIST_SET,
|
||||||
<< SOElement (sfSignerQuorum, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfSignerEntries, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("PaymentChannelCreate", ttPAYCHAN_CREATE)
|
|
||||||
<< SOElement (sfDestination, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfAmount, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfSettleDelay, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfPublicKey, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfCancelAfter, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("PaymentChannelFund", ttPAYCHAN_FUND)
|
|
||||||
<< SOElement (sfPayChannel, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfAmount, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfExpiration, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("PaymentChannelClaim", ttPAYCHAN_CLAIM)
|
|
||||||
<< SOElement (sfPayChannel, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfAmount, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfBalance, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfSignature, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfPublicKey, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("CheckCreate", ttCHECK_CREATE)
|
|
||||||
<< SOElement (sfDestination, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfSendMax, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfExpiration, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfInvoiceID, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("CheckCash", ttCHECK_CASH)
|
|
||||||
<< SOElement (sfCheckID, SOE_REQUIRED)
|
|
||||||
<< SOElement (sfAmount, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfDeliverMin, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("CheckCancel", ttCHECK_CANCEL)
|
|
||||||
<< SOElement (sfCheckID, SOE_REQUIRED)
|
|
||||||
;
|
|
||||||
|
|
||||||
add ("DepositPreauth", ttDEPOSIT_PREAUTH)
|
|
||||||
<< SOElement (sfAuthorize, SOE_OPTIONAL)
|
|
||||||
<< SOElement (sfUnauthorize, SOE_OPTIONAL)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TxFormats::addCommonFields (Item& item)
|
|
||||||
{
|
{
|
||||||
item
|
{ sfSignerQuorum, soeREQUIRED },
|
||||||
<< SOElement(sfTransactionType, SOE_REQUIRED)
|
{ sfSignerEntries, soeOPTIONAL },
|
||||||
<< SOElement(sfFlags, SOE_OPTIONAL)
|
},
|
||||||
<< SOElement(sfSourceTag, SOE_OPTIONAL)
|
commonFields);
|
||||||
<< SOElement(sfAccount, SOE_REQUIRED)
|
|
||||||
<< SOElement(sfSequence, SOE_REQUIRED)
|
add ("PaymentChannelCreate", ttPAYCHAN_CREATE,
|
||||||
<< SOElement(sfPreviousTxnID, SOE_OPTIONAL) // emulate027
|
{
|
||||||
<< SOElement(sfLastLedgerSequence, SOE_OPTIONAL)
|
{ sfDestination, soeREQUIRED },
|
||||||
<< SOElement(sfAccountTxnID, SOE_OPTIONAL)
|
{ sfAmount, soeREQUIRED },
|
||||||
<< SOElement(sfFee, SOE_REQUIRED)
|
{ sfSettleDelay, soeREQUIRED },
|
||||||
<< SOElement(sfOperationLimit, SOE_OPTIONAL)
|
{ sfPublicKey, soeREQUIRED },
|
||||||
<< SOElement(sfMemos, SOE_OPTIONAL)
|
{ sfCancelAfter, soeOPTIONAL },
|
||||||
<< SOElement(sfSigningPubKey, SOE_REQUIRED)
|
{ sfDestinationTag, soeOPTIONAL },
|
||||||
<< SOElement(sfTxnSignature, SOE_OPTIONAL)
|
},
|
||||||
<< SOElement(sfSigners, SOE_OPTIONAL) // submit_multisigned
|
commonFields);
|
||||||
;
|
|
||||||
|
add ("PaymentChannelFund", ttPAYCHAN_FUND,
|
||||||
|
{
|
||||||
|
{ sfPayChannel, soeREQUIRED },
|
||||||
|
{ sfAmount, soeREQUIRED },
|
||||||
|
{ sfExpiration, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("PaymentChannelClaim", ttPAYCHAN_CLAIM,
|
||||||
|
{
|
||||||
|
{ sfPayChannel, soeREQUIRED },
|
||||||
|
{ sfAmount, soeOPTIONAL },
|
||||||
|
{ sfBalance, soeOPTIONAL },
|
||||||
|
{ sfSignature, soeOPTIONAL },
|
||||||
|
{ sfPublicKey, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("CheckCreate", ttCHECK_CREATE,
|
||||||
|
{
|
||||||
|
{ sfDestination, soeREQUIRED },
|
||||||
|
{ sfSendMax, soeREQUIRED },
|
||||||
|
{ sfExpiration, soeOPTIONAL },
|
||||||
|
{ sfDestinationTag, soeOPTIONAL },
|
||||||
|
{ sfInvoiceID, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("CheckCash", ttCHECK_CASH,
|
||||||
|
{
|
||||||
|
{ sfCheckID, soeREQUIRED },
|
||||||
|
{ sfAmount, soeOPTIONAL },
|
||||||
|
{ sfDeliverMin, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("CheckCancel", ttCHECK_CANCEL,
|
||||||
|
{
|
||||||
|
{ sfCheckID, soeREQUIRED },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
|
|
||||||
|
add ("DepositPreauth", ttDEPOSIT_PREAUTH,
|
||||||
|
{
|
||||||
|
{ sfAuthorize, soeOPTIONAL },
|
||||||
|
{ sfUnauthorize, soeOPTIONAL },
|
||||||
|
},
|
||||||
|
commonFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
TxFormats const&
|
TxFormats const&
|
||||||
|
|||||||
@@ -237,10 +237,9 @@ public:
|
|||||||
unexpected (sfGeneric.isUseful (), "sfGeneric must not be useful");
|
unexpected (sfGeneric.isUseful (), "sfGeneric must not be useful");
|
||||||
{
|
{
|
||||||
// Try to put sfGeneric in an SOTemplate.
|
// Try to put sfGeneric in an SOTemplate.
|
||||||
SOTemplate elements;
|
|
||||||
except<std::runtime_error>( [&]()
|
except<std::runtime_error>( [&]()
|
||||||
{
|
{
|
||||||
elements.push_back (SOElement (sfGeneric, SOE_REQUIRED));
|
SOTemplate elements {{ sfGeneric, soeREQUIRED }};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,19 +259,19 @@ public:
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
// Try to put sfInvalid in an SOTemplate.
|
// Try to put sfInvalid in an SOTemplate.
|
||||||
SOTemplate elements;
|
|
||||||
except<std::runtime_error>( [&]()
|
except<std::runtime_error>( [&]()
|
||||||
{
|
{
|
||||||
elements.push_back (SOElement (sfInvalid, SOE_REQUIRED));
|
SOTemplate elements {{ sfInvalid, soeREQUIRED }};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// Try to put the same SField into an SOTemplate twice.
|
// Try to put the same SField into an SOTemplate twice.
|
||||||
SOTemplate elements;
|
|
||||||
elements.push_back (SOElement (sfAccount, SOE_REQUIRED));
|
|
||||||
except<std::runtime_error>( [&]()
|
except<std::runtime_error>( [&]()
|
||||||
{
|
{
|
||||||
elements.push_back (SOElement (sfAccount, SOE_REQUIRED));
|
SOTemplate elements {
|
||||||
|
{ sfAccount, soeREQUIRED },
|
||||||
|
{ sfAccount, soeREQUIRED },
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,12 +283,14 @@ public:
|
|||||||
SField const& sfTestObject = sfMajority;
|
SField const& sfTestObject = sfMajority;
|
||||||
|
|
||||||
|
|
||||||
SOTemplate elements;
|
SOTemplate const elements
|
||||||
elements.push_back (SOElement (sfFlags, SOE_REQUIRED));
|
{
|
||||||
elements.push_back (SOElement (sfTestVL, SOE_REQUIRED));
|
{ sfFlags, soeREQUIRED },
|
||||||
elements.push_back (SOElement (sfTestH256, SOE_OPTIONAL));
|
{ sfTestVL, soeREQUIRED },
|
||||||
elements.push_back (SOElement (sfTestU32, SOE_REQUIRED));
|
{ sfTestH256, soeOPTIONAL },
|
||||||
elements.push_back (SOElement (sfTestV256, SOE_OPTIONAL));
|
{ sfTestU32, soeREQUIRED },
|
||||||
|
{ sfTestV256, soeOPTIONAL },
|
||||||
|
};
|
||||||
|
|
||||||
STObject object1 (elements, sfTestObject);
|
STObject object1 (elements, sfTestObject);
|
||||||
STObject object2 (object1);
|
STObject object2 (object1);
|
||||||
@@ -419,17 +420,14 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read templated object
|
// read templated object
|
||||||
|
SOTemplate const sot
|
||||||
auto const sot = [&]()
|
|
||||||
{
|
{
|
||||||
SOTemplate sot;
|
{ sf1, soeREQUIRED },
|
||||||
sot.push_back(SOElement(sf1, SOE_REQUIRED));
|
{ sf2, soeOPTIONAL },
|
||||||
sot.push_back(SOElement(sf2, SOE_OPTIONAL));
|
{ sf3, soeDEFAULT },
|
||||||
sot.push_back(SOElement(sf3, SOE_DEFAULT));
|
{ sf4, soeOPTIONAL },
|
||||||
sot.push_back(SOElement(sf4, SOE_OPTIONAL));
|
{ sf5, soeDEFAULT },
|
||||||
sot.push_back(SOElement(sf5, SOE_DEFAULT));
|
};
|
||||||
return sot;
|
|
||||||
}();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto const st = [&]()
|
auto const st = [&]()
|
||||||
@@ -643,14 +641,13 @@ public:
|
|||||||
auto const& sf1 = sfIndexes;
|
auto const& sf1 = sfIndexes;
|
||||||
auto const& sf2 = sfHashes;
|
auto const& sf2 = sfHashes;
|
||||||
auto const& sf3 = sfAmendments;
|
auto const& sf3 = sfAmendments;
|
||||||
auto const sot = [&]()
|
SOTemplate const sot
|
||||||
{
|
{
|
||||||
SOTemplate sot;
|
{ sf1, soeREQUIRED },
|
||||||
sot.push_back(SOElement(sf1, SOE_REQUIRED));
|
{ sf2, soeOPTIONAL },
|
||||||
sot.push_back(SOElement(sf2, SOE_OPTIONAL));
|
{ sf3, soeDEFAULT },
|
||||||
sot.push_back(SOElement(sf3, SOE_DEFAULT));
|
};
|
||||||
return sot;
|
|
||||||
}();
|
|
||||||
STObject st(sot, sfGeneric);
|
STObject st(sot, sfGeneric);
|
||||||
auto const& cst(st);
|
auto const& cst(st);
|
||||||
BEAST_EXPECT(cst[sf1].size() == 0);
|
BEAST_EXPECT(cst[sf1].size() == 0);
|
||||||
|
|||||||
@@ -1250,9 +1250,11 @@ public:
|
|||||||
{
|
{
|
||||||
// Construct an SOTemplate to get the ball rolling on building
|
// Construct an SOTemplate to get the ball rolling on building
|
||||||
// an STObject that can contain another STObject.
|
// an STObject that can contain another STObject.
|
||||||
SOTemplate recurse;
|
SOTemplate const recurse
|
||||||
recurse.push_back (SOElement {sfTransactionMetaData, SOE_OPTIONAL});
|
{
|
||||||
recurse.push_back (SOElement {sfTransactionHash, SOE_OPTIONAL});
|
{ sfTransactionMetaData, soeOPTIONAL},
|
||||||
|
{ sfTransactionHash, soeOPTIONAL},
|
||||||
|
};
|
||||||
|
|
||||||
// Make an STObject that nests objects ten levels deep. There's
|
// Make an STObject that nests objects ten levels deep. There's
|
||||||
// a minimum transaction size we must meet, so include a hash256.
|
// a minimum transaction size we must meet, so include a hash256.
|
||||||
@@ -1312,10 +1314,12 @@ public:
|
|||||||
|
|
||||||
// Construct an SOTemplate to get the ball rolling on building
|
// Construct an SOTemplate to get the ball rolling on building
|
||||||
// an STObject that can contain an STArray.
|
// an STObject that can contain an STArray.
|
||||||
SOTemplate recurse;
|
SOTemplate recurse
|
||||||
recurse.push_back (SOElement {sfTransactionMetaData, SOE_OPTIONAL});
|
{
|
||||||
recurse.push_back (SOElement {sfTransactionHash, SOE_OPTIONAL});
|
{ sfTransactionMetaData, soeOPTIONAL },
|
||||||
recurse.push_back (SOElement {sfTemplate, SOE_OPTIONAL});
|
{ sfTransactionHash, soeOPTIONAL },
|
||||||
|
{ sfTemplate, soeOPTIONAL },
|
||||||
|
};
|
||||||
|
|
||||||
// Make an STObject that nests ten levels deep alternating objects
|
// Make an STObject that nests ten levels deep alternating objects
|
||||||
// and arrays. Include a hash256 to meet the minimum transaction
|
// and arrays. Include a hash256 to meet the minimum transaction
|
||||||
|
|||||||
Reference in New Issue
Block a user