Refactor SField (RIPD-431)

* Restrict access to SField constructors.
* Make all SField access const.
* Hide and simplify databases used to hold SField constants.
* Separate the two concerns of representing a field,
  and maintaining a database of fields.
This commit is contained in:
Howard Hinnant
2014-07-31 16:11:10 -04:00
committed by Vinnie Falco
parent 1c73a0f649
commit 9552551f9a
19 changed files with 838 additions and 724 deletions

View File

@@ -2560,11 +2560,6 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\module\data\protocol\BuildInfo.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\data\protocol\FieldNames.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\module\data\protocol\FieldNames.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\data\protocol\HashPrefix.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
@@ -2586,8 +2581,6 @@
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\data\protocol\RippleSystem.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\data\protocol\SerializeDeclarations.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\data\protocol\SerializedObject.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
@@ -2610,6 +2603,11 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\module\data\protocol\Serializer.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\data\protocol\SField.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\module\data\protocol\SField.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\data\protocol\STAmount.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>

View File

@@ -3699,12 +3699,6 @@
<ClInclude Include="..\..\src\ripple\module\data\protocol\BuildInfo.h">
<Filter>ripple\module\data\protocol</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\data\protocol\FieldNames.cpp">
<Filter>ripple\module\data\protocol</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\module\data\protocol\FieldNames.h">
<Filter>ripple\module\data\protocol</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\data\protocol\HashPrefix.cpp">
<Filter>ripple\module\data\protocol</Filter>
</ClCompile>
@@ -3732,9 +3726,6 @@
<ClInclude Include="..\..\src\ripple\module\data\protocol\RippleSystem.h">
<Filter>ripple\module\data\protocol</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\data\protocol\SerializeDeclarations.h">
<Filter>ripple\module\data\protocol</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\data\protocol\SerializedObject.cpp">
<Filter>ripple\module\data\protocol</Filter>
</ClCompile>
@@ -3762,6 +3753,12 @@
<ClInclude Include="..\..\src\ripple\module\data\protocol\Serializer.h">
<Filter>ripple\module\data\protocol</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\data\protocol\SField.cpp">
<Filter>ripple\module\data\protocol</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\module\data\protocol\SField.h">
<Filter>ripple\module\data\protocol</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\data\protocol\STAmount.cpp">
<Filter>ripple\module\data\protocol</Filter>
</ClCompile>

View File

@@ -25,7 +25,7 @@
#include <ripple/module/app/book/Types.h>
#include <ripple/module/app/misc/SerializedLedger.h>
#include <ripple/module/data/protocol/FieldNames.h>
#include <ripple/module/data/protocol/SField.h>
#include <beast/utility/noexcept.h>

View File

@@ -231,7 +231,7 @@ void OrderBookDB::processTxn (
{
if (node.getFieldU16 (sfLedgerEntryType) == ltOFFER)
{
SField* field = nullptr;
SField const* field = nullptr;
// We need a field that contains the TakerGets and TakerPays
// parameters.

View File

@@ -1,198 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
namespace ripple {
// These must stay at the top of this file
std::map<int, SField::ptr> SField::knownCodeToField;
std::map<int, SField::ptr> SField::unknownCodeToField;
int SField::num = 0;
// Solve construction issues for objects with static storage duration.
SField::StaticLockType& SField::getMutex ()
{
static StaticLockType mutex;
return mutex;
}
SField const sfInvalid (-1), sfGeneric (0);
SField const sfLedgerEntry (STI_LEDGERENTRY, 257, "LedgerEntry");
SField const sfTransaction (STI_TRANSACTION, 257, "Transaction");
SField const sfValidation (STI_VALIDATION, 257, "Validation");
SField const sfMetadata (STI_METADATA, 257, "Metadata");
SField const sfHash (STI_HASH256, 257, "hash");
SField const sfIndex (STI_HASH256, 258, "index");
// TODO(tom): Remove this horror.
#define FIELD(name, type, index) \
SField sf##name(FIELD_CODE(STI_##type, index), STI_##type, index, #name);
#define TYPE(name, type, index)
#include <ripple/module/data/protocol/SerializeDeclarations.h>
#undef FIELD
#undef TYPE
static int initFields ()
{
sfTxnSignature.notSigningField ();
sfTxnSignatures.notSigningField ();
sfSignature.notSigningField ();
sfIndexes.setMeta (SField::sMD_Never);
sfPreviousTxnID.setMeta (SField::sMD_DeleteFinal);
sfPreviousTxnLgrSeq.setMeta (SField::sMD_DeleteFinal);
sfLedgerEntryType.setMeta (SField::sMD_Never);
sfRootIndex.setMeta (SField::sMD_Always);
return 0;
}
static const int forceInitializionOfFields = initFields ();
SField::SField (SerializedTypeID tid, int fv)
: fieldCode (FIELD_CODE (tid, fv)), fieldType (tid), fieldValue (fv),
fieldMeta (sMD_Default),
fieldNum (++num),
signingField (true),
jsonName (nullptr)
{
// call with the map mutex
fieldName = beast::lexicalCast <std::string> (tid) + "/" +
beast::lexicalCast <std::string> (fv);
unknownCodeToField[fieldCode] = this;
rawJsonName = getName ();
jsonName = Json::StaticString (rawJsonName.c_str ());
assert ((fv != 1) || ((tid != STI_ARRAY) && (tid != STI_OBJECT)));
}
SField::ref SField::getField (int code)
{
std::map<int, SField::ptr>::iterator it = knownCodeToField.find (code);
if (it != knownCodeToField.end ())
{
// 99+% of the time, it will be a valid, known field
return * (it->second);
}
int type = code >> 16;
int field = code % 0xffff;
// Don't dynamically extend types that have no binary encoding.
if ((field > 255) || (code < 0))
return sfInvalid;
switch (type)
{
// Types we are willing to dynamically extend
// TODO(tom): Remove this horror.
#define FIELD(name, type, index)
#define TYPE(name, type, index) case STI_##type:
#include <ripple/module/data/protocol/SerializeDeclarations.h>
#undef FIELD
#undef TYPE
break;
default:
return sfInvalid;
}
{
StaticScopedLockType sl (getMutex ());
it = unknownCodeToField.find (code);
if (it != unknownCodeToField.end ())
return * (it->second);
return * (new SField (static_cast<SerializedTypeID> (type), field));
}
}
int SField::compare (SField::ref f1, SField::ref f2)
{
// -1 = f1 comes before f2, 0 = illegal combination, 1 = f1 comes after f2
if ((f1.fieldCode <= 0) || (f2.fieldCode <= 0))
return 0;
if (f1.fieldCode < f2.fieldCode)
return -1;
if (f2.fieldCode < f1.fieldCode)
return 1;
return 0;
}
std::string SField::getName () const
{
if (!fieldName.empty ())
return fieldName;
if (fieldValue == 0)
return "";
return std::to_string(static_cast<int> (fieldType)) + "/" +
std::to_string(fieldValue);
}
SField::ref SField::getField (std::string const& fieldName)
{
// OPTIMIZEME me with a map. CHECKME this is case sensitive
for (auto const & fieldPair : knownCodeToField)
{
if (fieldPair.second->fieldName == fieldName)
return * (fieldPair.second);
}
{
StaticScopedLockType sl (getMutex ());
for (auto const & fieldPair : unknownCodeToField)
{
if (fieldPair.second->fieldName == fieldName)
return * (fieldPair.second);
}
}
return sfInvalid;
}
SField::~SField ()
{
std::map<int, ptr>::iterator it = knownCodeToField.find (fieldCode);
if ((it != knownCodeToField.end ()) && (it->second == this))
{
knownCodeToField.erase (it);
}
else
{
StaticScopedLockType sl (getMutex ());
it = unknownCodeToField.find (fieldCode);
if ((it != unknownCodeToField.end ()) && (it->second == this))
unknownCodeToField.erase (it);
}
}
} // ripple

View File

@@ -1,260 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_FIELDNAMES_H
#define RIPPLE_FIELDNAMES_H
#include <ripple/basics/types/BasicTypes.h>
namespace ripple {
// VFALCO TODO lose the macro.
#define FIELD_CODE(type, index) ((static_cast<int>(type) << 16) | index)
enum SerializedTypeID
{
// special types
STI_UNKNOWN = -2,
STI_DONE = -1,
STI_NOTPRESENT = 0,
#define TYPE(name, field, value) STI_##field = value,
#define FIELD(name, field, value)
#include <ripple/module/data/protocol/SerializeDeclarations.h>
#undef TYPE
#undef FIELD
// high level types
// cannot be serialized inside other types
STI_TRANSACTION = 10001,
STI_LEDGERENTRY = 10002,
STI_VALIDATION = 10003,
STI_METADATA = 10004,
};
/** Identifies fields.
Fields are necessary to tag data in signed transactions so that
the binary format of the transaction can be canonicalized.
*/
// VFALCO TODO rename this to NamedField
class SField
{
public:
typedef const SField& ref;
typedef SField const* ptr;
static const int sMD_Never = 0x00;
static const int sMD_ChangeOrig = 0x01; // original value when it changes
static const int sMD_ChangeNew = 0x02; // new value when it changes
static const int sMD_DeleteFinal = 0x04; // final value when it is deleted
static const int sMD_Create = 0x08; // value when it's created
static const int sMD_Always = 0x10; // value when node containing it is affected at all
static const int sMD_Default = sMD_ChangeOrig | sMD_ChangeNew | sMD_DeleteFinal | sMD_Create;
const int fieldCode; // (type<<16)|index
const SerializedTypeID fieldType; // STI_*
const int fieldValue; // Code number for protocol
std::string fieldName;
int fieldMeta;
int fieldNum;
bool signingField;
std::string rawJsonName;
Json::StaticString jsonName;
SField(SField const&) = delete;
SField& operator=(SField const&) = delete;
SField (int fc, SerializedTypeID tid, int fv, const char* fn)
: fieldCode (fc)
, fieldType (tid)
, fieldValue (fv)
, fieldName (fn)
, fieldMeta (sMD_Default)
, signingField (true)
, rawJsonName (getName ())
, jsonName (rawJsonName.c_str ())
{
knownCodeToField[fieldCode] = this;
fieldNum = ++num;
}
SField (SerializedTypeID tid, int fv, const char* fn)
: fieldCode (FIELD_CODE (tid, fv))
, fieldType (tid)
, fieldValue (fv)
, fieldName (fn)
, fieldMeta (sMD_Default)
, signingField (true)
, rawJsonName (getName ())
, jsonName (rawJsonName.c_str ())
{
knownCodeToField[fieldCode] = this;
fieldNum = ++num;
}
explicit SField (int fc)
: fieldCode (fc)
, fieldType (STI_UNKNOWN)
, fieldValue (0)
, fieldMeta (sMD_Never)
, signingField (true)
, rawJsonName (getName ())
, jsonName (rawJsonName.c_str ())
{
StaticScopedLockType sl (getMutex ());
fieldNum = ++num;
}
~SField ();
static SField::ref getField (int fieldCode);
static SField::ref getField (std::string const& fieldName);
static SField::ref getField (int type, int value)
{
return getField (FIELD_CODE (type, value));
}
static SField::ref getField (SerializedTypeID type, int value)
{
return getField (FIELD_CODE (type, value));
}
std::string getName () const;
bool hasName () const
{
return !fieldName.empty ();
}
Json::StaticString const& getJsonName () const
{
return jsonName;
}
bool isGeneric () const
{
return fieldCode == 0;
}
bool isInvalid () const
{
return fieldCode == -1;
}
bool isUseful () const
{
return fieldCode > 0;
}
bool isKnown () const
{
return fieldType != STI_UNKNOWN;
}
bool isBinary () const
{
return fieldValue < 256;
}
// A discardable field is one that cannot be serialized, and
// should be discarded during serialization,like 'hash'.
// You cannot serialize an object's hash inside that object,
// but you can have it in the JSON representation.
bool isDiscardable () const
{
return fieldValue > 256;
}
int getCode () const
{
return fieldCode;
}
int getNum () const
{
return fieldNum;
}
static int getNumFields ()
{
return num;
}
bool isSigningField () const
{
return signingField;
}
void notSigningField ()
{
signingField = false;
}
bool shouldMeta (int c) const
{
return (fieldMeta & c) != 0;
}
void setMeta (int c)
{
fieldMeta = c;
}
bool shouldInclude (bool withSigningField) const
{
return (fieldValue < 256) && (withSigningField || signingField);
}
bool operator== (const SField& f) const
{
return fieldCode == f.fieldCode;
}
bool operator!= (const SField& f) const
{
return fieldCode != f.fieldCode;
}
static int compare (SField::ref f1, SField::ref f2);
// VFALCO TODO make these private
protected:
// Fields that are known at compile time
static std::map <int, ptr> knownCodeToField;
// Field that are discovered at run time
static std::map <int, ptr> unknownCodeToField;
typedef RippleMutex StaticLockType;
typedef std::lock_guard <StaticLockType> StaticScopedLockType;
static StaticLockType& getMutex ();
// VFALCO NOTE can this be replaced with an atomic int???!
static int num;
SField (SerializedTypeID id, int val);
};
extern const SField
sfInvalid, sfGeneric,
sfLedgerEntry, sfTransaction, sfValidation, sfMetadata;
#define FIELD(name, type, index) extern SField sf##name;
#define TYPE(name, type, index)
#include <ripple/module/data/protocol/SerializeDeclarations.h>
#undef FIELD
#undef TYPE
} // ripple
#endif

View File

@@ -40,21 +40,6 @@ LedgerFormats::LedgerFormats ()
<< SOElement (sfDomain, SOE_OPTIONAL)
;
add ("Contract", ltCONTRACT)
<< SOElement (sfAccount, SOE_REQUIRED)
<< SOElement (sfBalance, SOE_REQUIRED)
<< SOElement (sfPreviousTxnID, SOE_REQUIRED)
<< SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED)
<< SOElement (sfIssuer, SOE_REQUIRED)
<< SOElement (sfOwner, SOE_REQUIRED)
<< SOElement (sfExpiration, SOE_REQUIRED)
<< SOElement (sfBondAmount, SOE_REQUIRED)
<< SOElement (sfCreateCode, SOE_OPTIONAL)
<< SOElement (sfFundCode, SOE_OPTIONAL)
<< SOElement (sfRemoveCode, SOE_OPTIONAL)
<< SOElement (sfExpireCode, SOE_OPTIONAL)
;
add ("DirectoryNode", ltDIR_NODE)
<< SOElement (sfOwner, SOE_OPTIONAL) // for owner directories
<< SOElement (sfTakerPaysCurrency, SOE_OPTIONAL) // for order book directories

View File

@@ -59,7 +59,7 @@ enum LedgerEntryType
*/
ltOFFER = 'o',
ltCONTRACT = 'c',
ltNotUsed01 = 'c',
ltLEDGER_HASHES = 'h',

View File

@@ -0,0 +1,398 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/module/data/protocol/SField.h>
namespace ripple {
// These must stay at the top of this file, and in this order
// Files-cope statics are preferred here because the SFields must be
// file-scope. The following 3 objects must have scope prior to
// the file-scope SFields.
static std::mutex SField_mutex;
static std::map<int, SField::ptr> knownCodeToField;
static std::map<int, std::unique_ptr<SField const>> unknownCodeToField;
int SField::num = 0;
typedef std::lock_guard <std::mutex> StaticScopedLockType;
// Give this translation unit only, permission to construct SFields
struct SField::make
{
#ifndef _MSC_VER
template <class ...Args>
static SField one(SField const* p, Args&& ...args)
{
SField result(std::forward<Args>(args)...);
knownCodeToField[result.fieldCode] = p;
return result;
}
#else // remove this when VS gets variadic templates
template <class A0>
static SField one(SField const* p, A0&& arg0)
{
SField result(std::forward<A0>(arg0));
knownCodeToField[result.fieldCode] = p;
return result;
}
template <class A0, class A1, class A2>
static SField one(SField const* p, A0&& arg0, A1&& arg1, A2&& arg2)
{
SField result(std::forward<A0>(arg0), std::forward<A1>(arg1),
std::forward<A2>(arg2));
knownCodeToField[result.fieldCode] = p;
return result;
}
template <class A0, class A1, class A2, class A3>
static SField one(SField const* p, A0&& arg0, A1&& arg1, A2&& arg2,
A3&& arg3)
{
SField result(std::forward<A0>(arg0), std::forward<A1>(arg1),
std::forward<A2>(arg2), std::forward<A3>(arg3));
knownCodeToField[result.fieldCode] = p;
return result;
}
template <class A0, class A1, class A2, class A3, class A4>
static SField one(SField const* p, A0&& arg0, A1&& arg1, A2&& arg2,
A3&& arg3, A4&& arg4)
{
SField result(std::forward<A0>(arg0), std::forward<A1>(arg1),
std::forward<A2>(arg2), std::forward<A3>(arg3),
std::forward<A4>(arg4));
knownCodeToField[result.fieldCode] = p;
return result;
}
#endif
};
using make = SField::make;
// Construct all compile-time SFields, and register them in the knownCodeToField
// database:
SField const sfInvalid = make::one(&sfInvalid, -1);
SField const sfGeneric = make::one(&sfGeneric, 0);
SField const sfLedgerEntry = make::one(&sfLedgerEntry, STI_LEDGERENTRY, 257, "LedgerEntry");
SField const sfTransaction = make::one(&sfTransaction, STI_TRANSACTION, 257, "Transaction");
SField const sfValidation = make::one(&sfValidation, STI_VALIDATION, 257, "Validation");
SField const sfMetadata = make::one(&sfMetadata, STI_METADATA, 257, "Metadata");
SField const sfHash = make::one(&sfHash, STI_HASH256, 257, "hash");
SField const sfIndex = make::one(&sfIndex, STI_HASH256, 258, "index");
// 8-bit integers
SField const sfCloseResolution = make::one(&sfCloseResolution, STI_UINT8, 1, "CloseResolution");
SField const sfTemplateEntryType = make::one(&sfTemplateEntryType, STI_UINT8, 2, "TemplateEntryType");
SField const sfTransactionResult = make::one(&sfTransactionResult, STI_UINT8, 3, "TransactionResult");
// 16-bit integers
SField const sfLedgerEntryType = make::one(&sfLedgerEntryType, STI_UINT16, 1, "LedgerEntryType", SField::sMD_Never);
SField const sfTransactionType = make::one(&sfTransactionType, STI_UINT16, 2, "TransactionType");
// 32-bit integers (common)
SField const sfFlags = make::one(&sfFlags, STI_UINT32, 2, "Flags");
SField const sfSourceTag = make::one(&sfSourceTag, STI_UINT32, 3, "SourceTag");
SField const sfSequence = make::one(&sfSequence, STI_UINT32, 4, "Sequence");
SField const sfPreviousTxnLgrSeq = make::one(&sfPreviousTxnLgrSeq, STI_UINT32, 5, "PreviousTxnLgrSeq", SField::sMD_DeleteFinal);
SField const sfLedgerSequence = make::one(&sfLedgerSequence, STI_UINT32, 6, "LedgerSequence");
SField const sfCloseTime = make::one(&sfCloseTime, STI_UINT32, 7, "CloseTime");
SField const sfParentCloseTime = make::one(&sfParentCloseTime, STI_UINT32, 8, "ParentCloseTime");
SField const sfSigningTime = make::one(&sfSigningTime, STI_UINT32, 9, "SigningTime");
SField const sfExpiration = make::one(&sfExpiration, STI_UINT32, 10, "Expiration");
SField const sfTransferRate = make::one(&sfTransferRate, STI_UINT32, 11, "TransferRate");
SField const sfWalletSize = make::one(&sfWalletSize, STI_UINT32, 12, "WalletSize");
SField const sfOwnerCount = make::one(&sfOwnerCount, STI_UINT32, 13, "OwnerCount");
SField const sfDestinationTag = make::one(&sfDestinationTag, STI_UINT32, 14, "DestinationTag");
// 32-bit integers (uncommon)
SField const sfHighQualityIn = make::one(&sfHighQualityIn, STI_UINT32, 16, "HighQualityIn");
SField const sfHighQualityOut = make::one(&sfHighQualityOut, STI_UINT32, 17, "HighQualityOut");
SField const sfLowQualityIn = make::one(&sfLowQualityIn, STI_UINT32, 18, "LowQualityIn");
SField const sfLowQualityOut = make::one(&sfLowQualityOut, STI_UINT32, 19, "LowQualityOut");
SField const sfQualityIn = make::one(&sfQualityIn, STI_UINT32, 20, "QualityIn");
SField const sfQualityOut = make::one(&sfQualityOut, STI_UINT32, 21, "QualityOut");
SField const sfStampEscrow = make::one(&sfStampEscrow, STI_UINT32, 22, "StampEscrow");
SField const sfBondAmount = make::one(&sfBondAmount, STI_UINT32, 23, "BondAmount");
SField const sfLoadFee = make::one(&sfLoadFee, STI_UINT32, 24, "LoadFee");
SField const sfOfferSequence = make::one(&sfOfferSequence, STI_UINT32, 25, "OfferSequence");
SField const sfFirstLedgerSequence = make::one(&sfFirstLedgerSequence, STI_UINT32, 26, "FirstLedgerSequence"); // Deprecated: do not use
SField const sfLastLedgerSequence = make::one(&sfLastLedgerSequence, STI_UINT32, 27, "LastLedgerSequence");
SField const sfTransactionIndex = make::one(&sfTransactionIndex, STI_UINT32, 28, "TransactionIndex");
SField const sfOperationLimit = make::one(&sfOperationLimit, STI_UINT32, 29, "OperationLimit");
SField const sfReferenceFeeUnits = make::one(&sfReferenceFeeUnits, STI_UINT32, 30, "ReferenceFeeUnits");
SField const sfReserveBase = make::one(&sfReserveBase, STI_UINT32, 31, "ReserveBase");
SField const sfReserveIncrement = make::one(&sfReserveIncrement, STI_UINT32, 32, "ReserveIncrement");
SField const sfSetFlag = make::one(&sfSetFlag, STI_UINT32, 33, "SetFlag");
SField const sfClearFlag = make::one(&sfClearFlag, STI_UINT32, 34, "ClearFlag");
// 64-bit integers
SField const sfIndexNext = make::one(&sfIndexNext, STI_UINT64, 1, "IndexNext");
SField const sfIndexPrevious = make::one(&sfIndexPrevious, STI_UINT64, 2, "IndexPrevious");
SField const sfBookNode = make::one(&sfBookNode, STI_UINT64, 3, "BookNode");
SField const sfOwnerNode = make::one(&sfOwnerNode, STI_UINT64, 4, "OwnerNode");
SField const sfBaseFee = make::one(&sfBaseFee, STI_UINT64, 5, "BaseFee");
SField const sfExchangeRate = make::one(&sfExchangeRate, STI_UINT64, 6, "ExchangeRate");
SField const sfLowNode = make::one(&sfLowNode, STI_UINT64, 7, "LowNode");
SField const sfHighNode = make::one(&sfHighNode, STI_UINT64, 8, "HighNode");
// 128-bit
SField const sfEmailHash = make::one(&sfEmailHash, STI_HASH128, 1, "EmailHash");
// 256-bit (common)
SField const sfLedgerHash = make::one(&sfLedgerHash, STI_HASH256, 1, "LedgerHash");
SField const sfParentHash = make::one(&sfParentHash, STI_HASH256, 2, "ParentHash");
SField const sfTransactionHash = make::one(&sfTransactionHash, STI_HASH256, 3, "TransactionHash");
SField const sfAccountHash = make::one(&sfAccountHash, STI_HASH256, 4, "AccountHash");
SField const sfPreviousTxnID = make::one(&sfPreviousTxnID, STI_HASH256, 5, "PreviousTxnID", SField::sMD_DeleteFinal);
SField const sfLedgerIndex = make::one(&sfLedgerIndex, STI_HASH256, 6, "LedgerIndex");
SField const sfWalletLocator = make::one(&sfWalletLocator, STI_HASH256, 7, "WalletLocator");
SField const sfRootIndex = make::one(&sfRootIndex, STI_HASH256, 8, "RootIndex", SField::sMD_Always);
SField const sfAccountTxnID = make::one(&sfAccountTxnID, STI_HASH256, 9, "AccountTxnID");
// 256-bit (uncommon)
SField const sfBookDirectory = make::one(&sfBookDirectory, STI_HASH256, 16, "BookDirectory");
SField const sfInvoiceID = make::one(&sfInvoiceID, STI_HASH256, 17, "InvoiceID");
SField const sfNickname = make::one(&sfNickname, STI_HASH256, 18, "Nickname");
SField const sfAmendment = make::one(&sfAmendment, STI_HASH256, 19, "Amendment");
// 160-bit (common)
SField const sfTakerPaysCurrency = make::one(&sfTakerPaysCurrency, STI_HASH160, 1, "TakerPaysCurrency");
SField const sfTakerPaysIssuer = make::one(&sfTakerPaysIssuer, STI_HASH160, 2, "TakerPaysIssuer");
SField const sfTakerGetsCurrency = make::one(&sfTakerGetsCurrency, STI_HASH160, 3, "TakerGetsCurrency");
SField const sfTakerGetsIssuer = make::one(&sfTakerGetsIssuer, STI_HASH160, 4, "TakerGetsIssuer");
// currency amount (common)
SField const sfAmount = make::one(&sfAmount, STI_AMOUNT, 1, "Amount");
SField const sfBalance = make::one(&sfBalance, STI_AMOUNT, 2, "Balance");
SField const sfLimitAmount = make::one(&sfLimitAmount, STI_AMOUNT, 3, "LimitAmount");
SField const sfTakerPays = make::one(&sfTakerPays, STI_AMOUNT, 4, "TakerPays");
SField const sfTakerGets = make::one(&sfTakerGets, STI_AMOUNT, 5, "TakerGets");
SField const sfLowLimit = make::one(&sfLowLimit, STI_AMOUNT, 6, "LowLimit");
SField const sfHighLimit = make::one(&sfHighLimit, STI_AMOUNT, 7, "HighLimit");
SField const sfFee = make::one(&sfFee, STI_AMOUNT, 8, "Fee");
SField const sfSendMax = make::one(&sfSendMax, STI_AMOUNT, 9, "SendMax");
// currency amount (uncommon)
SField const sfMinimumOffer = make::one(&sfMinimumOffer, STI_AMOUNT, 16, "MinimumOffer");
SField const sfRippleEscrow = make::one(&sfRippleEscrow, STI_AMOUNT, 17, "RippleEscrow");
SField const sfDeliveredAmount = make::one(&sfDeliveredAmount, STI_AMOUNT, 18, "DeliveredAmount");
// variable length
SField const sfPublicKey = make::one(&sfPublicKey, STI_VL, 1, "PublicKey");
SField const sfMessageKey = make::one(&sfMessageKey, STI_VL, 2, "MessageKey");
SField const sfSigningPubKey = make::one(&sfSigningPubKey, STI_VL, 3, "SigningPubKey");
SField const sfTxnSignature = make::one(&sfTxnSignature, STI_VL, 4, "TxnSignature", SField::sMD_Default, false);
SField const sfGenerator = make::one(&sfGenerator, STI_VL, 5, "Generator");
SField const sfSignature = make::one(&sfSignature, STI_VL, 6, "Signature", SField::sMD_Default, false);
SField const sfDomain = make::one(&sfDomain, STI_VL, 7, "Domain");
SField const sfFundCode = make::one(&sfFundCode, STI_VL, 8, "FundCode");
SField const sfRemoveCode = make::one(&sfRemoveCode, STI_VL, 9, "RemoveCode");
SField const sfExpireCode = make::one(&sfExpireCode, STI_VL, 10, "ExpireCode");
SField const sfCreateCode = make::one(&sfCreateCode, STI_VL, 11, "CreateCode");
SField const sfMemoType = make::one(&sfMemoType, STI_VL, 12, "MemoType");
SField const sfMemoData = make::one(&sfMemoData, STI_VL, 13, "MemoData");
SField const sfMemoFormat = make::one(&sfMemoFormat, STI_VL, 14, "MemoFormat");
// account
SField const sfAccount = make::one(&sfAccount, STI_ACCOUNT, 1, "Account");
SField const sfOwner = make::one(&sfOwner, STI_ACCOUNT, 2, "Owner");
SField const sfDestination = make::one(&sfDestination, STI_ACCOUNT, 3, "Destination");
SField const sfIssuer = make::one(&sfIssuer, STI_ACCOUNT, 4, "Issuer");
SField const sfTarget = make::one(&sfTarget, STI_ACCOUNT, 7, "Target");
SField const sfRegularKey = make::one(&sfRegularKey, STI_ACCOUNT, 8, "RegularKey");
// path set
SField const sfPaths = make::one(&sfPaths, STI_PATHSET, 1, "Paths");
// vector of 256-bit
SField const sfIndexes = make::one(&sfIndexes, STI_VECTOR256, 1, "Indexes", SField::sMD_Never);
SField const sfHashes = make::one(&sfHashes, STI_VECTOR256, 2, "Hashes");
SField const sfAmendments = make::one(&sfAmendments, STI_VECTOR256, 3, "Amendments");
// inner object
// OBJECT/1 is reserved for end of object
SField const sfTransactionMetaData = make::one(&sfTransactionMetaData, STI_OBJECT, 2, "TransactionMetaData");
SField const sfCreatedNode = make::one(&sfCreatedNode, STI_OBJECT, 3, "CreatedNode");
SField const sfDeletedNode = make::one(&sfDeletedNode, STI_OBJECT, 4, "DeletedNode");
SField const sfModifiedNode = make::one(&sfModifiedNode, STI_OBJECT, 5, "ModifiedNode");
SField const sfPreviousFields = make::one(&sfPreviousFields, STI_OBJECT, 6, "PreviousFields");
SField const sfFinalFields = make::one(&sfFinalFields, STI_OBJECT, 7, "FinalFields");
SField const sfNewFields = make::one(&sfNewFields, STI_OBJECT, 8, "NewFields");
SField const sfTemplateEntry = make::one(&sfTemplateEntry, STI_OBJECT, 9, "TemplateEntry");
SField const sfMemo = make::one(&sfMemo, STI_OBJECT, 10, "Memo");
// array of objects
// ARRAY/1 is reserved for end of array
SField const sfSigningAccounts = make::one(&sfSigningAccounts, STI_ARRAY, 2, "SigningAccounts");
SField const sfTxnSignatures = make::one(&sfTxnSignatures, STI_ARRAY, 3, "TxnSignatures", SField::sMD_Default, false);
SField const sfSignatures = make::one(&sfSignatures, STI_ARRAY, 4, "Signatures");
SField const sfTemplate = make::one(&sfTemplate, STI_ARRAY, 5, "Template");
SField const sfNecessary = make::one(&sfNecessary, STI_ARRAY, 6, "Necessary");
SField const sfSufficient = make::one(&sfSufficient, STI_ARRAY, 7, "Sufficient");
SField const sfAffectedNodes = make::one(&sfAffectedNodes, STI_ARRAY, 8, "AffectedNodes");
SField const sfMemos = make::one(&sfMemos, STI_ARRAY, 9, "Memos");
SField::SField (SerializedTypeID tid, int fv, const char* fn,
int meta, bool signing)
: fieldCode (field_code (tid, fv))
, fieldType (tid)
, fieldValue (fv)
, fieldName (fn)
, fieldMeta (meta)
, fieldNum (++num)
, signingField (signing)
, rawJsonName (getName ())
, jsonName (rawJsonName.c_str ())
{
}
SField::SField (int fc)
: fieldCode (fc)
, fieldType (STI_UNKNOWN)
, fieldValue (0)
, fieldMeta (sMD_Never)
, fieldNum (++num)
, signingField (true)
, rawJsonName (getName ())
, jsonName (rawJsonName.c_str ())
{
}
// call with the map mutex to protect num.
// This is naturally done with no extra expense
// from getField(int code).
SField::SField (SerializedTypeID tid, int fv)
: fieldCode (field_code (tid, fv)), fieldType (tid), fieldValue (fv),
fieldMeta (sMD_Default),
fieldNum (++num),
signingField (true),
jsonName (nullptr)
{
fieldName = std::to_string (tid) + '/' + std::to_string (fv);
rawJsonName = getName ();
jsonName = Json::StaticString (rawJsonName.c_str ());
assert ((fv != 1) || ((tid != STI_ARRAY) && (tid != STI_OBJECT)));
}
SField::ref SField::getField (int code)
{
auto it = knownCodeToField.find (code);
if (it != knownCodeToField.end ())
{
// 99+% of the time, it will be a valid, known field
return * (it->second);
}
int type = code >> 16;
int field = code & 0xffff;
// Don't dynamically extend types that have no binary encoding.
if ((field > 255) || (code < 0))
return sfInvalid;
switch (type)
{
// Types we are willing to dynamically extend
// types (common)
case STI_UINT16:
case STI_UINT32:
case STI_UINT64:
case STI_HASH128:
case STI_HASH256:
case STI_AMOUNT:
case STI_VL:
case STI_ACCOUNT:
case STI_OBJECT:
case STI_ARRAY:
// types (uncommon)
case STI_UINT8:
case STI_HASH160:
case STI_PATHSET:
case STI_VECTOR256:
break;
default:
return sfInvalid;
}
{
// Lookup in the run-time data base, and create if it does not
// yet exist.
StaticScopedLockType sl (SField_mutex);
auto it = unknownCodeToField.find (code);
if (it != unknownCodeToField.end ())
return * (it->second);
return *(unknownCodeToField[code] = std::unique_ptr<SField const>(
new SField(static_cast<SerializedTypeID>(type), field)));
}
}
int SField::compare (SField::ref f1, SField::ref f2)
{
// -1 = f1 comes before f2, 0 = illegal combination, 1 = f1 comes after f2
if ((f1.fieldCode <= 0) || (f2.fieldCode <= 0))
return 0;
if (f1.fieldCode < f2.fieldCode)
return -1;
if (f2.fieldCode < f1.fieldCode)
return 1;
return 0;
}
std::string SField::getName () const
{
if (!fieldName.empty ())
return fieldName;
if (fieldValue == 0)
return "";
return std::to_string(static_cast<int> (fieldType)) + "/" +
std::to_string(fieldValue);
}
SField::ref SField::getField (std::string const& fieldName)
{
for (auto const & fieldPair : knownCodeToField)
{
if (fieldPair.second->fieldName == fieldName)
return * (fieldPair.second);
}
{
StaticScopedLockType sl (SField_mutex);
for (auto const & fieldPair : unknownCodeToField)
{
if (fieldPair.second->fieldName == fieldName)
return * (fieldPair.second);
}
}
return sfInvalid;
}
} // ripple

View File

@@ -0,0 +1,416 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_FIELDNAMES_H
#define RIPPLE_FIELDNAMES_H
#include <ripple/basics/types/BasicTypes.h>
namespace ripple {
enum SerializedTypeID
{
// special types
STI_UNKNOWN = -2,
STI_DONE = -1,
STI_NOTPRESENT = 0,
// // types (common)
STI_UINT16 = 1,
STI_UINT32 = 2,
STI_UINT64 = 3,
STI_HASH128 = 4,
STI_HASH256 = 5,
STI_AMOUNT = 6,
STI_VL = 7,
STI_ACCOUNT = 8,
// 9-13 are reserved
STI_OBJECT = 14,
STI_ARRAY = 15,
// types (uncommon)
STI_UINT8 = 16,
STI_HASH160 = 17,
STI_PATHSET = 18,
STI_VECTOR256 = 19,
// high level types
// cannot be serialized inside other types
STI_TRANSACTION = 10001,
STI_LEDGERENTRY = 10002,
STI_VALIDATION = 10003,
STI_METADATA = 10004,
};
// constexpr
inline
int
field_code(SerializedTypeID id, int index)
{
return (static_cast<int>(id) << 16) | index;
}
// constexpr
inline
int
field_code(int id, int index)
{
return (id << 16) | index;
}
/** Identifies fields.
Fields are necessary to tag data in signed transactions so that
the binary format of the transaction can be canonicalized.
There are two categories of these fields:
1. Those that are created at compile time.
2. Those that are created at run time.
Both are always const. Category 1 can only be created in FieldNames.cpp.
This is enforced at compile time. Category 2 can only be created by
calling getField with an as yet unused fieldType and fieldValue (or the
equivalent fieldCode).
Each SField, once constructed, lives until program termination, and there
is only one instance per fieldType/fieldValue pair which serves the entire
application.
*/
class SField
{
public:
typedef const SField& ref;
typedef SField const* ptr;
enum
{
sMD_Never = 0x00,
sMD_ChangeOrig = 0x01, // original value when it changes
sMD_ChangeNew = 0x02, // new value when it changes
sMD_DeleteFinal = 0x04, // final value when it is deleted
sMD_Create = 0x08, // value when it's created
sMD_Always = 0x10, // value when node containing it is affected at all
sMD_Default = sMD_ChangeOrig | sMD_ChangeNew | sMD_DeleteFinal | sMD_Create
};
const int fieldCode; // (type<<16)|index
const SerializedTypeID fieldType; // STI_*
const int fieldValue; // Code number for protocol
std::string fieldName;
int fieldMeta;
int fieldNum;
bool signingField;
std::string rawJsonName;
Json::StaticString jsonName;
SField(SField const&) = delete;
SField& operator=(SField const&) = delete;
#ifndef _MSC_VER
SField(SField&&) = default;
#else // remove this when VS gets defaulted move members
SField(SField&& sf)
: fieldCode (std::move(sf.fieldCode))
, fieldType (std::move(sf.fieldType))
, fieldValue (std::move(sf.fieldValue))
, fieldName (std::move(sf.fieldName))
, fieldMeta (std::move(sf.fieldMeta))
, fieldNum (std::move(sf.fieldNum))
, signingField (std::move(sf.signingField))
, rawJsonName (std::move(sf.rawJsonName))
, jsonName (rawJsonName.c_str ())
{}
#endif
private:
// These constructors can only be called from FieldNames.cpp
SField (SerializedTypeID tid, int fv, const char* fn,
int meta = sMD_Default, bool signing = true);
explicit SField (int fc);
SField (SerializedTypeID id, int val);
public:
// getField will dynamically construct a new SField if necessary
static SField::ref getField (int fieldCode);
static SField::ref getField (std::string const& fieldName);
static SField::ref getField (int type, int value)
{
return getField (field_code (type, value));
}
static SField::ref getField (SerializedTypeID type, int value)
{
return getField (field_code (type, value));
}
std::string getName () const;
bool hasName () const
{
return !fieldName.empty ();
}
Json::StaticString const& getJsonName () const
{
return jsonName;
}
bool isGeneric () const
{
return fieldCode == 0;
}
bool isInvalid () const
{
return fieldCode == -1;
}
bool isUseful () const
{
return fieldCode > 0;
}
bool isKnown () const
{
return fieldType != STI_UNKNOWN;
}
bool isBinary () const
{
return fieldValue < 256;
}
// A discardable field is one that cannot be serialized, and
// should be discarded during serialization,like 'hash'.
// You cannot serialize an object's hash inside that object,
// but you can have it in the JSON representation.
bool isDiscardable () const
{
return fieldValue > 256;
}
int getCode () const
{
return fieldCode;
}
int getNum () const
{
return fieldNum;
}
static int getNumFields ()
{
return num;
}
bool isSigningField () const
{
return signingField;
}
void notSigningField ()
{
signingField = false;
}
bool shouldMeta (int c) const
{
return (fieldMeta & c) != 0;
}
void setMeta (int c)
{
fieldMeta = c;
}
bool shouldInclude (bool withSigningField) const
{
return (fieldValue < 256) && (withSigningField || signingField);
}
bool operator== (const SField& f) const
{
return fieldCode == f.fieldCode;
}
bool operator!= (const SField& f) const
{
return fieldCode != f.fieldCode;
}
static int compare (SField::ref f1, SField::ref f2);
struct make; // public, but still an implementation detail
private:
static int num;
};
extern SField const sfInvalid;
extern SField const sfGeneric;
extern SField const sfLedgerEntry;
extern SField const sfTransaction;
extern SField const sfValidation;
extern SField const sfMetadata;
// 8-bit integers
extern SField const sfCloseResolution;
extern SField const sfTemplateEntryType;
extern SField const sfTransactionResult;
// 16-bit integers
extern SField const sfLedgerEntryType;
extern SField const sfTransactionType;
// 32-bit integers (common)
extern SField const sfFlags;
extern SField const sfSourceTag;
extern SField const sfSequence;
extern SField const sfPreviousTxnLgrSeq;
extern SField const sfLedgerSequence;
extern SField const sfCloseTime;
extern SField const sfParentCloseTime;
extern SField const sfSigningTime;
extern SField const sfExpiration;
extern SField const sfTransferRate;
extern SField const sfWalletSize;
extern SField const sfOwnerCount;
extern SField const sfDestinationTag;
// 32-bit integers (uncommon)
extern SField const sfHighQualityIn;
extern SField const sfHighQualityOut;
extern SField const sfLowQualityIn;
extern SField const sfLowQualityOut;
extern SField const sfQualityIn;
extern SField const sfQualityOut;
extern SField const sfStampEscrow;
extern SField const sfBondAmount;
extern SField const sfLoadFee;
extern SField const sfOfferSequence;
extern SField const sfFirstLedgerSequence; // Deprecated: do not use
extern SField const sfLastLedgerSequence;
extern SField const sfTransactionIndex;
extern SField const sfOperationLimit;
extern SField const sfReferenceFeeUnits;
extern SField const sfReserveBase;
extern SField const sfReserveIncrement;
extern SField const sfSetFlag;
extern SField const sfClearFlag;
// 64-bit integers
extern SField const sfIndexNext;
extern SField const sfIndexPrevious;
extern SField const sfBookNode;
extern SField const sfOwnerNode;
extern SField const sfBaseFee;
extern SField const sfExchangeRate;
extern SField const sfLowNode;
extern SField const sfHighNode;
// 128-bit
extern SField const sfEmailHash;
// 256-bit (common)
extern SField const sfLedgerHash;
extern SField const sfParentHash;
extern SField const sfTransactionHash;
extern SField const sfAccountHash;
extern SField const sfPreviousTxnID;
extern SField const sfLedgerIndex;
extern SField const sfWalletLocator;
extern SField const sfRootIndex;
extern SField const sfAccountTxnID;
// 256-bit (uncommon)
extern SField const sfBookDirectory;
extern SField const sfInvoiceID;
extern SField const sfNickname;
extern SField const sfAmendment;
// 160-bit (common)
extern SField const sfTakerPaysCurrency;
extern SField const sfTakerPaysIssuer;
extern SField const sfTakerGetsCurrency;
extern SField const sfTakerGetsIssuer;
// currency amount (common)
extern SField const sfAmount;
extern SField const sfBalance;
extern SField const sfLimitAmount;
extern SField const sfTakerPays;
extern SField const sfTakerGets;
extern SField const sfLowLimit;
extern SField const sfHighLimit;
extern SField const sfFee;
extern SField const sfSendMax;
// currency amount (uncommon)
extern SField const sfMinimumOffer;
extern SField const sfRippleEscrow;
extern SField const sfDeliveredAmount;
// variable length
extern SField const sfPublicKey;
extern SField const sfMessageKey;
extern SField const sfSigningPubKey;
extern SField const sfTxnSignature;
extern SField const sfGenerator;
extern SField const sfSignature;
extern SField const sfDomain;
extern SField const sfFundCode;
extern SField const sfRemoveCode;
extern SField const sfExpireCode;
extern SField const sfCreateCode;
extern SField const sfMemoType;
extern SField const sfMemoData;
extern SField const sfMemoFormat;
// account
extern SField const sfAccount;
extern SField const sfOwner;
extern SField const sfDestination;
extern SField const sfIssuer;
extern SField const sfTarget;
extern SField const sfRegularKey;
// path set
extern SField const sfPaths;
// vector of 256-bit
extern SField const sfIndexes;
extern SField const sfHashes;
extern SField const sfAmendments;
// inner object
// OBJECT/1 is reserved for end of object
extern SField const sfTransactionMetaData;
extern SField const sfCreatedNode;
extern SField const sfDeletedNode;
extern SField const sfModifiedNode;
extern SField const sfPreviousFields;
extern SField const sfFinalFields;
extern SField const sfNewFields;
extern SField const sfTemplateEntry;
extern SField const sfMemo;
// array of objects
// ARRAY/1 is reserved for end of array
extern SField const sfSigningAccounts;
extern SField const sfTxnSignatures;
extern SField const sfSignatures;
extern SField const sfTemplate;
extern SField const sfNecessary;
extern SField const sfSufficient;
extern SField const sfAffectedNodes;
extern SField const sfMemos;
} // ripple
#endif

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_STAMOUNT_H
#define RIPPLE_STAMOUNT_H
#include <ripple/module/data/protocol/FieldNames.h>
#include <ripple/module/data/protocol/SField.h>
#include <ripple/module/data/protocol/Serializer.h>
#include <ripple/module/data/protocol/SerializedType.h>

View File

@@ -1,206 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
// This is not really a header file, but it can be used as one with
// appropriate #define statements.
/*
Common type common field - 1 byte
Common type uncommon field - 2 bytes
...
Rarity of fields determines the number of bytes.
This is done to reduce the average size of the messages.
*/
// types (common)
TYPE (Int16, UINT16, 1)
TYPE (Int32, UINT32, 2)
TYPE (Int64, UINT64, 3)
TYPE (Hash128, HASH128, 4)
TYPE (Hash256, HASH256, 5)
TYPE (Amount, AMOUNT, 6)
TYPE (VariableLength, VL, 7)
TYPE (Account, ACCOUNT, 8)
// 9-13 are reserved
TYPE (Object, OBJECT, 14)
TYPE (Array, ARRAY, 15)
// types (uncommon)
TYPE (Int8, UINT8, 16)
TYPE (Hash160, HASH160, 17)
TYPE (PathSet, PATHSET, 18)
TYPE (Vector256, VECTOR256, 19)
// 8-bit integers
FIELD (CloseResolution, UINT8, 1)
FIELD (TemplateEntryType, UINT8, 2)
FIELD (TransactionResult, UINT8, 3)
// 16-bit integers
FIELD (LedgerEntryType, UINT16, 1)
FIELD (TransactionType, UINT16, 2)
// 32-bit integers (common)
FIELD (Flags, UINT32, 2)
FIELD (SourceTag, UINT32, 3)
FIELD (Sequence, UINT32, 4)
FIELD (PreviousTxnLgrSeq, UINT32, 5)
FIELD (LedgerSequence, UINT32, 6)
FIELD (CloseTime, UINT32, 7)
FIELD (ParentCloseTime, UINT32, 8)
FIELD (SigningTime, UINT32, 9)
FIELD (Expiration, UINT32, 10)
FIELD (TransferRate, UINT32, 11)
FIELD (WalletSize, UINT32, 12)
FIELD (OwnerCount, UINT32, 13)
FIELD (DestinationTag, UINT32, 14)
// 32-bit integers (uncommon)
FIELD (HighQualityIn, UINT32, 16)
FIELD (HighQualityOut, UINT32, 17)
FIELD (LowQualityIn, UINT32, 18)
FIELD (LowQualityOut, UINT32, 19)
FIELD (QualityIn, UINT32, 20)
FIELD (QualityOut, UINT32, 21)
FIELD (StampEscrow, UINT32, 22)
FIELD (BondAmount, UINT32, 23)
FIELD (LoadFee, UINT32, 24)
FIELD (OfferSequence, UINT32, 25)
FIELD (FirstLedgerSequence, UINT32, 26) // Deprecated: do not use
FIELD (LastLedgerSequence, UINT32, 27)
FIELD (TransactionIndex, UINT32, 28)
FIELD (OperationLimit, UINT32, 29)
FIELD (ReferenceFeeUnits, UINT32, 30)
FIELD (ReserveBase, UINT32, 31)
FIELD (ReserveIncrement, UINT32, 32)
FIELD (SetFlag, UINT32, 33)
FIELD (ClearFlag, UINT32, 34)
// 64-bit integers
FIELD (IndexNext, UINT64, 1)
FIELD (IndexPrevious, UINT64, 2)
FIELD (BookNode, UINT64, 3)
FIELD (OwnerNode, UINT64, 4)
FIELD (BaseFee, UINT64, 5)
FIELD (ExchangeRate, UINT64, 6)
FIELD (LowNode, UINT64, 7)
FIELD (HighNode, UINT64, 8)
// 128-bit
FIELD (EmailHash, HASH128, 1)
// 256-bit (common)
FIELD (LedgerHash, HASH256, 1)
FIELD (ParentHash, HASH256, 2)
FIELD (TransactionHash, HASH256, 3)
FIELD (AccountHash, HASH256, 4)
FIELD (PreviousTxnID, HASH256, 5)
FIELD (LedgerIndex, HASH256, 6)
FIELD (WalletLocator, HASH256, 7)
FIELD (RootIndex, HASH256, 8)
FIELD (AccountTxnID, HASH256, 9)
// 256-bit (uncommon)
FIELD (BookDirectory, HASH256, 16)
FIELD (InvoiceID, HASH256, 17)
// FIELD 18 was Nickname - nicknames are no longer supported
FIELD (Amendment, HASH256, 19)
// 160-bit (common)
FIELD (TakerPaysCurrency, HASH160, 1)
FIELD (TakerPaysIssuer, HASH160, 2)
FIELD (TakerGetsCurrency, HASH160, 3)
FIELD (TakerGetsIssuer, HASH160, 4)
// currency amount (common)
FIELD (Amount, AMOUNT, 1)
FIELD (Balance, AMOUNT, 2)
FIELD (LimitAmount, AMOUNT, 3)
FIELD (TakerPays, AMOUNT, 4)
FIELD (TakerGets, AMOUNT, 5)
FIELD (LowLimit, AMOUNT, 6)
FIELD (HighLimit, AMOUNT, 7)
FIELD (Fee, AMOUNT, 8)
FIELD (SendMax, AMOUNT, 9)
// currency amount (uncommon)
FIELD (MinimumOffer, AMOUNT, 16)
FIELD (RippleEscrow, AMOUNT, 17)
FIELD (DeliveredAmount, AMOUNT, 18)
// variable length
FIELD (PublicKey, VL, 1)
FIELD (MessageKey, VL, 2)
FIELD (SigningPubKey, VL, 3)
FIELD (TxnSignature, VL, 4)
FIELD (Generator, VL, 5)
FIELD (Signature, VL, 6)
FIELD (Domain, VL, 7)
FIELD (FundCode, VL, 8)
FIELD (RemoveCode, VL, 9)
FIELD (ExpireCode, VL, 10)
FIELD (CreateCode, VL, 11)
FIELD (MemoType, VL, 12)
FIELD (MemoData, VL, 13)
FIELD (MemoFormat, VL, 14)
// account
FIELD (Account, ACCOUNT, 1)
FIELD (Owner, ACCOUNT, 2)
FIELD (Destination, ACCOUNT, 3)
FIELD (Issuer, ACCOUNT, 4)
FIELD (Target, ACCOUNT, 7)
FIELD (RegularKey, ACCOUNT, 8)
// path set
FIELD (Paths, PATHSET, 1)
// vector of 256-bit
FIELD (Indexes, VECTOR256, 1)
FIELD (Hashes, VECTOR256, 2)
FIELD (Amendments, VECTOR256, 3)
// inner object
// OBJECT/1 is reserved for end of object
FIELD (TransactionMetaData, OBJECT, 2)
FIELD (CreatedNode, OBJECT, 3)
FIELD (DeletedNode, OBJECT, 4)
FIELD (ModifiedNode, OBJECT, 5)
FIELD (PreviousFields, OBJECT, 6)
FIELD (FinalFields, OBJECT, 7)
FIELD (NewFields, OBJECT, 8)
FIELD (TemplateEntry, OBJECT, 9)
FIELD (Memo, OBJECT, 10)
// array of objects
// ARRAY/1 is reserved for end of array
FIELD (SigningAccounts, ARRAY, 2)
FIELD (TxnSignatures, ARRAY, 3)
FIELD (Signatures, ARRAY, 4)
FIELD (Template, ARRAY, 5)
FIELD (Necessary, ARRAY, 6)
FIELD (Sufficient, ARRAY, 7)
FIELD (AffectedNodes, ARRAY, 8)
FIELD (Memos, ARRAY, 9)
// vim:ts=4

View File

@@ -1353,10 +1353,10 @@ public:
unexpected (sfGeneric.isUseful (), "sfGeneric must not be useful");
SField sfTestVL (STI_VL, 255, "TestVL");
SField sfTestH256 (STI_HASH256, 255, "TestH256");
SField sfTestU32 (STI_UINT32, 255, "TestU32");
SField sfTestObject (STI_OBJECT, 255, "TestObject");
SField const& sfTestVL = SField::getField (STI_VL, 255);
SField const& sfTestH256 = SField::getField (STI_HASH256, 255);
SField const& sfTestU32 = SField::getField (STI_UINT32, 255);
SField const& sfTestObject = SField::getField (STI_OBJECT, 255);
SOTemplate elements;
elements.push_back (SOElement (sfFlags, SOE_REQUIRED));

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_SERIALIZEDTYPE_H
#define RIPPLE_SERIALIZEDTYPE_H
#include <ripple/module/data/protocol/FieldNames.h>
#include <ripple/module/data/protocol/SField.h>
#include <ripple/module/data/protocol/Serializer.h>
namespace ripple {

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_SERIALIZEDTYPES_H
#define RIPPLE_SERIALIZEDTYPES_H
#include <ripple/module/data/protocol/FieldNames.h>
#include <ripple/module/data/protocol/SField.h>
#include <ripple/module/data/protocol/Serializer.h>
#include <ripple/module/data/protocol/STBitString.h>
#include <ripple/module/data/protocol/STInteger.h>

View File

@@ -62,21 +62,6 @@ TxFormats::TxFormats ()
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
;
add ("Contract", ttCONTRACT)
<< SOElement (sfExpiration, SOE_REQUIRED)
<< SOElement (sfBondAmount, SOE_REQUIRED)
<< SOElement (sfStampEscrow, SOE_REQUIRED)
<< SOElement (sfRippleEscrow, SOE_REQUIRED)
<< SOElement (sfCreateCode, SOE_OPTIONAL)
<< SOElement (sfFundCode, SOE_OPTIONAL)
<< SOElement (sfRemoveCode, SOE_OPTIONAL)
<< SOElement (sfExpireCode, SOE_OPTIONAL)
;
add ("RemoveContract", ttCONTRACT_REMOVE)
<< SOElement (sfTarget, SOE_REQUIRED)
;
add ("EnableAmendment", ttAMENDMENT)
<< SOElement (sfAmendment, SOE_REQUIRED)
;

View File

@@ -41,8 +41,7 @@ enum TxType
ttNICKNAME_SET = 6, // open
ttOFFER_CREATE = 7,
ttOFFER_CANCEL = 8,
ttCONTRACT = 9,
ttCONTRACT_REMOVE = 10, // can we use the same msg as offer cancel
no_longer_used = 9,
ttTRUST_SET = 20,

View File

@@ -67,7 +67,7 @@
#include <ripple/module/data/crypto/RFC1751.cpp>
#include <ripple/module/data/protocol/BuildInfo.cpp>
#include <ripple/module/data/protocol/FieldNames.cpp>
#include <ripple/module/data/protocol/SField.cpp>
#include <ripple/module/data/protocol/HashPrefix.cpp>
#include <ripple/module/data/protocol/LedgerFormats.cpp>
#include <ripple/module/data/protocol/RippleAddress.cpp>

View File

@@ -30,7 +30,7 @@ typedef struct bignum_st BIGNUM;
#include <ripple/module/data/crypto/Base58Data.h>
#include <ripple/module/data/crypto/RFC1751.h>
#include <ripple/module/data/protocol/BuildInfo.h>
#include <ripple/module/data/protocol/FieldNames.h>
#include <ripple/module/data/protocol/SField.h>
#include <ripple/module/data/protocol/HashPrefix.h>
#include <ripple/module/data/protocol/Protocol.h>
#include <ripple/module/data/protocol/RippleAddress.h>