From 09e4f6a4fe925568cbf4ee8f438c7d443988333f Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 16 Apr 2013 11:53:50 -0700 Subject: [PATCH] Merge fixes. --- src/cpp/ripple/AmountRound.cpp | 8 ++------ src/cpp/ripple/OfferCreateTransactor.cpp | 6 ++++++ src/cpp/ripple/Pathfinder.cpp | 1 + src/cpp/ripple/PaymentTransactor.cpp | 6 ++++++ src/cpp/ripple/RippleCalc.cpp | 2 +- src/cpp/ripple/TransactionErr.cpp | 1 + src/cpp/ripple/TransactionErr.h | 1 + src/cpp/ripple/TrustSetTransactor.cpp | 6 +++++- 8 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/cpp/ripple/AmountRound.cpp b/src/cpp/ripple/AmountRound.cpp index c278b40e00..3b77d26b8e 100644 --- a/src/cpp/ripple/AmountRound.cpp +++ b/src/cpp/ripple/AmountRound.cpp @@ -231,10 +231,8 @@ STAmount STAmount::mulRound(const STAmount& v1, const STAmount& v2, if ((BN_add_word64(&v, value1) != 1) || (BN_mul_word64(&v, value2) != 1)) throw std::runtime_error("internal bn error"); - if (resultNegative != roundUp) + if (resultNegative != roundUp) // rounding down is automatic when we divide BN_add_word64(&v, tenTo14m1); - else - BN_sub_word64(&v, tenTo14m1); if (BN_div_word64(&v, tenTo14) == ((uint64) -1)) throw std::runtime_error("internal bn error"); @@ -279,10 +277,8 @@ STAmount STAmount::divRound(const STAmount& num, const STAmount& den, if ((BN_add_word64(&v, numVal) != 1) || (BN_mul_word64(&v, tenTo17) != 1)) throw std::runtime_error("internal bn error"); - if (resultNegative != roundUp) + if (resultNegative != roundUp) // Rounding down is automatic when we divide BN_add_word64(&v, denVal - 1); - else - BN_sub_word64(&v, denVal - 1); if (BN_div_word64(&v, denVal) == ((uint64) -1)) throw std::runtime_error("internal bn error"); diff --git a/src/cpp/ripple/OfferCreateTransactor.cpp b/src/cpp/ripple/OfferCreateTransactor.cpp index 0743b36380..1c3cfe22c6 100644 --- a/src/cpp/ripple/OfferCreateTransactor.cpp +++ b/src/cpp/ripple/OfferCreateTransactor.cpp @@ -436,6 +436,12 @@ TER OfferCreateTransactor::doApply() terResult = temREDUNDANT; } + else if (CURRENCY_BAD == uPaysCurrency || CURRENCY_BAD == uGetsCurrency) + { + cLog(lsWARNING) << "OfferCreate: Malformed offer: Bad currency."; + + teResult = temBAD_CURRENCY; + } else if (saTakerPays.isNative() != !uPaysIssuerID || saTakerGets.isNative() != !uGetsIssuerID) { cLog(lsWARNING) << "OfferCreate: Malformed offer: bad issuer"; diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index 6cf6e00084..65490357a6 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -153,6 +153,7 @@ Pathfinder::Pathfinder(Ledger::ref ledger, if (((mSrcAccountID == mDstAccountID) && (mSrcCurrencyID == mDstAmount.getCurrency())) || mDstAmount.isZero()) { // no need to send to same account with same currency, must send non-zero bValid = false; + mLedger.reset(); return; } bValid = true; diff --git a/src/cpp/ripple/PaymentTransactor.cpp b/src/cpp/ripple/PaymentTransactor.cpp index 3a5f12a504..65c4aedf37 100644 --- a/src/cpp/ripple/PaymentTransactor.cpp +++ b/src/cpp/ripple/PaymentTransactor.cpp @@ -55,6 +55,12 @@ TER PaymentTransactor::doApply() return temBAD_AMOUNT; } + else if (CURRENCY_BAD == uSrcCurrency || CURRENCY_BAD == uDstCurrency) + { + cLog(lsINFO) << "Payment: Malformed transaction: Bad currency."; + + return temBAD_CURRENCY; + } else if (mTxnAccountID == uDstAccountID && uSrcCurrency == uDstCurrency && !bPaths) { cLog(lsINFO) << boost::str(boost::format("Payment: Malformed transaction: Redundant transaction: src=%s, dst=%s, src_cur=%s, dst_cur=%s") diff --git a/src/cpp/ripple/RippleCalc.cpp b/src/cpp/ripple/RippleCalc.cpp index 0f8957fc1c..3cce7bbde8 100644 --- a/src/cpp/ripple/RippleCalc.cpp +++ b/src/cpp/ripple/RippleCalc.cpp @@ -1440,7 +1440,7 @@ TER RippleCalc::calcNodeDeliverFwd( STAmount saOutFunded = std::min(saOfferFunds, saTakerGets); // Offer maximum out - If there are no out fees. STAmount saInFunded = STAmount::mulRound(saOutFunded, saOfrRate, saTakerPays, true); // Offer maximum in - Limited by by payout. - STAmount saInTotal = STAmount::mulRound(saInFunded, saInTransRate, true); // Offer maximum in with fees. + STAmount saInTotal = STAmount::mulRound(saInFunded, saInFeeRate, true); // Offer maximum in with fees. STAmount saInSum = std::min(saInTotal, saInReq-saInAct-saInFees); // In limited by remaining. STAmount saInPassAct = STAmount::divRound(saInSum, saInFeeRate, true); // In without fees. STAmount saOutPassMax = STAmount::divRound(saInPassAct, saOfrRate, saTakerGets, true); // Out limited by in remaining. diff --git a/src/cpp/ripple/TransactionErr.cpp b/src/cpp/ripple/TransactionErr.cpp index 1709cfc368..04fcb1d2eb 100644 --- a/src/cpp/ripple/TransactionErr.cpp +++ b/src/cpp/ripple/TransactionErr.cpp @@ -51,6 +51,7 @@ bool transResultInfo(TER terCode, std::string& strToken, std::string& strHuman) { temMALFORMED, "temMALFORMED", "Malformed transaction." }, { temBAD_AMOUNT, "temBAD_AMOUNT", "Can only send positive amounts." }, { temBAD_AUTH_MASTER, "temBAD_AUTH_MASTER", "Auth for unclaimed account needs correct master key." }, + { temBAD_CURRENCY, "temBAD_CURRENCY", "Malformed: Bad currency." }, { temBAD_FEE, "temBAD_FEE", "Invalid fee, negative or not XRP." }, { temBAD_EXPIRATION, "temBAD_EXPIRATION", "Malformed: Bad expiration." }, { temBAD_ISSUER, "temBAD_ISSUER", "Malformed: Bad issuer." }, diff --git a/src/cpp/ripple/TransactionErr.h b/src/cpp/ripple/TransactionErr.h index 186aa3c145..7df06c8f71 100644 --- a/src/cpp/ripple/TransactionErr.h +++ b/src/cpp/ripple/TransactionErr.h @@ -31,6 +31,7 @@ enum TER // aka TransactionEngineResult temMALFORMED = -299, temBAD_AMOUNT, temBAD_AUTH_MASTER, + temBAD_CURRENCY, temBAD_FEE, temBAD_EXPIRATION, temBAD_ISSUER, diff --git a/src/cpp/ripple/TrustSetTransactor.cpp b/src/cpp/ripple/TrustSetTransactor.cpp index a8f9f7a487..1e59430108 100644 --- a/src/cpp/ripple/TrustSetTransactor.cpp +++ b/src/cpp/ripple/TrustSetTransactor.cpp @@ -248,7 +248,7 @@ TER TrustSetTransactor::doApply() if (uFlagsIn != uFlagsOut) sleRippleState->setFieldU32(sfFlags, uFlagsOut); - if (bDefault) + if (bDefault || CURRENCY_BAD == uCurrencyID) { // Can delete. @@ -285,6 +285,10 @@ TER TrustSetTransactor::doApply() // Another transaction could create the account and then this transaction would succeed. terResult = tecNO_LINE_INSUF_RESERVE; } + else if (CURRENCY_BAD == uCurrencyID) + { + terResult = temBAD_CURRENCY; + } else { STAmount saBalance = STAmount(uCurrencyID, ACCOUNT_ONE); // Zero balance in currency.