Make accounts there own type

so we can add new functionality  and so they can display properly.
Cleanups and missing helper function.
This commit is contained in:
JoelKatz
2012-03-27 15:51:14 -07:00
parent cbddb42e43
commit cb28fd52a3
5 changed files with 113 additions and 20 deletions

View File

@@ -4,6 +4,7 @@
#include "SerializedTypes.h"
#include "SerializedObject.h"
#include "TransactionFormats.h"
#include "NewcoinAddress.h"
std::string SerializedType::getFullText() const
{
@@ -104,6 +105,44 @@ int STVariableLength::getLength() const
return Serializer::encodeLengthLength(value.size()) + value.size();
}
std::string STAccount::getText() const
{
uint160 u;
NewcoinAddress a;
if(!getValueH160(u)) return STVariableLength::getText();
a.setAccountID(u);
return a.humanAccountPublic();
}
STAccount* STAccount::construct(SerializerIterator& u, const char *name)
{
STAccount *ret=new STAccount(u.getVL());
if(!ret->isValueH160())
{
delete ret;
throw(std::runtime_error("invalid account in transaction"));
}
return ret;
}
bool STAccount::isValueH160() const
{
return peekValue().size() == (160/8);
}
void STAccount::setValueH160(const uint160& v)
{
peekValue().empty();
peekValue().insert(peekValue().end(), v.begin(), v.end());
}
bool STAccount::getValueH160(uint160& v) const
{
if(!isValueH160()) return false;
memcpy(v.begin(), &(peekValue().front()), 32);
return true;
}
std::string STTaggedList::getText() const
{
std::string ret;
@@ -128,3 +167,4 @@ int STTaggedList::getLength() const
return ret;
}