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:
Scott Schurr
2019-02-27 12:56:22 -08:00
committed by Nik Bougalis
parent 57fe197d3e
commit afcc4ff296
17 changed files with 601 additions and 560 deletions

View File

@@ -23,20 +23,18 @@ namespace ripple {
InnerObjectFormats::InnerObjectFormats ()
{
add (sfSignerEntry.getJsonName ().c_str (), sfSignerEntry.getCode ())
<< SOElement (sfAccount, SOE_REQUIRED)
<< SOElement (sfSignerWeight, SOE_REQUIRED)
;
add (sfSignerEntry.jsonName.c_str(), sfSignerEntry.getCode(),
{
{sfAccount, soeREQUIRED},
{sfSignerWeight, soeREQUIRED},
});
add (sfSigner.getJsonName ().c_str (), sfSigner.getCode ())
<< SOElement (sfAccount, SOE_REQUIRED)
<< SOElement (sfSigningPubKey, SOE_REQUIRED)
<< SOElement (sfTxnSignature, SOE_REQUIRED)
;
}
void InnerObjectFormats::addCommonFields (Item& item)
{
add (sfSigner.jsonName.c_str(), sfSigner.getCode(),
{
{sfAccount, soeREQUIRED},
{sfSigningPubKey, soeREQUIRED},
{sfTxnSignature, soeREQUIRED},
});
}
InnerObjectFormats const&
@@ -49,12 +47,11 @@ InnerObjectFormats::getInstance ()
SOTemplate const*
InnerObjectFormats::findSOTemplateBySField (SField const& sField) const
{
SOTemplate const* ret = nullptr;
auto itemPtr = findByType (sField.getCode ());
if (itemPtr)
ret = &(itemPtr->elements);
return &(itemPtr->getSOTemplate());
return ret;
return nullptr;
}
} // ripple

View File

@@ -28,163 +28,188 @@ namespace ripple {
LedgerFormats::LedgerFormats ()
{
add ("AccountRoot", ltACCOUNT_ROOT)
<< SOElement (sfAccount, SOE_REQUIRED)
<< 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)
;
// Fields shared by all ledger formats:
static const std::initializer_list<SOElement> commonFields
{
{ sfLedgerIndex, soeOPTIONAL },
{ sfLedgerEntryType, soeREQUIRED },
{ sfFlags, soeREQUIRED },
};
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 ("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 ("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 ("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 ("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 ("Offer", ltOFFER,
{
{ sfAccount, soeREQUIRED },
{ sfSequence, soeREQUIRED },
{ sfTakerPays, soeREQUIRED },
{ sfTakerGets, soeREQUIRED },
{ sfBookDirectory, soeREQUIRED },
{ sfBookNode, soeREQUIRED },
{ sfOwnerNode, soeREQUIRED },
{ sfPreviousTxnID, soeREQUIRED },
{ sfPreviousTxnLgrSeq, soeREQUIRED },
{ sfExpiration, soeOPTIONAL },
},
commonFields);
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 ("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 ("LedgerHashes", ltLEDGER_HASHES)
<< SOElement (sfFirstLedgerSequence, SOE_OPTIONAL) // Remove if we do a ledger restart
<< SOElement (sfLastLedgerSequence, SOE_OPTIONAL)
<< SOElement (sfHashes, SOE_REQUIRED)
;
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 ("Amendments", ltAMENDMENTS)
<< SOElement (sfAmendments, SOE_OPTIONAL) // Enabled
<< SOElement (sfMajorities, SOE_OPTIONAL)
;
add ("LedgerHashes", ltLEDGER_HASHES,
{
{ sfFirstLedgerSequence, soeOPTIONAL }, // Remove if we do a ledger restart
{ sfLastLedgerSequence, soeOPTIONAL },
{ sfHashes, soeREQUIRED },
},
commonFields);
add ("FeeSettings", ltFEE_SETTINGS)
<< SOElement (sfBaseFee, SOE_REQUIRED)
<< SOElement (sfReferenceFeeUnits, SOE_REQUIRED)
<< SOElement (sfReserveBase, SOE_REQUIRED)
<< SOElement (sfReserveIncrement, SOE_REQUIRED)
;
add ("Amendments", ltAMENDMENTS,
{
{ sfAmendments, soeOPTIONAL }, // Enabled
{ sfMajorities, soeOPTIONAL },
},
commonFields);
add ("Ticket", ltTICKET)
<< SOElement (sfAccount, SOE_REQUIRED)
<< SOElement (sfSequence, SOE_REQUIRED)
<< SOElement (sfOwnerNode, SOE_REQUIRED)
<< SOElement (sfTarget, SOE_OPTIONAL)
<< SOElement (sfExpiration, SOE_OPTIONAL)
;
add ("FeeSettings", ltFEE_SETTINGS,
{
{ sfBaseFee, soeREQUIRED },
{ sfReferenceFeeUnits, soeREQUIRED },
{ sfReserveBase, soeREQUIRED },
{ sfReserveIncrement, soeREQUIRED },
},
commonFields);
// All fields are SOE_REQUIRED because there is always a
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)
<< 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 ("SignerList", ltSIGNER_LIST,
{
{ sfOwnerNode, soeREQUIRED },
{ sfSignerQuorum, soeREQUIRED },
{ sfSignerEntries, soeREQUIRED },
{ sfSignerListID, soeREQUIRED },
{ sfPreviousTxnID, soeREQUIRED },
{ sfPreviousTxnLgrSeq, soeREQUIRED },
},
commonFields);
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 ("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)
<< 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 ("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)
<< 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
<< SOElement(sfLedgerIndex, SOE_OPTIONAL)
<< SOElement(sfLedgerEntryType, SOE_REQUIRED)
<< SOElement(sfFlags, SOE_REQUIRED)
;
add ("DepositPreauth", ltDEPOSIT_PREAUTH,
{
{ sfAccount, soeREQUIRED },
{ sfAuthorize, soeREQUIRED },
{ sfOwnerNode, soeREQUIRED },
{ sfPreviousTxnID, soeREQUIRED },
{ sfPreviousTxnLgrSeq, soeREQUIRED },
},
commonFields);
}
LedgerFormats const&

View File

@@ -21,44 +21,45 @@
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
// table for all possible fields.
//
if (mIndex.empty ())
// Add all SOElements.
elements_.reserve (uniqueFields.size() + commonFields.size());
elements_.assign (uniqueFields);
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()};
// Make sure the field's index is in range
//
mIndex.resize (SField::getNumFields () + 1, -1);
if (sField.getNum() <= 0 || sField.getNum() >= indices_.size())
Throw<std::runtime_error> ("Invalid field index for SOTemplate.");
// Make sure that this field hasn't already been assigned
//
if (getIndex (sField) != -1)
Throw<std::runtime_error> ("Duplicate field index for SOTemplate.");
// Add the field to the index mapping table
//
indices_[sField.getNum ()] = i;
}
// Make sure the field's index is in range
//
if (r.e_field.getNum() <= 0 || r.e_field.getNum() >= mIndex.size())
Throw<std::runtime_error> ("Invalid field index for SOTemplate.");
// Make sure that this field hasn't already been assigned
//
if (getIndex (r.e_field) != -1)
Throw<std::runtime_error> ("Duplicate field index for SOTemplate.");
// Add the field to the index mapping table
//
mIndex [r.e_field.getNum ()] = mTypes.size ();
// 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
//
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

View File

@@ -43,7 +43,7 @@ STLedgerEntry::STLedgerEntry (Keylet const& k)
if (format == nullptr)
Throw<std::runtime_error> ("invalid ledger entry type");
set (format->elements);
set (format->getSOTemplate());
setFieldU16 (sfLedgerEntryType,
static_cast <std::uint16_t> (type_));
@@ -78,7 +78,7 @@ void STLedgerEntry::setSLEType ()
Throw<std::runtime_error> ("invalid ledger entry type");
type_ = format->getType ();
applyTemplate (format->elements); // May throw
applyTemplate (format->getSOTemplate()); // May throw
}
std::string STLedgerEntry::getFullText () const

View File

@@ -91,12 +91,12 @@ void STObject::set (const SOTemplate& type)
v_.reserve(type.size());
mType = &type;
for (auto const& elem : type.all())
for (auto const& elem : type)
{
if (elem->flags != SOE_REQUIRED)
v_.emplace_back(detail::nonPresentObject, elem->e_field);
if (elem.style() != soeREQUIRED)
v_.emplace_back(detail::nonPresentObject, elem.sField());
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;
decltype(v_) v;
v.reserve(type.size());
for (auto const& e : type.all())
for (auto const& e : type)
{
auto const iter = std::find_if(
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 ((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.");
}
v.emplace_back(std::move(*iter));
@@ -131,12 +131,12 @@ void STObject::applyTemplate (const SOTemplate& type) noexcept (false)
}
else
{
if (e->flags == SOE_REQUIRED)
if (e.style() == soeREQUIRED)
{
throwFieldErr (e->e_field.fieldName,
throwFieldErr (e.sField().fieldName,
"is required but missing.");
}
v.emplace_back(detail::nonPresentObject, e->e_field);
v.emplace_back(detail::nonPresentObject, e.sField());
}
}
for (auto const& e : v_)

View File

@@ -60,7 +60,7 @@ STTx::STTx (STObject&& object) noexcept (false)
: STObject (std::move (object))
{
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);
}
@@ -77,7 +77,7 @@ STTx::STTx (SerialIter& sit) noexcept (false)
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);
}
@@ -88,7 +88,7 @@ STTx::STTx (
{
auto format = getTxFormat (type);
set (format->elements);
set (format->getSOTemplate());
setFieldU16 (sfTransactionType, format->getType ());
assembler (*this);

View File

@@ -147,26 +147,23 @@ SOTemplate const& STValidation::getFormat ()
{
struct FormatHolder
{
SOTemplate format;
FormatHolder ()
SOTemplate format
{
format.push_back (SOElement (sfFlags, SOE_REQUIRED));
format.push_back (SOElement (sfLedgerHash, SOE_REQUIRED));
format.push_back (SOElement (sfLedgerSequence, SOE_OPTIONAL));
format.push_back (SOElement (sfCloseTime, SOE_OPTIONAL));
format.push_back (SOElement (sfLoadFee, SOE_OPTIONAL));
format.push_back (SOElement (sfAmendments, SOE_OPTIONAL));
format.push_back (SOElement (sfBaseFee, SOE_OPTIONAL));
format.push_back (SOElement (sfReserveBase, SOE_OPTIONAL));
format.push_back (SOElement (sfReserveIncrement, SOE_OPTIONAL));
format.push_back (SOElement (sfSigningTime, SOE_REQUIRED));
format.push_back (SOElement (sfSigningPubKey, SOE_REQUIRED));
format.push_back (SOElement (sfSignature, SOE_OPTIONAL));
format.push_back (SOElement (sfConsensusHash, SOE_OPTIONAL));
format.push_back (SOElement (sfCookie, SOE_OPTIONAL));
}
{ sfFlags, soeREQUIRED },
{ sfLedgerHash, soeREQUIRED },
{ sfLedgerSequence, soeOPTIONAL },
{ sfCloseTime, soeOPTIONAL },
{ sfLoadFee, soeOPTIONAL },
{ sfAmendments, soeOPTIONAL },
{ sfBaseFee, soeOPTIONAL },
{ sfReserveBase, soeOPTIONAL },
{ sfReserveIncrement, soeOPTIONAL },
{ sfSigningTime, soeREQUIRED },
{ sfSigningPubKey, soeREQUIRED },
{ sfSignature, soeOPTIONAL },
{ sfConsensusHash, soeOPTIONAL },
{ sfCookie, soeOPTIONAL },
};
};
static const FormatHolder holder;

View File

@@ -23,164 +23,205 @@ namespace ripple {
TxFormats::TxFormats ()
{
add ("AccountSet", ttACCOUNT_SET)
<< SOElement (sfEmailHash, SOE_OPTIONAL)
<< SOElement (sfWalletLocator, SOE_OPTIONAL)
<< SOElement (sfWalletSize, SOE_OPTIONAL)
<< SOElement (sfMessageKey, SOE_OPTIONAL)
<< SOElement (sfDomain, SOE_OPTIONAL)
<< SOElement (sfTransferRate, SOE_OPTIONAL)
<< SOElement (sfSetFlag, SOE_OPTIONAL)
<< SOElement (sfClearFlag, SOE_OPTIONAL)
<< SOElement (sfTickSize, SOE_OPTIONAL)
;
// Fields shared by all txFormats:
static const std::initializer_list<SOElement> commonFields
{
{ sfTransactionType, soeREQUIRED },
{ sfFlags, soeOPTIONAL },
{ sfSourceTag, soeOPTIONAL },
{ sfAccount, soeREQUIRED },
{ sfSequence, soeREQUIRED },
{ sfPreviousTxnID, soeOPTIONAL }, // emulate027
{ sfLastLedgerSequence, soeOPTIONAL },
{ sfAccountTxnID, soeOPTIONAL },
{ sfFee, soeREQUIRED },
{ sfOperationLimit, soeOPTIONAL },
{ sfMemos, soeOPTIONAL },
{ sfSigningPubKey, soeREQUIRED },
{ sfTxnSignature, soeOPTIONAL },
{ sfSigners, soeOPTIONAL }, // submit_multisigned
};
add ("TrustSet", ttTRUST_SET)
<< SOElement (sfLimitAmount, SOE_OPTIONAL)
<< SOElement (sfQualityIn, SOE_OPTIONAL)
<< SOElement (sfQualityOut, SOE_OPTIONAL)
;
add ("AccountSet", ttACCOUNT_SET,
{
{ sfEmailHash, soeOPTIONAL },
{ sfWalletLocator, soeOPTIONAL },
{ sfWalletSize, soeOPTIONAL },
{ sfMessageKey, soeOPTIONAL },
{ sfDomain, soeOPTIONAL },
{ sfTransferRate, soeOPTIONAL },
{ sfSetFlag, soeOPTIONAL },
{ sfClearFlag, soeOPTIONAL },
{ sfTickSize, soeOPTIONAL },
},
commonFields);
add ("OfferCreate", ttOFFER_CREATE)
<< SOElement (sfTakerPays, SOE_REQUIRED)
<< SOElement (sfTakerGets, SOE_REQUIRED)
<< SOElement (sfExpiration, SOE_OPTIONAL)
<< SOElement (sfOfferSequence, SOE_OPTIONAL)
;
add ("TrustSet", ttTRUST_SET,
{
{ sfLimitAmount, soeOPTIONAL },
{ sfQualityIn, soeOPTIONAL },
{ sfQualityOut, soeOPTIONAL },
},
commonFields);
add ("OfferCancel", ttOFFER_CANCEL)
<< SOElement (sfOfferSequence, SOE_REQUIRED)
;
add ("OfferCreate", ttOFFER_CREATE,
{
{ sfTakerPays, soeREQUIRED },
{ sfTakerGets, soeREQUIRED },
{ sfExpiration, soeOPTIONAL },
{ sfOfferSequence, soeOPTIONAL },
},
commonFields);
add ("SetRegularKey", ttREGULAR_KEY_SET)
<< SOElement (sfRegularKey, SOE_OPTIONAL)
;
add ("OfferCancel", ttOFFER_CANCEL,
{
{ sfOfferSequence, soeREQUIRED },
},
commonFields);
add ("Payment", ttPAYMENT)
<< SOElement (sfDestination, SOE_REQUIRED)
<< SOElement (sfAmount, SOE_REQUIRED)
<< SOElement (sfSendMax, SOE_OPTIONAL)
<< SOElement (sfPaths, SOE_DEFAULT)
<< SOElement (sfInvoiceID, SOE_OPTIONAL)
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
<< SOElement (sfDeliverMin, SOE_OPTIONAL)
;
add ("SetRegularKey", ttREGULAR_KEY_SET,
{
{ sfRegularKey, soeOPTIONAL },
},
commonFields);
add ("EscrowCreate", ttESCROW_CREATE)
<< SOElement (sfDestination, SOE_REQUIRED)
<< SOElement (sfAmount, SOE_REQUIRED)
<< SOElement (sfCondition, SOE_OPTIONAL)
<< SOElement (sfCancelAfter, SOE_OPTIONAL)
<< SOElement (sfFinishAfter, SOE_OPTIONAL)
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
;
add ("Payment", ttPAYMENT,
{
{ sfDestination, soeREQUIRED },
{ sfAmount, soeREQUIRED },
{ sfSendMax, soeOPTIONAL },
{ sfPaths, soeDEFAULT },
{ sfInvoiceID, soeOPTIONAL },
{ sfDestinationTag, soeOPTIONAL },
{ sfDeliverMin, soeOPTIONAL },
},
commonFields);
add ("EscrowFinish", ttESCROW_FINISH)
<< SOElement (sfOwner, SOE_REQUIRED)
<< SOElement (sfOfferSequence, SOE_REQUIRED)
<< SOElement (sfFulfillment, SOE_OPTIONAL)
<< SOElement (sfCondition, SOE_OPTIONAL)
;
add ("EscrowCreate", ttESCROW_CREATE,
{
{ sfDestination, soeREQUIRED },
{ sfAmount, soeREQUIRED },
{ sfCondition, soeOPTIONAL },
{ sfCancelAfter, soeOPTIONAL },
{ sfFinishAfter, soeOPTIONAL },
{ sfDestinationTag, soeOPTIONAL },
},
commonFields);
add ("EscrowCancel", ttESCROW_CANCEL)
<< SOElement (sfOwner, SOE_REQUIRED)
<< SOElement (sfOfferSequence, SOE_REQUIRED)
;
add ("EscrowFinish", ttESCROW_FINISH,
{
{ sfOwner, soeREQUIRED },
{ sfOfferSequence, soeREQUIRED },
{ sfFulfillment, soeOPTIONAL },
{ sfCondition, soeOPTIONAL },
},
commonFields);
add ("EnableAmendment", ttAMENDMENT)
<< SOElement (sfLedgerSequence, SOE_REQUIRED)
<< SOElement (sfAmendment, SOE_REQUIRED)
;
add ("EscrowCancel", ttESCROW_CANCEL,
{
{ sfOwner, soeREQUIRED },
{ sfOfferSequence, soeREQUIRED },
},
commonFields);
add ("SetFee", ttFEE)
<< SOElement (sfLedgerSequence, SOE_OPTIONAL)
<< SOElement (sfBaseFee, SOE_REQUIRED)
<< SOElement (sfReferenceFeeUnits, SOE_REQUIRED)
<< SOElement (sfReserveBase, SOE_REQUIRED)
<< SOElement (sfReserveIncrement, SOE_REQUIRED)
;
add ("EnableAmendment", ttAMENDMENT,
{
{ sfLedgerSequence, soeREQUIRED },
{ sfAmendment, soeREQUIRED },
},
commonFields);
add ("TicketCreate", ttTICKET_CREATE)
<< SOElement (sfTarget, SOE_OPTIONAL)
<< SOElement (sfExpiration, SOE_OPTIONAL)
;
add ("SetFee", ttFEE,
{
{ sfLedgerSequence, soeOPTIONAL },
{ sfBaseFee, soeREQUIRED },
{ sfReferenceFeeUnits, soeREQUIRED },
{ sfReserveBase, soeREQUIRED },
{ sfReserveIncrement, soeREQUIRED },
},
commonFields);
add ("TicketCancel", ttTICKET_CANCEL)
<< SOElement (sfTicketID, SOE_REQUIRED)
;
add ("TicketCreate", ttTICKET_CREATE,
{
{ sfTarget, soeOPTIONAL },
{ sfExpiration, soeOPTIONAL },
},
commonFields);
add ("TicketCancel", ttTICKET_CANCEL,
{
{ sfTicketID, soeREQUIRED },
},
commonFields);
// The SignerEntries are optional because a SignerList is deleted by
// setting the SignerQuorum to zero and omitting SignerEntries.
add ("SignerListSet", ttSIGNER_LIST_SET)
<< SOElement (sfSignerQuorum, SOE_REQUIRED)
<< SOElement (sfSignerEntries, SOE_OPTIONAL)
;
add ("SignerListSet", ttSIGNER_LIST_SET,
{
{ sfSignerQuorum, soeREQUIRED },
{ sfSignerEntries, soeOPTIONAL },
},
commonFields);
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 ("PaymentChannelCreate", ttPAYCHAN_CREATE,
{
{ sfDestination, soeREQUIRED },
{ sfAmount, soeREQUIRED },
{ sfSettleDelay, soeREQUIRED },
{ sfPublicKey, soeREQUIRED },
{ sfCancelAfter, soeOPTIONAL },
{ sfDestinationTag, soeOPTIONAL },
},
commonFields);
add ("PaymentChannelFund", ttPAYCHAN_FUND)
<< SOElement (sfPayChannel, SOE_REQUIRED)
<< SOElement (sfAmount, SOE_REQUIRED)
<< SOElement (sfExpiration, SOE_OPTIONAL)
;
add ("PaymentChannelFund", ttPAYCHAN_FUND,
{
{ sfPayChannel, soeREQUIRED },
{ sfAmount, soeREQUIRED },
{ sfExpiration, soeOPTIONAL },
},
commonFields);
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 ("PaymentChannelClaim", ttPAYCHAN_CLAIM,
{
{ sfPayChannel, soeREQUIRED },
{ sfAmount, soeOPTIONAL },
{ sfBalance, soeOPTIONAL },
{ sfSignature, soeOPTIONAL },
{ sfPublicKey, soeOPTIONAL },
},
commonFields);
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 ("CheckCreate", ttCHECK_CREATE,
{
{ sfDestination, soeREQUIRED },
{ sfSendMax, soeREQUIRED },
{ sfExpiration, soeOPTIONAL },
{ sfDestinationTag, soeOPTIONAL },
{ sfInvoiceID, soeOPTIONAL },
},
commonFields);
add ("CheckCash", ttCHECK_CASH)
<< SOElement (sfCheckID, SOE_REQUIRED)
<< SOElement (sfAmount, SOE_OPTIONAL)
<< SOElement (sfDeliverMin, SOE_OPTIONAL)
;
add ("CheckCash", ttCHECK_CASH,
{
{ sfCheckID, soeREQUIRED },
{ sfAmount, soeOPTIONAL },
{ sfDeliverMin, soeOPTIONAL },
},
commonFields);
add ("CheckCancel", ttCHECK_CANCEL)
<< SOElement (sfCheckID, SOE_REQUIRED)
;
add ("CheckCancel", ttCHECK_CANCEL,
{
{ sfCheckID, soeREQUIRED },
},
commonFields);
add ("DepositPreauth", ttDEPOSIT_PREAUTH)
<< SOElement (sfAuthorize, SOE_OPTIONAL)
<< SOElement (sfUnauthorize, SOE_OPTIONAL)
;
}
void TxFormats::addCommonFields (Item& item)
{
item
<< SOElement(sfTransactionType, SOE_REQUIRED)
<< SOElement(sfFlags, SOE_OPTIONAL)
<< SOElement(sfSourceTag, SOE_OPTIONAL)
<< SOElement(sfAccount, SOE_REQUIRED)
<< SOElement(sfSequence, SOE_REQUIRED)
<< SOElement(sfPreviousTxnID, SOE_OPTIONAL) // emulate027
<< SOElement(sfLastLedgerSequence, SOE_OPTIONAL)
<< SOElement(sfAccountTxnID, SOE_OPTIONAL)
<< SOElement(sfFee, SOE_REQUIRED)
<< SOElement(sfOperationLimit, SOE_OPTIONAL)
<< SOElement(sfMemos, SOE_OPTIONAL)
<< SOElement(sfSigningPubKey, SOE_REQUIRED)
<< SOElement(sfTxnSignature, SOE_OPTIONAL)
<< SOElement(sfSigners, SOE_OPTIONAL) // submit_multisigned
;
add ("DepositPreauth", ttDEPOSIT_PREAUTH,
{
{ sfAuthorize, soeOPTIONAL },
{ sfUnauthorize, soeOPTIONAL },
},
commonFields);
}
TxFormats const&