diff --git a/js/amount.js b/js/amount.js index b5c542288e..10c9ffb392 100644 --- a/js/amount.js +++ b/js/amount.js @@ -136,8 +136,8 @@ UInt160.json_rewrite = function (j) { // Return a new UInt160 from j. UInt160.from_json = function (j) { return 'string' === typeof j - ? (new UInt160()).parse_json(j) - : j.clone(); + ? (new UInt160()).parse_json(j) + : j.clone(); }; UInt160.prototype.clone = function() { @@ -238,7 +238,9 @@ Currency.json_rewrite = function(j) { }; Currency.from_json = function (j) { - return (new Currency()).parse_json(j); + return 'string' === typeof j + ? (new Currency()).parse_json(j) + : j.clone(); }; Currency.prototype.clone = function() { diff --git a/js/remote.js b/js/remote.js index 1b0fe5a2d4..9e0b4fedfe 100644 --- a/js/remote.js +++ b/js/remote.js @@ -914,6 +914,17 @@ Transaction.prototype.submit = function () { var self = this; var transaction = this.transaction; + if ('string' !== typeof transaction.Account) + { + this.emit('error', { + 'error' : 'invalidAccount', + 'error_message' : 'Bad account.' + }); + return; + } + + // YYY Might check paths for invalid accounts. + if (undefined === transaction.Fee) { if ('Payment' === transaction.TransactionType && transaction.Flags & Remote.flags.Payment.CreateAccount) { @@ -989,8 +1000,10 @@ Transaction._path_rewrite = function (path) { if ('account' in node) node_new.account = UInt160.json_rewrite(node.account); + if ('issuer' in node) node_new.issuer = UInt160.json_rewrite(node.issuer); + if ('currency' in node) node_new.currency = Currency.json_rewrite(node.currency); diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index f39faa6d8e..7bb4c67057 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -88,17 +88,26 @@ Transaction::pointer NetworkOPs::submitTransaction(const Transaction::pointer& t tpTrans->getSTransaction()->add(s); Transaction::pointer tpTransNew = Transaction::sharedTransaction(s.getData(), true); - assert(tpTransNew); - if(!tpTransNew->getSTransaction()->isEquivalent(*tpTrans->getSTransaction())) + if (!tpTransNew) + { + // Could not construct transaction. + nothing(); + } + else if (tpTransNew->getSTransaction()->isEquivalent(*tpTrans->getSTransaction())) + { + (void) NetworkOPs::processTransaction(tpTransNew); + } + else { cLog(lsFATAL) << "Transaction reconstruction failure"; cLog(lsFATAL) << tpTransNew->getSTransaction()->getJson(0); cLog(lsFATAL) << tpTrans->getSTransaction()->getJson(0); - assert(false); - } - (void) NetworkOPs::processTransaction(tpTransNew); + assert(false); + + tpTransNew = Transaction::pointer(); + } return tpTransNew; } diff --git a/src/SerializedTypes.cpp b/src/SerializedTypes.cpp index d147a3fdfe..61f526eeb0 100644 --- a/src/SerializedTypes.cpp +++ b/src/SerializedTypes.cpp @@ -540,7 +540,6 @@ void STPathSet::add(Serializer& s) const if (!bFirst) { s.add8(STPathElement::typeBoundary); - bFirst = false; } BOOST_FOREACH(const STPathElement& speElement, spPath) @@ -558,6 +557,8 @@ void STPathSet::add(Serializer& s) const if (iType & STPathElement::typeIssuer) s.add160(speElement.getIssuerID()); } + + bFirst = false; } s.add8(STPathElement::typeEnd); } diff --git a/src/WSDoor.cpp b/src/WSDoor.cpp index 91b17e8aaf..5d52859fbe 100644 --- a/src/WSDoor.cpp +++ b/src/WSDoor.cpp @@ -1072,6 +1072,12 @@ void WSConnection::doSubmit(Json::Value& jvResult, const Json::Value& jvRequest) try { tpTrans = mNetwork.submitTransaction(tpTrans); + + if (!tpTrans) { + jvResult["error"] = "invalidTransaction"; + jvResult["error_exception"] = "Unable to sterilize transaction."; + return; + } } catch (std::exception& e) {