From 8c2eda1f93536138c881bb0c15e07ea445e9b1d4 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 28 Sep 2012 14:26:19 -0700 Subject: [PATCH] Fix signature/hash generation. --- src/SerializedObject.cpp | 29 ++++++++++++++++++++++++++--- src/SerializedObject.h | 6 +++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/SerializedObject.cpp b/src/SerializedObject.cpp index 4834a1f3f5..cc6f6f9136 100644 --- a/src/SerializedObject.cpp +++ b/src/SerializedObject.cpp @@ -217,14 +217,18 @@ std::string STObject::getFullText() const return ret; } -void STObject::add(Serializer& s) const +void STObject::add(Serializer& s, bool withSigningFields) const { std::map fields; BOOST_FOREACH(const SerializedType& it, mData) { // pick out the fields and sort them if (it.getSType() != STI_NOTPRESENT) - fields.insert(std::make_pair(it.getFName().fieldCode, &it)); + { + SField::ref fName = it.getFName(); + if (withSigningFields || (fName == sfSignature) || (fName == sfSignatures)) + fields.insert(std::make_pair(it.getFName().fieldCode, &it)); + } } @@ -235,7 +239,10 @@ void STObject::add(Serializer& s) const field->addFieldID(s); field->add(s); - s.addFieldID(STI_OBJECT, 1); + if (dynamic_cast(field) != NULL) + s.addFieldID(STI_ARRAY, 1); + else if (dynamic_cast(field) != NULL) + s.addFieldID(STI_OBJECT, 1); } } @@ -272,6 +279,22 @@ bool STObject::isEquivalent(const SerializedType& t) const return (it1 == end1) && (it2 == end2); } +uint256 getHash(uint32 prefix) cosnt +{ + Serializer s; + s.add32(prefix); + add(s, true); + return s.getSHA512Half(); +} + +uint256 getSigningHash(uint32 prefix) cosnt +{ + Serializer s; + s.add32(prefix); + add(s, false); + return s.getSHA512Half(); +} + int STObject::getFieldIndex(SField::ref field) const { int i = 0; diff --git a/src/SerializedObject.h b/src/SerializedObject.h index c74402f15c..adb054586b 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -54,7 +54,8 @@ public: virtual SerializedTypeID getSType() const { return STI_OBJECT; } virtual bool isEquivalent(const SerializedType& t) const; - virtual void add(Serializer& s) const; // just inner elements + virtual void add(Serializer& s) const { add(s, true); } // just inner elements + void add(Serializer& s, int withSignature) const; Serializer getSerializer() const { Serializer s; add(s); return s; } std::string getFullText() const; std::string getText() const; @@ -72,6 +73,9 @@ public: bool clearFlag(uint32); uint32 getFlags() const; + uint256 getHash(uint32 prefix) const; + uint256 getSigningHash(uint32 prefix) const; + const SerializedType& peekAtIndex(int offset) const { return mData[offset]; } SerializedType& getIndex(int offset) { return mData[offset]; } const SerializedType* peekAtPIndex(int offset) const { return &(mData[offset]); }