JSON->Account

This commit is contained in:
JoelKatz
2012-10-02 01:01:27 -07:00
parent 4d64ab03b0
commit d9b0d39cf6
3 changed files with 29 additions and 5 deletions

View File

@@ -897,7 +897,7 @@ std::auto_ptr<STObject> STObject::parseJson(const Json::Value& object, SField::r
else if (value.isInt())
data.push_back(new STUInt32(field, range_check_cast<uint32>(value.asInt(), 0, 4294967295)));
else if (value.isUInt())
data.push_back(new STUInt32(field, static_cast<uint32>(value.asUInt(), 0, 4294967295)));
data.push_back(new STUInt32(field, static_cast<uint32>(value.asUInt())));
else
throw std::runtime_error("Incorrect type");
break;
@@ -940,7 +940,7 @@ std::auto_ptr<STObject> STObject::parseJson(const Json::Value& object, SField::r
if (!value.isString())
throw std::runtime_error("Incorrect type");
data.push_back(new STVariableLength(field, strUnHex(value.asString())));
break;
break;
case STI_AMOUNT:
// WRITEME
@@ -950,9 +950,27 @@ std::auto_ptr<STObject> STObject::parseJson(const Json::Value& object, SField::r
case STI_PATHSET:
// WRITEME
break;
case STI_ACCOUNT:
// WRITEME
{
if (!value.isString())
throw std::runtime_error("Incorrect type");
std::string strValue = value.asString();
if (value.size() == 40) // 160-bit hex account value
{
uint160 v;
v.SetHex(strValue);
data.push_back(new STAccount(field, v));
}
else
{ // newcoin addres
NewcoinAddress a;
if (!a.setAccountPublic(strValue))
throw std::runtime_error("Account invalid");
data.push_back(new STAccount(field, a.getAccountID()));
}
}
break;
case STI_OBJECT:
case STI_TRANSACTION:

View File

@@ -231,9 +231,14 @@ bool STVector256::isEquivalent(const SerializedType& t) const
// STAccount
//
STAccount::STAccount(SField::ref n, const uint160& v) : STVariableLength(n)
{
peekValue().insert(peekValue().end(), v.begin(), v.end());
}
bool STAccount::isValueH160() const
{
return peekValue().size() == (160/8);
return peekValue().size() == (160 / 8);
}
void STAccount::setValueH160(const uint160& v)

View File

@@ -496,6 +496,7 @@ public:
STAccount(const std::vector<unsigned char>& v) : STVariableLength(v) { ; }
STAccount(SField::ref n, const std::vector<unsigned char>& v) : STVariableLength(n, v) { ; }
STAccount(SField::ref n, const uint160& v);
STAccount(SField::ref n) : STVariableLength(n) { ; }
STAccount() { ; }
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)