mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-28 15:05:53 +00:00
Split up ripple_SerializedObject.h
This commit is contained in:
@@ -23,14 +23,7 @@ enum SerializedTypeID
|
|||||||
STI_VALIDATION = 10003,
|
STI_VALIDATION = 10003,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SOE_Flags
|
// VFALCO: TODO, rename this to NamedField
|
||||||
{
|
|
||||||
SOE_INVALID = -1,
|
|
||||||
SOE_REQUIRED = 0, // required
|
|
||||||
SOE_OPTIONAL = 1, // optional, may be present with default value
|
|
||||||
SOE_DEFAULT = 2, // optional, if present, must not have default value
|
|
||||||
};
|
|
||||||
|
|
||||||
class SField
|
class SField
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -117,22 +117,6 @@ UPTR_T<SerializedType> STObject::makeDeserializedObject(SerializedTypeID id, SFi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SOTemplate::push_back(const SOElement &r)
|
|
||||||
{
|
|
||||||
if (mIndex.empty())
|
|
||||||
mIndex.resize(SField::getNumFields() + 1, -1);
|
|
||||||
assert(r.e_field.getNum() < mIndex.size());
|
|
||||||
assert(getIndex(r.e_field) == -1);
|
|
||||||
mIndex[r.e_field.getNum()] = mTypes.size();
|
|
||||||
mTypes.push_back(new SOElement(r));
|
|
||||||
}
|
|
||||||
|
|
||||||
int SOTemplate::getIndex(SField::ref f) const
|
|
||||||
{
|
|
||||||
assert(f.getNum() < mIndex.size());
|
|
||||||
return mIndex[f.getNum()];
|
|
||||||
}
|
|
||||||
|
|
||||||
void STObject::set(const SOTemplate& type)
|
void STObject::set(const SOTemplate& type)
|
||||||
{
|
{
|
||||||
mData.clear();
|
mData.clear();
|
||||||
|
|||||||
@@ -4,41 +4,17 @@
|
|||||||
DEFINE_INSTANCE(SerializedObject);
|
DEFINE_INSTANCE(SerializedObject);
|
||||||
DEFINE_INSTANCE(SerializedArray);
|
DEFINE_INSTANCE(SerializedArray);
|
||||||
|
|
||||||
// Serializable object/array types
|
|
||||||
|
|
||||||
class SOElement
|
|
||||||
{ // An element in the description of a serialized object
|
|
||||||
public:
|
|
||||||
SField::ref e_field;
|
|
||||||
const SOE_Flags flags;
|
|
||||||
|
|
||||||
SOElement(SField::ref fi, SOE_Flags fl) : e_field(fi), flags(fl) { ; }
|
|
||||||
};
|
|
||||||
|
|
||||||
class SOTemplate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SOTemplate() { ; }
|
|
||||||
const std::vector<const SOElement*>& peek() const { return mTypes; }
|
|
||||||
void push_back(const SOElement& r);
|
|
||||||
int getIndex(SField::ref) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<const SOElement*> mTypes;
|
|
||||||
std::vector<int> mIndex; // field num -> index
|
|
||||||
};
|
|
||||||
|
|
||||||
class STObject : public SerializedType, private IS_INSTANCE(SerializedObject)
|
class STObject : public SerializedType, private IS_INSTANCE(SerializedObject)
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
STObject() : mType(NULL) { ; }
|
STObject() : mType(NULL) { ; }
|
||||||
|
|
||||||
STObject(SField::ref name) : SerializedType(name), mType(NULL) { ; }
|
explicit STObject(SField::ref name) : SerializedType(name), mType(NULL) { ; }
|
||||||
|
|
||||||
STObject(const SOTemplate& type, SField::ref name) : SerializedType(name)
|
STObject (const SOTemplate& type, SField::ref name) : SerializedType(name)
|
||||||
{ set(type); }
|
{ set(type); }
|
||||||
|
|
||||||
STObject(const SOTemplate& type, SerializerIterator& sit, SField::ref name) : SerializedType(name)
|
STObject (const SOTemplate& type, SerializerIterator& sit, SField::ref name) : SerializedType(name)
|
||||||
{ set(sit); setType(type); }
|
{ set(sit); setType(type); }
|
||||||
|
|
||||||
UPTR_T<STObject> oClone() const { return UPTR_T<STObject>(new STObject(*this)); }
|
UPTR_T<STObject> oClone() const { return UPTR_T<STObject>(new STObject(*this)); }
|
||||||
@@ -184,7 +160,7 @@ namespace boost
|
|||||||
template<> struct range_const_iterator<STObject> { typedef STObject::const_iterator type; };
|
template<> struct range_const_iterator<STObject> { typedef STObject::const_iterator type; };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
class STArray : public SerializedType, private IS_INSTANCE(SerializedArray)
|
class STArray : public SerializedType, private IS_INSTANCE(SerializedArray)
|
||||||
{
|
{
|
||||||
@@ -197,12 +173,12 @@ public:
|
|||||||
typedef boost::ptr_vector<STObject>::size_type size_type;
|
typedef boost::ptr_vector<STObject>::size_type size_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
STArray() { ; }
|
STArray () { ; }
|
||||||
STArray(int n) { value.reserve(n); }
|
explicit STArray(int n) { value.reserve(n); }
|
||||||
STArray(SField::ref f) : SerializedType(f) { ; }
|
explicit STArray(SField::ref f) : SerializedType(f) { ; }
|
||||||
STArray(SField::ref f, int n) : SerializedType(f) { value.reserve(n); }
|
STArray(SField::ref f, int n) : SerializedType(f) { value.reserve(n); }
|
||||||
STArray(SField::ref f, const vector& v) : SerializedType(f), value(v) { ; }
|
STArray(SField::ref f, const vector& v) : SerializedType(f), value(v) { ; }
|
||||||
STArray(vector& v) : value(v) { ; }
|
explicit STArray(vector& v) : value(v) { ; }
|
||||||
|
|
||||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||||
@@ -210,7 +186,9 @@ public:
|
|||||||
const vector& getValue() const { return value; }
|
const vector& getValue() const { return value; }
|
||||||
vector& getValue() { return value; }
|
vector& getValue() { return value; }
|
||||||
|
|
||||||
// vector-like functions
|
// VFALCO: NOTE as long as we're married to boost why not use boost::iterator_facade?
|
||||||
|
//
|
||||||
|
// vector-like functions
|
||||||
void push_back(const STObject& object) { value.push_back(object.oClone().release()); }
|
void push_back(const STObject& object) { value.push_back(object.oClone().release()); }
|
||||||
STObject& operator[](int j) { return value[j]; }
|
STObject& operator[](int j) { return value[j]; }
|
||||||
const STObject& operator[](int j) const { return value[j]; }
|
const STObject& operator[](int j) const { return value[j]; }
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
|
||||||
|
SOTemplate::SOTemplate ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SOTemplate::push_back (SOElement const& r)
|
||||||
|
{
|
||||||
|
// Ensure there is the enough space in the index mapping
|
||||||
|
// table for all possible fields.
|
||||||
|
//
|
||||||
|
if (mIndex.empty())
|
||||||
|
{
|
||||||
|
// Unmapped indices will be set to -1
|
||||||
|
//
|
||||||
|
mIndex.resize (SField::getNumFields() + 1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the field's index is in range
|
||||||
|
//
|
||||||
|
assert (r.e_field.getNum() < mIndex.size());
|
||||||
|
|
||||||
|
// Make sure that this field hasn't already been assigned
|
||||||
|
//
|
||||||
|
assert(getIndex(r.e_field) == -1);
|
||||||
|
|
||||||
|
// Add the field to the index mapping table
|
||||||
|
//
|
||||||
|
mIndex [r.e_field.getNum ()] = mTypes.size();
|
||||||
|
|
||||||
|
// Append the new element.
|
||||||
|
//
|
||||||
|
mTypes.push_back (new SOElement (r));
|
||||||
|
}
|
||||||
|
|
||||||
|
int SOTemplate::getIndex (SField::ref f) const
|
||||||
|
{
|
||||||
|
// The mapping table should be large enough for any possible field
|
||||||
|
//
|
||||||
|
assert (f.getNum() < mIndex.size());
|
||||||
|
|
||||||
|
return mIndex[f.getNum()];
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
#ifndef RIPPLE_SERIALIZEDOBJECTTEMPLATE_H
|
||||||
|
#define RIPPLE_SERIALIZEDOBJECTTEMPLATE_H
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Flags for elements in a SerializedObjectTemplate.
|
||||||
|
*/
|
||||||
|
// VFALCO: NOTE, these don't look like bit-flags...
|
||||||
|
enum SOE_Flags
|
||||||
|
{
|
||||||
|
SOE_INVALID = -1,
|
||||||
|
SOE_REQUIRED = 0, // required
|
||||||
|
SOE_OPTIONAL = 1, // optional, may be present with default value
|
||||||
|
SOE_DEFAULT = 2, // optional, if present, must not have default value
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/** An element in a SerializedObjectTemplate.
|
||||||
|
*/
|
||||||
|
class SOElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SField::ref const e_field;
|
||||||
|
SOE_Flags const flags;
|
||||||
|
|
||||||
|
SOElement (SField::ref fieldName, SOE_Flags flags)
|
||||||
|
: e_field (fieldName)
|
||||||
|
, flags (flags)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Defines the fields and their attributes within a SerializedObject.
|
||||||
|
|
||||||
|
Each subclass of SerializedObject will provide its own template
|
||||||
|
describing the available fields and their metadata attributes.
|
||||||
|
*/
|
||||||
|
class SOTemplate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/** Create an empty template.
|
||||||
|
|
||||||
|
After creating the template, call @ref push_back with the
|
||||||
|
desired fields.
|
||||||
|
|
||||||
|
@see push_back
|
||||||
|
*/
|
||||||
|
SOTemplate ();
|
||||||
|
|
||||||
|
std::vector <SOElement const*> const& peek() const
|
||||||
|
{
|
||||||
|
return mTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Add an element to the template.
|
||||||
|
*/
|
||||||
|
void push_back (SOElement const& r);
|
||||||
|
|
||||||
|
/** Retrieve the position of a named field.
|
||||||
|
*/
|
||||||
|
int getIndex (SField::ref) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<SOElement const*> mTypes;
|
||||||
|
std::vector <int> mIndex; // field num -> index
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -82,6 +82,7 @@
|
|||||||
#include "protocol/ripple_RippleAddress.cpp"
|
#include "protocol/ripple_RippleAddress.cpp"
|
||||||
#include "protocol/ripple_SerializedTypes.cpp"
|
#include "protocol/ripple_SerializedTypes.cpp"
|
||||||
#include "protocol/ripple_Serializer.cpp"
|
#include "protocol/ripple_Serializer.cpp"
|
||||||
|
#include "protocol/ripple_SerializedObjectTemplate.cpp"
|
||||||
#include "protocol/ripple_SerializedObject.cpp"
|
#include "protocol/ripple_SerializedObject.cpp"
|
||||||
#include "protocol/ripple_TER.cpp"
|
#include "protocol/ripple_TER.cpp"
|
||||||
#include "protocol/ripple_TransactionFormat.cpp"
|
#include "protocol/ripple_TransactionFormat.cpp"
|
||||||
|
|||||||
@@ -72,6 +72,7 @@
|
|||||||
#include "protocol/ripple_Serializer.h" // needs CKey
|
#include "protocol/ripple_Serializer.h" // needs CKey
|
||||||
#include "protocol/ripple_TER.h"
|
#include "protocol/ripple_TER.h"
|
||||||
#include "protocol/ripple_SerializedTypes.h" // needs Serializer, TER
|
#include "protocol/ripple_SerializedTypes.h" // needs Serializer, TER
|
||||||
|
#include "protocol/ripple_SerializedObjectTemplate.h"
|
||||||
#include "protocol/ripple_SerializedObject.h"
|
#include "protocol/ripple_SerializedObject.h"
|
||||||
#include "protocol/ripple_LedgerFormat.h" // needs SOTemplate from SerializedObject
|
#include "protocol/ripple_LedgerFormat.h" // needs SOTemplate from SerializedObject
|
||||||
#include "protocol/ripple_TransactionFormat.h"
|
#include "protocol/ripple_TransactionFormat.h"
|
||||||
|
|||||||
@@ -315,6 +315,12 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="modules\ripple_data\protocol\ripple_SerializedObjectTemplate.cpp">
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="modules\ripple_data\protocol\ripple_SerializedTypes.cpp">
|
<ClCompile Include="modules\ripple_data\protocol\ripple_SerializedTypes.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
@@ -1311,6 +1317,7 @@
|
|||||||
<ClInclude Include="modules\ripple_data\protocol\ripple_RippleSystem.h" />
|
<ClInclude Include="modules\ripple_data\protocol\ripple_RippleSystem.h" />
|
||||||
<ClInclude Include="modules\ripple_data\protocol\ripple_SerializeDeclarations.h" />
|
<ClInclude Include="modules\ripple_data\protocol\ripple_SerializeDeclarations.h" />
|
||||||
<ClInclude Include="modules\ripple_data\protocol\ripple_SerializedObject.h" />
|
<ClInclude Include="modules\ripple_data\protocol\ripple_SerializedObject.h" />
|
||||||
|
<ClInclude Include="modules\ripple_data\protocol\ripple_SerializedObjectTemplate.h" />
|
||||||
<ClInclude Include="modules\ripple_data\protocol\ripple_SerializedTypes.h" />
|
<ClInclude Include="modules\ripple_data\protocol\ripple_SerializedTypes.h" />
|
||||||
<ClInclude Include="modules\ripple_data\protocol\ripple_Serializer.h" />
|
<ClInclude Include="modules\ripple_data\protocol\ripple_Serializer.h" />
|
||||||
<ClInclude Include="modules\ripple_data\protocol\ripple_TER.h" />
|
<ClInclude Include="modules\ripple_data\protocol\ripple_TER.h" />
|
||||||
|
|||||||
@@ -816,6 +816,9 @@
|
|||||||
<ClCompile Include="src\cpp\ripple\ripple_HashedObject.cpp">
|
<ClCompile Include="src\cpp\ripple\ripple_HashedObject.cpp">
|
||||||
<Filter>1. Modules\ripple_main\refactored</Filter>
|
<Filter>1. Modules\ripple_main\refactored</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="modules\ripple_data\protocol\ripple_SerializedObjectTemplate.cpp">
|
||||||
|
<Filter>1. Modules\ripple_data\protocol</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="database\sqlite3ext.h">
|
<ClInclude Include="database\sqlite3ext.h">
|
||||||
@@ -1520,6 +1523,9 @@
|
|||||||
<ClInclude Include="src\cpp\ripple\ripple_HashedObject.h">
|
<ClInclude Include="src\cpp\ripple\ripple_HashedObject.h">
|
||||||
<Filter>1. Modules\ripple_main\refactored</Filter>
|
<Filter>1. Modules\ripple_main\refactored</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="modules\ripple_data\protocol\ripple_SerializedObjectTemplate.h">
|
||||||
|
<Filter>1. Modules\ripple_data\protocol</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="SConstruct" />
|
<None Include="SConstruct" />
|
||||||
|
|||||||
@@ -1,128 +1,139 @@
|
|||||||
|
|
||||||
DECLARE_INSTANCE(SerializedValidation);
|
DECLARE_INSTANCE(SerializedValidation);
|
||||||
|
|
||||||
SOTemplate sValidationFormat;
|
SerializedValidation::SerializedValidation (SerializerIterator& sit, bool checkSignature)
|
||||||
|
: STObject (getFormat (), sit, sfValidation)
|
||||||
void SVFInit()
|
, mTrusted (false)
|
||||||
{
|
{
|
||||||
sValidationFormat.push_back(SOElement(sfFlags, SOE_REQUIRED));
|
mNodeID = RippleAddress::createNodePublic(getFieldVL(sfSigningPubKey)).getNodeID();
|
||||||
sValidationFormat.push_back(SOElement(sfLedgerHash, SOE_REQUIRED));
|
assert(mNodeID.isNonZero());
|
||||||
sValidationFormat.push_back(SOElement(sfLedgerSequence, SOE_OPTIONAL));
|
if (checkSignature && !isValid())
|
||||||
sValidationFormat.push_back(SOElement(sfCloseTime, SOE_OPTIONAL));
|
{
|
||||||
sValidationFormat.push_back(SOElement(sfLoadFee, SOE_OPTIONAL));
|
Log(lsTRACE) << "Invalid validation " << getJson(0);
|
||||||
sValidationFormat.push_back(SOElement(sfFeatures, SOE_OPTIONAL));
|
throw std::runtime_error("Invalid validation");
|
||||||
sValidationFormat.push_back(SOElement(sfBaseFee, SOE_OPTIONAL));
|
}
|
||||||
sValidationFormat.push_back(SOElement(sfReserveBase, SOE_OPTIONAL));
|
|
||||||
sValidationFormat.push_back(SOElement(sfReserveIncrement, SOE_OPTIONAL));
|
|
||||||
sValidationFormat.push_back(SOElement(sfSigningTime, SOE_REQUIRED));
|
|
||||||
sValidationFormat.push_back(SOElement(sfSigningPubKey, SOE_REQUIRED));
|
|
||||||
sValidationFormat.push_back(SOElement(sfSignature, SOE_OPTIONAL));
|
|
||||||
};
|
|
||||||
|
|
||||||
const uint32 SerializedValidation::sFullFlag = 0x1;
|
|
||||||
|
|
||||||
SerializedValidation::SerializedValidation(SerializerIterator& sit, bool checkSignature)
|
|
||||||
: STObject(sValidationFormat, sit, sfValidation), mTrusted(false)
|
|
||||||
{
|
|
||||||
mNodeID = RippleAddress::createNodePublic(getFieldVL(sfSigningPubKey)).getNodeID();
|
|
||||||
assert(mNodeID.isNonZero());
|
|
||||||
if (checkSignature && !isValid())
|
|
||||||
{
|
|
||||||
Log(lsTRACE) << "Invalid validation " << getJson(0);
|
|
||||||
throw std::runtime_error("Invalid validation");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SerializedValidation::SerializedValidation(const uint256& ledgerHash, uint32 signTime,
|
SerializedValidation::SerializedValidation (
|
||||||
const RippleAddress& raPub, bool isFull)
|
const uint256& ledgerHash, uint32 signTime,
|
||||||
: STObject(sValidationFormat, sfValidation), mTrusted(false)
|
const RippleAddress& raPub, bool isFull)
|
||||||
|
: STObject (getFormat (), sfValidation)
|
||||||
|
, mTrusted (false)
|
||||||
{ // Does not sign
|
{ // Does not sign
|
||||||
setFieldH256(sfLedgerHash, ledgerHash);
|
setFieldH256(sfLedgerHash, ledgerHash);
|
||||||
setFieldU32(sfSigningTime, signTime);
|
setFieldU32(sfSigningTime, signTime);
|
||||||
|
|
||||||
setFieldVL(sfSigningPubKey, raPub.getNodePublic());
|
setFieldVL(sfSigningPubKey, raPub.getNodePublic());
|
||||||
mNodeID = raPub.getNodeID();
|
mNodeID = raPub.getNodeID();
|
||||||
assert(mNodeID.isNonZero());
|
assert(mNodeID.isNonZero());
|
||||||
|
|
||||||
if (!isFull)
|
if (!isFull)
|
||||||
setFlag(sFullFlag);
|
setFlag(sFullFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializedValidation::sign(const RippleAddress& raPriv)
|
void SerializedValidation::sign(const RippleAddress& raPriv)
|
||||||
{
|
{
|
||||||
uint256 signingHash;
|
uint256 signingHash;
|
||||||
sign(signingHash, raPriv);
|
sign(signingHash, raPriv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializedValidation::sign(uint256& signingHash, const RippleAddress& raPriv)
|
void SerializedValidation::sign(uint256& signingHash, const RippleAddress& raPriv)
|
||||||
{
|
{
|
||||||
signingHash = getSigningHash();
|
signingHash = getSigningHash();
|
||||||
std::vector<unsigned char> signature;
|
std::vector<unsigned char> signature;
|
||||||
raPriv.signNodePrivate(signingHash, signature);
|
raPriv.signNodePrivate(signingHash, signature);
|
||||||
setFieldVL(sfSignature, signature);
|
setFieldVL(sfSignature, signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 SerializedValidation::getSigningHash() const
|
uint256 SerializedValidation::getSigningHash() const
|
||||||
{
|
{
|
||||||
return STObject::getSigningHash(theConfig.SIGN_VALIDATION);
|
return STObject::getSigningHash(theConfig.SIGN_VALIDATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 SerializedValidation::getLedgerHash() const
|
uint256 SerializedValidation::getLedgerHash() const
|
||||||
{
|
{
|
||||||
return getFieldH256(sfLedgerHash);
|
return getFieldH256(sfLedgerHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 SerializedValidation::getSignTime() const
|
uint32 SerializedValidation::getSignTime() const
|
||||||
{
|
{
|
||||||
return getFieldU32(sfSigningTime);
|
return getFieldU32(sfSigningTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 SerializedValidation::getFlags() const
|
uint32 SerializedValidation::getFlags() const
|
||||||
{
|
{
|
||||||
return getFieldU32(sfFlags);
|
return getFieldU32(sfFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SerializedValidation::isValid() const
|
bool SerializedValidation::isValid() const
|
||||||
{
|
{
|
||||||
return isValid(getSigningHash());
|
return isValid(getSigningHash());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SerializedValidation::isValid(const uint256& signingHash) const
|
bool SerializedValidation::isValid(const uint256& signingHash) const
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RippleAddress raPublicKey = RippleAddress::createNodePublic(getFieldVL(sfSigningPubKey));
|
RippleAddress raPublicKey = RippleAddress::createNodePublic(getFieldVL(sfSigningPubKey));
|
||||||
return raPublicKey.isValid() && raPublicKey.verifyNodePublic(signingHash, getFieldVL(sfSignature));
|
return raPublicKey.isValid() && raPublicKey.verifyNodePublic(signingHash, getFieldVL(sfSignature));
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
Log(lsINFO) << "exception validating validation";
|
Log(lsINFO) << "exception validating validation";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RippleAddress SerializedValidation::getSignerPublic() const
|
RippleAddress SerializedValidation::getSignerPublic() const
|
||||||
{
|
{
|
||||||
RippleAddress a;
|
RippleAddress a;
|
||||||
a.setNodePublic(getFieldVL(sfSigningPubKey));
|
a.setNodePublic(getFieldVL(sfSigningPubKey));
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SerializedValidation::isFull() const
|
bool SerializedValidation::isFull() const
|
||||||
{
|
{
|
||||||
return (getFlags() & sFullFlag) != 0;
|
return (getFlags() & sFullFlag) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<unsigned char> SerializedValidation::getSignature() const
|
std::vector<unsigned char> SerializedValidation::getSignature() const
|
||||||
{
|
{
|
||||||
return getFieldVL(sfSignature);
|
return getFieldVL(sfSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<unsigned char> SerializedValidation::getSigned() const
|
std::vector<unsigned char> SerializedValidation::getSigned() const
|
||||||
{
|
{
|
||||||
Serializer s;
|
Serializer s;
|
||||||
add(s);
|
add(s);
|
||||||
return s.peekData();
|
return s.peekData();
|
||||||
|
}
|
||||||
|
|
||||||
|
SOTemplate const& SerializedValidation::getFormat ()
|
||||||
|
{
|
||||||
|
struct FormatHolder
|
||||||
|
{
|
||||||
|
SOTemplate format;
|
||||||
|
|
||||||
|
FormatHolder ()
|
||||||
|
{
|
||||||
|
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 (sfFeatures, 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));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static FormatHolder holder;
|
||||||
|
|
||||||
|
return holder.format;
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
#ifndef __VALIDATION__
|
#ifndef RIPPLE_SERIALIZEDVALIDATION_H
|
||||||
#define __VALIDATION__
|
#define RIPPLE_SERIALIZEDVALIDATION_H
|
||||||
|
|
||||||
DEFINE_INSTANCE(SerializedValidation);
|
DEFINE_INSTANCE (SerializedValidation);
|
||||||
|
|
||||||
class SerializedValidation : public STObject, private IS_INSTANCE(SerializedValidation)
|
class SerializedValidation
|
||||||
|
: public STObject
|
||||||
|
, private IS_INSTANCE (SerializedValidation)
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef boost::shared_ptr<SerializedValidation> pointer;
|
typedef boost::shared_ptr<SerializedValidation> pointer;
|
||||||
typedef const boost::shared_ptr<SerializedValidation>& ref;
|
typedef const boost::shared_ptr<SerializedValidation>& ref;
|
||||||
|
|
||||||
static const uint32 sFullFlag;
|
static const uint32 sFullFlag = 0x1;
|
||||||
|
|
||||||
// These throw if the object is not valid
|
// These throw if the object is not valid
|
||||||
SerializedValidation(SerializerIterator& sit, bool checkSignature = true);
|
SerializedValidation (SerializerIterator& sit, bool checkSignature = true);
|
||||||
|
|
||||||
// Does not sign the validation
|
// Does not sign the validation
|
||||||
SerializedValidation(const uint256& ledgerHash, uint32 signTime, const RippleAddress& raPub, bool isFull);
|
SerializedValidation (const uint256& ledgerHash, uint32 signTime, const RippleAddress& raPub, bool isFull);
|
||||||
|
|
||||||
uint256 getLedgerHash() const;
|
uint256 getLedgerHash() const;
|
||||||
uint32 getSignTime() const;
|
uint32 getSignTime() const;
|
||||||
@@ -36,15 +38,17 @@ public:
|
|||||||
|
|
||||||
// The validation this replaced
|
// The validation this replaced
|
||||||
const uint256& getPreviousHash() { return mPreviousHash; }
|
const uint256& getPreviousHash() { return mPreviousHash; }
|
||||||
bool isPreviousHash(const uint256& h) { return mPreviousHash == h; }
|
bool isPreviousHash(const uint256& h) const { return mPreviousHash == h; }
|
||||||
void setPreviousHash(const uint256& h) { mPreviousHash = h; }
|
void setPreviousHash(const uint256& h) { mPreviousHash = h; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint256 mPreviousHash;
|
static SOTemplate const& getFormat ();
|
||||||
|
|
||||||
|
void setNode ();
|
||||||
|
|
||||||
|
uint256 mPreviousHash;
|
||||||
uint160 mNodeID;
|
uint160 mNodeID;
|
||||||
bool mTrusted;
|
bool mTrusted;
|
||||||
|
|
||||||
void setNode();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -12,9 +12,9 @@
|
|||||||
|
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
|
// VFALCO: TODO make these singletons that initialize statically
|
||||||
extern void TFInit();
|
extern void TFInit();
|
||||||
extern void LEFInit();
|
extern void LEFInit();
|
||||||
extern void SVFInit();
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost::unit_test;
|
using namespace boost::unit_test;
|
||||||
@@ -213,9 +213,9 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
InstanceType::multiThread();
|
InstanceType::multiThread();
|
||||||
|
|
||||||
|
// VFALCO: TODO make these singletons that initialize statically
|
||||||
TFInit();
|
TFInit();
|
||||||
LEFInit();
|
LEFInit();
|
||||||
SVFInit();
|
|
||||||
|
|
||||||
if (vm.count("unittest"))
|
if (vm.count("unittest"))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user