From 931bd332df3116a9ad7191ce5cc678ebf28746cf Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sun, 20 Jan 2013 20:08:24 -0800 Subject: [PATCH] Be stricter with payment options. --- src/cpp/ripple/PaymentTransactor.cpp | 29 ++++++++++++++++++++++++++-- src/cpp/ripple/TransactionErr.cpp | 6 +++++- src/cpp/ripple/TransactionErr.h | 6 +++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/cpp/ripple/PaymentTransactor.cpp b/src/cpp/ripple/PaymentTransactor.cpp index 6019d07169..a4c16fb069 100644 --- a/src/cpp/ripple/PaymentTransactor.cpp +++ b/src/cpp/ripple/PaymentTransactor.cpp @@ -25,6 +25,7 @@ TER PaymentTransactor::doApply() : STAmount(saDstAmount.getCurrency(), mTxnAccountID, saDstAmount.getMantissa(), saDstAmount.getExponent(), saDstAmount.isNegative()); const uint160 uSrcCurrency = saMaxAmount.getCurrency(); const uint160 uDstCurrency = saDstAmount.getCurrency(); + const bool bXRPDirect = uSrcCurrency.isZero() && uDstCurrency.isZero(); cLog(lsINFO) << boost::str(boost::format("Payment> saMaxAmount=%s saDstAmount=%s") % saMaxAmount.getFullText() @@ -70,11 +71,35 @@ TER PaymentTransactor::doApply() return temREDUNDANT_SEND_MAX; } - else if (bMax && (saDstAmount.isNative() && saMaxAmount.isNative())) + else if (bXRPDirect && bMax) { cLog(lsINFO) << "Payment: Malformed transaction: SendMax not allowed for XRP."; - return temBAD_SEND_MAX_XRP; + return temBAD_SEND_XRP_MAX; + } + else if (bXRPDirect && bPaths) + { + cLog(lsINFO) << "Payment: Malformed transaction: Paths specfied for XRP to XRP."; + + return temBAD_SEND_XRP_PATHS; + } + else if (bXRPDirect && bPartialPayment) + { + cLog(lsINFO) << "Payment: Malformed transaction: Partial payment specfied for XRP to XRP."; + + return temBAD_SEND_XRP_PARTIAL; + } + else if (bXRPDirect && bLimitQuality) + { + cLog(lsINFO) << "Payment: Malformed transaction: Limit quality specfied for XRP to XRP."; + + return temBAD_SEND_XRP_LIMIT; + } + else if (bXRPDirect && bNoRippleDirect) + { + cLog(lsINFO) << "Payment: Malformed transaction: No ripple direct specfied for XRP to XRP."; + + return temBAD_SEND_XRP_NO_DIRECT; } SLE::pointer sleDst = mEngine->entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(uDstAccountID)); diff --git a/src/cpp/ripple/TransactionErr.cpp b/src/cpp/ripple/TransactionErr.cpp index 201393ae86..c6d112afd7 100644 --- a/src/cpp/ripple/TransactionErr.cpp +++ b/src/cpp/ripple/TransactionErr.cpp @@ -59,7 +59,11 @@ bool transResultInfo(TER terCode, std::string& strToken, std::string& strHuman) { temBAD_SRC_ACCOUNT, "temBAD_SRC_ACCOUNT", "Malformed: Bad source account." }, { temBAD_TRANSFER_RATE, "temBAD_TRANSFER_RATE", "Malformed: Transfer rate must be >= 1.0" }, { temBAD_SEQUENCE, "temBAD_SEQUENCE", "Malformed: Sequence is not in the past." }, - { temBAD_SEND_MAX_XRP, "temBAD_SEND_MAX_XRP", "Malformed: Send max is not allowed for XRP." }, + { temBAD_SEND_XRP_LIMIT, "temBAD_SEND_XRP_LIMIT", "Malformed: Limit quality is not allowed for XRP to XRP." }, + { temBAD_SEND_XRP_MAX, "temBAD_SEND_XRP_MAX", "Malformed: Send max is not allowed for XRP." }, + { temBAD_SEND_XRP_NO_DIRECT, "temBAD_SEND_XRP_NO_DIRECT", "Malformed: No Ripple direct is not allowed for XRP to XRP." }, + { temBAD_SEND_XRP_PARTIAL, "temBAD_SEND_XRP_PARTIAL", "Malformed: Partial payment is not allowed for XRP to XRP." }, + { temBAD_SEND_XRP_PATHS, "temBAD_SEND_XRP_PATHS", "Malformed: Paths are not allowed for XRP to XRP." }, { temDST_IS_SRC, "temDST_IS_SRC", "Destination may not be source." }, { temDST_NEEDED, "temDST_NEEDED", "Destination not specified." }, { temDST_TAG_NEEDED, "temDST_TAG_NEEDED", "Destination tag required." }, diff --git a/src/cpp/ripple/TransactionErr.h b/src/cpp/ripple/TransactionErr.h index 0230be8480..2eec0554ce 100644 --- a/src/cpp/ripple/TransactionErr.h +++ b/src/cpp/ripple/TransactionErr.h @@ -39,7 +39,11 @@ enum TER // aka TransactionEngineResult temBAD_PATH_LOOP, temBAD_PUBLISH, temBAD_TRANSFER_RATE, - temBAD_SEND_MAX_XRP, + temBAD_SEND_XRP_LIMIT, + temBAD_SEND_XRP_MAX, + temBAD_SEND_XRP_NO_DIRECT, + temBAD_SEND_XRP_PARTIAL, + temBAD_SEND_XRP_PATHS, temBAD_SIGNATURE, temBAD_SRC_ACCOUNT, temBAD_SEQUENCE,