mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Ability to compare serialized types.
This commit is contained in:
@@ -167,6 +167,22 @@ std::string STObject::getText() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool STObject::isEquivalent(const SerializedType& t) const
|
||||||
|
{
|
||||||
|
const STObject* v=dynamic_cast<const STObject*>(&t);
|
||||||
|
if(!v) return false;
|
||||||
|
boost::ptr_vector<SerializedType>::const_iterator it1=mData.begin(), end1=mData.end();
|
||||||
|
boost::ptr_vector<SerializedType>::const_iterator it2=v->mData.begin(), end2=v->mData.end();
|
||||||
|
while((it1!=end1) && (it2!=end2))
|
||||||
|
{
|
||||||
|
if(it1->getType() != it2->getType()) return false;
|
||||||
|
if(!it1->isEquivalent(*it2)) return false;
|
||||||
|
++it1;
|
||||||
|
++it2;
|
||||||
|
}
|
||||||
|
return (it1==end1) && (it2==end2);
|
||||||
|
}
|
||||||
|
|
||||||
int STObject::getFieldIndex(SOE_Field field) const
|
int STObject::getFieldIndex(SOE_Field field) const
|
||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ public:
|
|||||||
int getLength() const;
|
int getLength() const;
|
||||||
SerializedTypeID getType() const { return STI_OBJECT; }
|
SerializedTypeID getType() const { return STI_OBJECT; }
|
||||||
STObject* duplicate() const { return new STObject(*this); }
|
STObject* duplicate() const { return new STObject(*this); }
|
||||||
|
virtual bool isEquivalent(const SerializedType& t) const;
|
||||||
|
|
||||||
void add(Serializer& s) const;
|
void add(Serializer& s) const;
|
||||||
std::string getFullText() const;
|
std::string getFullText() const;
|
||||||
|
|||||||
@@ -77,6 +77,16 @@ int SerializedTransaction::getTransaction(Serializer& s, bool include_length) co
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SerializedTransaction::isEquivalent(const SerializedType& t) const
|
||||||
|
{ // Signatures are not compared
|
||||||
|
const SerializedTransaction* v=dynamic_cast<const SerializedTransaction*>(&t);
|
||||||
|
if(!v) return false;
|
||||||
|
if(type != v->type) return false;
|
||||||
|
if(mMiddleTxn != v->mMiddleTxn) return false;
|
||||||
|
if(mInnerTxn != v->mInnerTxn) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
uint256 SerializedTransaction::getSigningHash() const
|
uint256 SerializedTransaction::getSigningHash() const
|
||||||
{
|
{
|
||||||
Serializer s;
|
Serializer s;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public:
|
|||||||
std::string getFullText() const;
|
std::string getFullText() const;
|
||||||
std::string getText() const;
|
std::string getText() const;
|
||||||
void add(Serializer& s) const { getTransaction(s, true); }
|
void add(Serializer& s) const { getTransaction(s, true); }
|
||||||
|
virtual bool isEquivalent(const SerializedType& t) const;
|
||||||
|
|
||||||
// outer transaction functions / signature functions
|
// outer transaction functions / signature functions
|
||||||
std::vector<unsigned char> getSignature() const;
|
std::vector<unsigned char> getSignature() const;
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ std::string STUInt8::getText() const
|
|||||||
return boost::lexical_cast<std::string>(value);
|
return boost::lexical_cast<std::string>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool STUInt8::isEquivalent(const SerializedType& t) const
|
||||||
|
{
|
||||||
|
const STUInt8* v=dynamic_cast<const STUInt8*>(&t);
|
||||||
|
return v && (value==v->value);
|
||||||
|
}
|
||||||
|
|
||||||
STUInt16* STUInt16::construct(SerializerIterator& u, const char *name)
|
STUInt16* STUInt16::construct(SerializerIterator& u, const char *name)
|
||||||
{
|
{
|
||||||
return new STUInt16(name, u.get16());
|
return new STUInt16(name, u.get16());
|
||||||
@@ -41,8 +47,14 @@ std::string STUInt16::getText() const
|
|||||||
return boost::lexical_cast<std::string>(value);
|
return boost::lexical_cast<std::string>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
STUInt32* STUInt32::construct(SerializerIterator& u, const char *name)
|
bool STUInt16::isEquivalent(const SerializedType& t) const
|
||||||
{
|
{
|
||||||
|
const STUInt16* v=dynamic_cast<const STUInt16*>(&t);
|
||||||
|
return v && (value==v->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
STUInt32* STUInt32::construct(SerializerIterator& u, const char *name)
|
||||||
|
{
|
||||||
return new STUInt32(name, u.get32());
|
return new STUInt32(name, u.get32());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +63,12 @@ std::string STUInt32::getText() const
|
|||||||
return boost::lexical_cast<std::string>(value);
|
return boost::lexical_cast<std::string>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool STUInt32::isEquivalent(const SerializedType& t) const
|
||||||
|
{
|
||||||
|
const STUInt32* v=dynamic_cast<const STUInt32*>(&t);
|
||||||
|
return v && (value==v->value);
|
||||||
|
}
|
||||||
|
|
||||||
STUInt64* STUInt64::construct(SerializerIterator& u, const char *name)
|
STUInt64* STUInt64::construct(SerializerIterator& u, const char *name)
|
||||||
{
|
{
|
||||||
return new STUInt64(name, u.get64());
|
return new STUInt64(name, u.get64());
|
||||||
@@ -61,6 +79,12 @@ std::string STUInt64::getText() const
|
|||||||
return boost::lexical_cast<std::string>(value);
|
return boost::lexical_cast<std::string>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool STUInt64::isEquivalent(const SerializedType& t) const
|
||||||
|
{
|
||||||
|
const STUInt64* v=dynamic_cast<const STUInt64*>(&t);
|
||||||
|
return v && (value==v->value);
|
||||||
|
}
|
||||||
|
|
||||||
STHash128* STHash128::construct(SerializerIterator& u, const char *name)
|
STHash128* STHash128::construct(SerializerIterator& u, const char *name)
|
||||||
{
|
{
|
||||||
return new STHash128(name, u.get128());
|
return new STHash128(name, u.get128());
|
||||||
@@ -71,6 +95,12 @@ std::string STHash128::getText() const
|
|||||||
return value.GetHex();
|
return value.GetHex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool STHash128::isEquivalent(const SerializedType& t) const
|
||||||
|
{
|
||||||
|
const STHash128* v=dynamic_cast<const STHash128*>(&t);
|
||||||
|
return v && (value==v->value);
|
||||||
|
}
|
||||||
|
|
||||||
STHash160* STHash160::construct(SerializerIterator& u, const char *name)
|
STHash160* STHash160::construct(SerializerIterator& u, const char *name)
|
||||||
{
|
{
|
||||||
return new STHash160(name, u.get160());
|
return new STHash160(name, u.get160());
|
||||||
@@ -81,6 +111,12 @@ std::string STHash160::getText() const
|
|||||||
return value.GetHex();
|
return value.GetHex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool STHash160::isEquivalent(const SerializedType& t) const
|
||||||
|
{
|
||||||
|
const STHash160* v=dynamic_cast<const STHash160*>(&t);
|
||||||
|
return v && (value==v->value);
|
||||||
|
}
|
||||||
|
|
||||||
STHash256* STHash256::construct(SerializerIterator& u, const char *name)
|
STHash256* STHash256::construct(SerializerIterator& u, const char *name)
|
||||||
{
|
{
|
||||||
return new STHash256(name, u.get256());
|
return new STHash256(name, u.get256());
|
||||||
@@ -91,6 +127,12 @@ std::string STHash256::getText() const
|
|||||||
return value.GetHex();
|
return value.GetHex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool STHash256::isEquivalent(const SerializedType& t) const
|
||||||
|
{
|
||||||
|
const STHash256* v=dynamic_cast<const STHash256*>(&t);
|
||||||
|
return v && (value==v->value);
|
||||||
|
}
|
||||||
|
|
||||||
static std::string hex(const std::vector<unsigned char>& value)
|
static std::string hex(const std::vector<unsigned char>& value)
|
||||||
{
|
{
|
||||||
int dlen=value.size(), i=0;
|
int dlen=value.size(), i=0;
|
||||||
@@ -115,6 +157,12 @@ int STVariableLength::getLength() const
|
|||||||
return Serializer::encodeLengthLength(value.size()) + value.size();
|
return Serializer::encodeLengthLength(value.size()) + value.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool STVariableLength::isEquivalent(const SerializedType& t) const
|
||||||
|
{
|
||||||
|
const STVariableLength* v=dynamic_cast<const STVariableLength*>(&t);
|
||||||
|
return v && (value==v->value);
|
||||||
|
}
|
||||||
|
|
||||||
std::string STAccount::getText() const
|
std::string STAccount::getText() const
|
||||||
{
|
{
|
||||||
uint160 u;
|
uint160 u;
|
||||||
@@ -177,4 +225,8 @@ int STTaggedList::getLength() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool STTaggedList::isEquivalent(const SerializedType& t) const
|
||||||
|
{
|
||||||
|
const STTaggedList* v=dynamic_cast<const STTaggedList*>(&t);
|
||||||
|
return v && (value==v->value);
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,6 +46,13 @@ public:
|
|||||||
|
|
||||||
SerializedType* new_clone(const SerializedType& s) { return s.duplicate(); }
|
SerializedType* new_clone(const SerializedType& s) { return s.duplicate(); }
|
||||||
void delete_clone(const SerializedType* s) { boost::checked_delete(s); }
|
void delete_clone(const SerializedType* s) { boost::checked_delete(s); }
|
||||||
|
|
||||||
|
virtual bool isEquivalent(const SerializedType& t) const { return true; }
|
||||||
|
|
||||||
|
bool operator==(const SerializedType& t) const
|
||||||
|
{ return (getType()==t.getType()) && isEquivalent(t); }
|
||||||
|
bool operator!=(const SerializedType& t) const
|
||||||
|
{ return (getType()!=t.getType()) || !isEquivalent(t); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class STUInt8 : public SerializedType
|
class STUInt8 : public SerializedType
|
||||||
@@ -70,6 +77,7 @@ public:
|
|||||||
|
|
||||||
operator unsigned char() const { return value; }
|
operator unsigned char() const { return value; }
|
||||||
STUInt8& operator=(unsigned char v) { value=v; return *this; }
|
STUInt8& operator=(unsigned char v) { value=v; return *this; }
|
||||||
|
virtual bool isEquivalent(const SerializedType& t) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class STUInt16 : public SerializedType
|
class STUInt16 : public SerializedType
|
||||||
@@ -94,6 +102,7 @@ public:
|
|||||||
|
|
||||||
operator uint16() const { return value; }
|
operator uint16() const { return value; }
|
||||||
STUInt16& operator=(uint16 v) { value=v; return *this; }
|
STUInt16& operator=(uint16 v) { value=v; return *this; }
|
||||||
|
virtual bool isEquivalent(const SerializedType& t) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class STUInt32 : public SerializedType
|
class STUInt32 : public SerializedType
|
||||||
@@ -118,6 +127,7 @@ public:
|
|||||||
|
|
||||||
operator uint32() const { return value; }
|
operator uint32() const { return value; }
|
||||||
STUInt32& operator=(uint32 v) { value=v; return *this; }
|
STUInt32& operator=(uint32 v) { value=v; return *this; }
|
||||||
|
virtual bool isEquivalent(const SerializedType& t) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class STUInt64 : public SerializedType
|
class STUInt64 : public SerializedType
|
||||||
@@ -142,6 +152,7 @@ public:
|
|||||||
|
|
||||||
operator uint64() const { return value; }
|
operator uint64() const { return value; }
|
||||||
STUInt64& operator=(uint64 v) { value=v; return *this; }
|
STUInt64& operator=(uint64 v) { value=v; return *this; }
|
||||||
|
virtual bool isEquivalent(const SerializedType& t) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class STHash128 : public SerializedType
|
class STHash128 : public SerializedType
|
||||||
@@ -167,6 +178,7 @@ public:
|
|||||||
|
|
||||||
operator uint128() const { return value; }
|
operator uint128() const { return value; }
|
||||||
STHash128& operator=(const uint128& v) { value=v; return *this; }
|
STHash128& operator=(const uint128& v) { value=v; return *this; }
|
||||||
|
virtual bool isEquivalent(const SerializedType& t) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class STHash160 : public SerializedType
|
class STHash160 : public SerializedType
|
||||||
@@ -192,6 +204,7 @@ public:
|
|||||||
|
|
||||||
operator uint160() const { return value; }
|
operator uint160() const { return value; }
|
||||||
STHash160& operator=(const uint160& v) { value=v; return *this; }
|
STHash160& operator=(const uint160& v) { value=v; return *this; }
|
||||||
|
virtual bool isEquivalent(const SerializedType& t) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class STHash256 : public SerializedType
|
class STHash256 : public SerializedType
|
||||||
@@ -217,6 +230,7 @@ public:
|
|||||||
|
|
||||||
operator uint256() const { return value; }
|
operator uint256() const { return value; }
|
||||||
STHash256& operator=(const uint256& v) { value=v; return *this; }
|
STHash256& operator=(const uint256& v) { value=v; return *this; }
|
||||||
|
virtual bool isEquivalent(const SerializedType& t) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class STVariableLength : public SerializedType
|
class STVariableLength : public SerializedType
|
||||||
@@ -245,6 +259,7 @@ public:
|
|||||||
|
|
||||||
operator std::vector<unsigned char>() const { return value; }
|
operator std::vector<unsigned char>() const { return value; }
|
||||||
STVariableLength& operator=(const std::vector<unsigned char>& v) { value=v; return *this; }
|
STVariableLength& operator=(const std::vector<unsigned char>& v) { value=v; return *this; }
|
||||||
|
virtual bool isEquivalent(const SerializedType& t) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class STAccount : public STVariableLength
|
class STAccount : public STVariableLength
|
||||||
@@ -299,6 +314,7 @@ public:
|
|||||||
|
|
||||||
operator std::vector<TaggedListItem>() const { return value; }
|
operator std::vector<TaggedListItem>() const { return value; }
|
||||||
STTaggedList& operator=(const std::vector<TaggedListItem>& v) { value=v; return *this; }
|
STTaggedList& operator=(const std::vector<TaggedListItem>& v) { value=v; return *this; }
|
||||||
|
virtual bool isEquivalent(const SerializedType& t) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user