From 7e30db94b4a9e37d5910938aeca9245d86edad2b Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sun, 19 Aug 2012 21:36:25 -0700 Subject: [PATCH] Work on ripple paths. --- src/SerializedTypes.cpp | 13 ++++++++++--- src/TransactionEngine.cpp | 27 ++++++++++++++++++--------- src/TransactionEngine.h | 6 +++++- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/SerializedTypes.cpp b/src/SerializedTypes.cpp index cd759e1ee2..6e50c61fdb 100644 --- a/src/SerializedTypes.cpp +++ b/src/SerializedTypes.cpp @@ -5,6 +5,7 @@ #include "SerializedTypes.h" #include "SerializedObject.h" #include "TransactionFormats.h" +#include "Log.h" #include "NewcoinAddress.h" #include "utils.h" @@ -308,7 +309,11 @@ STPathSet* STPathSet::construct(SerializerIterator& s, const char *name) if (iType == STPathElement::typeEnd || iType == STPathElement::typeBoundary) { if (path.empty()) + { + Log(lsINFO) << "STPathSet: Empty path."; + throw std::runtime_error("empty path"); + } paths.push_back(path); path.clear(); @@ -320,13 +325,15 @@ STPathSet* STPathSet::construct(SerializerIterator& s, const char *name) } else if (iType & ~STPathElement::typeValidBits) { + Log(lsINFO) << "STPathSet: Bad path element: " << iType; + throw std::runtime_error("bad path element"); } else { - bool bAccount = !!(iType & STPathElement::typeAccount); - bool bCurrency = !!(iType & STPathElement::typeCurrency); - bool bIssuer = !!(iType & STPathElement::typeIssuer); + const bool bAccount = !!(iType & STPathElement::typeAccount); + const bool bCurrency = !!(iType & STPathElement::typeCurrency); + const bool bIssuer = !!(iType & STPathElement::typeIssuer); uint160 uAccountID; uint160 uCurrency; diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index af7f9a53a2..c322b289de 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -1969,14 +1969,14 @@ bool TransactionEngine::calcNodeOfferRev( if (!saCurOfrFunds) { // Offer is unfunded. - Log(lsINFO) << "calcNodeOffer: encountered unfunded offer"; + Log(lsINFO) << "calcNodeOfferRev: encountered unfunded offer"; // XXX Mark unfunded. } else if (sleCurOfr->getIFieldPresent(sfExpiration) && sleCurOfr->getIFieldU32(sfExpiration) <= mLedger->getParentCloseTimeNC()) { // Offer is expired. - Log(lsINFO) << "calcNodeOffer: encountered expired offer"; + Log(lsINFO) << "calcNodeOfferRev: encountered expired offer"; // XXX Mark unfunded. } @@ -3774,8 +3774,10 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction if (!bNoRippleDirect) { // Direct path. + // XXX Might also make a stamp bridge by default. Log(lsINFO) << "doPayment: Build direct:"; - vpsPaths.push_back(PathState::createPathState( + + PathState::pointer pspDirect = PathState::createPathState( mLedger, vpsPaths.size(), mNodes, @@ -3784,14 +3786,19 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction mTxnAccountID, saDstAmount, saMaxAmount, - bPartialPayment - )); + bPartialPayment); + + if (pspDirect) + vpsPaths.push_back(pspDirect); } + Log(lsINFO) << "doPayment: Paths: " << spsPaths.getPathCount(); + BOOST_FOREACH(const STPath& spPath, spsPaths) { Log(lsINFO) << "doPayment: Build path:"; - vpsPaths.push_back(PathState::createPathState( + + PathState::pointer pspExpanded = PathState::createPathState( mLedger, vpsPaths.size(), mNodes, @@ -3800,8 +3807,10 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction mTxnAccountID, saDstAmount, saMaxAmount, - bPartialPayment - )); + bPartialPayment); + + if (pspExpanded) + vpsPaths.push_back(pspExpanded); } TransactionEngineResult terResult; @@ -3885,7 +3894,7 @@ TransactionEngineResult TransactionEngine::doWalletAdd(const SerializedTransacti if (!naMasterPubKey.accountPublicVerify(Serializer::getSHA512Half(uAuthKeyID.begin(), uAuthKeyID.size()), vucSignature)) { - std::cerr << "WalletAdd: unauthorized: bad signature " << std::endl; + std::cerr << "WalletAdd: unauthorized: bad signature " << std::endl; return tenBAD_ADD_AUTH; } diff --git a/src/TransactionEngine.h b/src/TransactionEngine.h index 5df286d743..ecc1a4a722 100644 --- a/src/TransactionEngine.h +++ b/src/TransactionEngine.h @@ -169,7 +169,11 @@ public: STAmount saSendMax, bool bPartialPayment ) - { return boost::make_shared(lpLedger, iIndex, lesSource, spSourcePath, uReceiverID, uSenderID, saSend, saSendMax, bPartialPayment); }; + { + PathState::pointer pspNew = boost::make_shared(lpLedger, iIndex, lesSource, spSourcePath, uReceiverID, uSenderID, saSend, saSendMax, bPartialPayment); + + return pspNew && pspNew->bValid ? pspNew : PathState::pointer(); + } static bool lessPriority(const PathState::pointer& lhs, const PathState::pointer& rhs); };