From d7d5a0d2b16b2487b7d7e75078af0ef7c81d8f57 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 2 Oct 2012 20:15:51 -0700 Subject: [PATCH] Finish STAmount JSON parser. --- src/Amount.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Amount.cpp b/src/Amount.cpp index ef8f417c7a..b4f6b0ba48 100644 --- a/src/Amount.cpp +++ b/src/Amount.cpp @@ -106,7 +106,7 @@ STAmount::STAmount(SField::ref n, const Json::Value& v) else if (value.isUInt()) mValue = v.asUInt(); else if (value.isString()) - { // FIXME: If it has a '.' we have to process it specially! + { if (mIsNative) { int64 val = lexical_cast_st(value.asString()); @@ -127,8 +127,23 @@ STAmount::STAmount(SField::ref n, const Json::Value& v) if (mIsNative) return; - // parse currency and issuer - // WRITEME + if (!currencyFromString(mCurrency, currency.asString())) + throw std::runtime_error("invalid currency"); + + if (!issuer.isString()) + throw std::runtime_error("invalid issuer"); + + if (issuer.size() == (160/4)) + mIssuer.SetHex(issuer.asString()); + else + { + NewcoinAddress is; + if(!is.setAccountID(issuer.asString())) + throw std::runtime_error("invalid issuer"); + mIssuer = is.getAccountID(); + } + if (mIssuer.isZero()) + throw std::runtime_error("invalid issuer"); canonicalize(); }