Fix signature/hash generation.

This commit is contained in:
JoelKatz
2012-09-28 14:26:19 -07:00
parent b88d6486a6
commit 8c2eda1f93
2 changed files with 31 additions and 4 deletions

View File

@@ -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<int, const SerializedType*> 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<STArray>(field) != NULL)
s.addFieldID(STI_ARRAY, 1);
else if (dynamic_cast<STObject>(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;

View File

@@ -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]); }