diff --git a/src/SerializedObject.cpp b/src/SerializedObject.cpp index e27ce55d28..c09e67904d 100644 --- a/src/SerializedObject.cpp +++ b/src/SerializedObject.cpp @@ -167,6 +167,22 @@ std::string STObject::getText() const return ret; } +bool STObject::isEquivalent(const SerializedType& t) const +{ + const STObject* v=dynamic_cast(&t); + if(!v) return false; + boost::ptr_vector::const_iterator it1=mData.begin(), end1=mData.end(); + boost::ptr_vector::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 i=0; diff --git a/src/SerializedObject.h b/src/SerializedObject.h index f1e53ad141..16dc182858 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -58,6 +58,7 @@ public: int getLength() const; SerializedTypeID getType() const { return STI_OBJECT; } STObject* duplicate() const { return new STObject(*this); } + virtual bool isEquivalent(const SerializedType& t) const; void add(Serializer& s) const; std::string getFullText() const; diff --git a/src/SerializedTransaction.cpp b/src/SerializedTransaction.cpp index 8192a8e71b..88dd761c32 100644 --- a/src/SerializedTransaction.cpp +++ b/src/SerializedTransaction.cpp @@ -77,6 +77,16 @@ int SerializedTransaction::getTransaction(Serializer& s, bool include_length) co return l; } +bool SerializedTransaction::isEquivalent(const SerializedType& t) const +{ // Signatures are not compared + const SerializedTransaction* v=dynamic_cast(&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 { Serializer s; diff --git a/src/SerializedTransaction.h b/src/SerializedTransaction.h index 644634d8f6..3f64589549 100644 --- a/src/SerializedTransaction.h +++ b/src/SerializedTransaction.h @@ -31,6 +31,7 @@ public: std::string getFullText() const; std::string getText() const; void add(Serializer& s) const { getTransaction(s, true); } + virtual bool isEquivalent(const SerializedType& t) const; // outer transaction functions / signature functions std::vector getSignature() const; diff --git a/src/SerializedTypes.cpp b/src/SerializedTypes.cpp index 80d63de302..a7527b332e 100644 --- a/src/SerializedTypes.cpp +++ b/src/SerializedTypes.cpp @@ -31,6 +31,12 @@ std::string STUInt8::getText() const return boost::lexical_cast(value); } +bool STUInt8::isEquivalent(const SerializedType& t) const +{ + const STUInt8* v=dynamic_cast(&t); + return v && (value==v->value); +} + STUInt16* STUInt16::construct(SerializerIterator& u, const char *name) { return new STUInt16(name, u.get16()); @@ -41,8 +47,14 @@ std::string STUInt16::getText() const return boost::lexical_cast(value); } -STUInt32* STUInt32::construct(SerializerIterator& u, const char *name) +bool STUInt16::isEquivalent(const SerializedType& t) const { + const STUInt16* v=dynamic_cast(&t); + return v && (value==v->value); +} + +STUInt32* STUInt32::construct(SerializerIterator& u, const char *name) + { return new STUInt32(name, u.get32()); } @@ -51,6 +63,12 @@ std::string STUInt32::getText() const return boost::lexical_cast(value); } +bool STUInt32::isEquivalent(const SerializedType& t) const +{ + const STUInt32* v=dynamic_cast(&t); + return v && (value==v->value); +} + STUInt64* STUInt64::construct(SerializerIterator& u, const char *name) { return new STUInt64(name, u.get64()); @@ -61,6 +79,12 @@ std::string STUInt64::getText() const return boost::lexical_cast(value); } +bool STUInt64::isEquivalent(const SerializedType& t) const +{ + const STUInt64* v=dynamic_cast(&t); + return v && (value==v->value); +} + STHash128* STHash128::construct(SerializerIterator& u, const char *name) { return new STHash128(name, u.get128()); @@ -71,6 +95,12 @@ std::string STHash128::getText() const return value.GetHex(); } +bool STHash128::isEquivalent(const SerializedType& t) const +{ + const STHash128* v=dynamic_cast(&t); + return v && (value==v->value); +} + STHash160* STHash160::construct(SerializerIterator& u, const char *name) { return new STHash160(name, u.get160()); @@ -81,6 +111,12 @@ std::string STHash160::getText() const return value.GetHex(); } +bool STHash160::isEquivalent(const SerializedType& t) const +{ + const STHash160* v=dynamic_cast(&t); + return v && (value==v->value); +} + STHash256* STHash256::construct(SerializerIterator& u, const char *name) { return new STHash256(name, u.get256()); @@ -91,6 +127,12 @@ std::string STHash256::getText() const return value.GetHex(); } +bool STHash256::isEquivalent(const SerializedType& t) const +{ + const STHash256* v=dynamic_cast(&t); + return v && (value==v->value); +} + static std::string hex(const std::vector& value) { int dlen=value.size(), i=0; @@ -115,6 +157,12 @@ int STVariableLength::getLength() const return Serializer::encodeLengthLength(value.size()) + value.size(); } +bool STVariableLength::isEquivalent(const SerializedType& t) const +{ + const STVariableLength* v=dynamic_cast(&t); + return v && (value==v->value); +} + std::string STAccount::getText() const { uint160 u; @@ -177,4 +225,8 @@ int STTaggedList::getLength() const return ret; } - +bool STTaggedList::isEquivalent(const SerializedType& t) const +{ + const STTaggedList* v=dynamic_cast(&t); + return v && (value==v->value); +} diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index 53b1375c68..3c43e1aadd 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -46,6 +46,13 @@ public: SerializedType* new_clone(const SerializedType& s) { return s.duplicate(); } 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 @@ -70,6 +77,7 @@ public: operator unsigned char() const { return value; } STUInt8& operator=(unsigned char v) { value=v; return *this; } + virtual bool isEquivalent(const SerializedType& t) const; }; class STUInt16 : public SerializedType @@ -94,6 +102,7 @@ public: operator uint16() const { return value; } STUInt16& operator=(uint16 v) { value=v; return *this; } + virtual bool isEquivalent(const SerializedType& t) const; }; class STUInt32 : public SerializedType @@ -118,6 +127,7 @@ public: operator uint32() const { return value; } STUInt32& operator=(uint32 v) { value=v; return *this; } + virtual bool isEquivalent(const SerializedType& t) const; }; class STUInt64 : public SerializedType @@ -142,6 +152,7 @@ public: operator uint64() const { return value; } STUInt64& operator=(uint64 v) { value=v; return *this; } + virtual bool isEquivalent(const SerializedType& t) const; }; class STHash128 : public SerializedType @@ -167,6 +178,7 @@ public: operator uint128() const { return value; } STHash128& operator=(const uint128& v) { value=v; return *this; } + virtual bool isEquivalent(const SerializedType& t) const; }; class STHash160 : public SerializedType @@ -192,6 +204,7 @@ public: operator uint160() const { return value; } STHash160& operator=(const uint160& v) { value=v; return *this; } + virtual bool isEquivalent(const SerializedType& t) const; }; class STHash256 : public SerializedType @@ -217,6 +230,7 @@ public: operator uint256() const { return value; } STHash256& operator=(const uint256& v) { value=v; return *this; } + virtual bool isEquivalent(const SerializedType& t) const; }; class STVariableLength : public SerializedType @@ -245,6 +259,7 @@ public: operator std::vector() const { return value; } STVariableLength& operator=(const std::vector& v) { value=v; return *this; } + virtual bool isEquivalent(const SerializedType& t) const; }; class STAccount : public STVariableLength @@ -299,6 +314,7 @@ public: operator std::vector() const { return value; } STTaggedList& operator=(const std::vector& v) { value=v; return *this; } + virtual bool isEquivalent(const SerializedType& t) const; }; #endif