Merge fixes.

This commit is contained in:
JoelKatz
2013-04-16 11:53:50 -07:00
parent 644d97a332
commit 09e4f6a4fe
8 changed files with 23 additions and 8 deletions

View File

@@ -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");

View File

@@ -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";

View File

@@ -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;

View File

@@ -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")

View File

@@ -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.

View File

@@ -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." },

View File

@@ -31,6 +31,7 @@ enum TER // aka TransactionEngineResult
temMALFORMED = -299,
temBAD_AMOUNT,
temBAD_AUTH_MASTER,
temBAD_CURRENCY,
temBAD_FEE,
temBAD_EXPIRATION,
temBAD_ISSUER,

View File

@@ -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.