mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
DeliverMin enable switch and precheck greater than dest amount
This commit is contained in:
committed by
Nik Bougalis
parent
761f218c0a
commit
7c2478480d
@@ -192,13 +192,6 @@
|
||||
#define RIPPLE_USE_OPENSSL 0
|
||||
#endif
|
||||
|
||||
/** Config: RIPPLE_ENABLE_DELIVERMIN
|
||||
Enables processing of delivermin in transactions
|
||||
*/
|
||||
#ifndef RIPPLE_ENABLE_DELIVERMIN
|
||||
#define RIPPLE_ENABLE_DELIVERMIN 0
|
||||
#endif
|
||||
|
||||
// Enables the experimental OpenLedger
|
||||
#ifndef RIPPLE_OPEN_LEDGER
|
||||
#define RIPPLE_OPEN_LEDGER 0
|
||||
|
||||
@@ -28,6 +28,16 @@ namespace ripple {
|
||||
|
||||
// See https://ripple.com/wiki/Transaction_Format#Payment_.280.29
|
||||
|
||||
// Mon Aug 3 11:00:00am PDT
|
||||
static std::uint32_t const deliverMinTime = 491940000;
|
||||
|
||||
bool
|
||||
allowDeliverMin (ApplyView const& view)
|
||||
{
|
||||
return view.info().parentCloseTime > deliverMinTime ||
|
||||
(view.flags() & tapENABLE_TESTING);
|
||||
}
|
||||
|
||||
TER
|
||||
Payment::preCheck ()
|
||||
{
|
||||
@@ -45,12 +55,6 @@ Payment::preCheck ()
|
||||
bool const defaultPathsAllowed = !(uTxFlags & tfNoRippleDirect);
|
||||
bool const bPaths = mTxn.isFieldPresent (sfPaths);
|
||||
bool const bMax = mTxn.isFieldPresent (sfSendMax);
|
||||
bool const deliverMin =
|
||||
#if RIPPLE_ENABLE_DELIVERMIN
|
||||
#else
|
||||
(view().flags() & tapENABLE_TESTING) &&
|
||||
#endif
|
||||
mTxn.isFieldPresent(sfDeliverMin);
|
||||
|
||||
STAmount const saDstAmount (mTxn.getFieldAmount (sfAmount));
|
||||
|
||||
@@ -145,12 +149,11 @@ Payment::preCheck ()
|
||||
"No ripple direct specified for XRP to XRP.";
|
||||
return temBAD_SEND_XRP_NO_DIRECT;
|
||||
}
|
||||
if (deliverMin)
|
||||
|
||||
if (mTxn.isFieldPresent(sfDeliverMin))
|
||||
{
|
||||
#if ! RIPPLE_ENABLE_DELIVERMIN
|
||||
if (! (view().flags() & tapENABLE_TESTING))
|
||||
if (! allowDeliverMin(view()))
|
||||
return temMALFORMED;
|
||||
#endif
|
||||
|
||||
if (! partialPaymentAllowed)
|
||||
{
|
||||
@@ -160,7 +163,7 @@ Payment::preCheck ()
|
||||
}
|
||||
|
||||
auto const dMin = mTxn.getFieldAmount(sfDeliverMin);
|
||||
if (!isLegalNet(dMin) || dMin <= zero)
|
||||
if (! isLegalNet(dMin) || dMin <= zero)
|
||||
{
|
||||
j_.trace << "Malformed transaction: Invalid " <<
|
||||
jss::DeliverMin.c_str() << " amount. " <<
|
||||
@@ -174,11 +177,9 @@ Payment::preCheck ()
|
||||
dMin.getFullText();
|
||||
return temBAD_AMOUNT;
|
||||
}
|
||||
if (bMax &&
|
||||
(dMin.getCurrency() == maxSourceAmount.getCurrency() &&
|
||||
dMin > maxSourceAmount))
|
||||
if (dMin > saDstAmount)
|
||||
{
|
||||
j_.trace << "Malformed transaction: SendMax less than " <<
|
||||
j_.trace << "Malformed transaction: Dst amount less than " <<
|
||||
jss::DeliverMin.c_str() << ". " <<
|
||||
dMin.getFullText();
|
||||
return temBAD_AMOUNT;
|
||||
@@ -198,12 +199,8 @@ Payment::doApply ()
|
||||
bool const defaultPathsAllowed = !(uTxFlags & tfNoRippleDirect);
|
||||
bool const bPaths = mTxn.isFieldPresent (sfPaths);
|
||||
bool const bMax = mTxn.isFieldPresent (sfSendMax);
|
||||
bool const deliverMin =
|
||||
#if RIPPLE_ENABLE_DELIVERMIN
|
||||
#else
|
||||
(view().flags() & tapENABLE_TESTING) &&
|
||||
#endif
|
||||
mTxn.isFieldPresent(sfDeliverMin);
|
||||
bool const deliverMin = mTxn.isFieldPresent(sfDeliverMin) &&
|
||||
allowDeliverMin(view());
|
||||
|
||||
AccountID const uDstAccountID (mTxn.getAccountID (sfDestination));
|
||||
STAmount const saDstAmount (mTxn.getFieldAmount (sfAmount));
|
||||
|
||||
@@ -49,23 +49,14 @@ public:
|
||||
delivermin(Account("carol")["USD"](5)),
|
||||
txflags(tfPartialPayment), ter(temBAD_AMOUNT));
|
||||
env(pay("alice", "bob", USD(10)), delivermin(USD(15)),
|
||||
txflags(tfPartialPayment), ter(tecPATH_DRY));
|
||||
env(pay("alice", "bob", USD(10)),
|
||||
delivermin(USD(10)), txflags(tfPartialPayment),
|
||||
sendmax(USD(9)), ter(temBAD_AMOUNT));
|
||||
txflags(tfPartialPayment), ter(temBAD_AMOUNT));
|
||||
env(pay(gw, "carol", USD(50)));
|
||||
env(offer("carol", XRP(5), USD(5)));
|
||||
env(pay("alice", "bob", USD(10)), paths(XRP),
|
||||
delivermin(USD(7)), txflags(tfPartialPayment),
|
||||
sendmax(XRP(20)), ter(tecPATH_PARTIAL));
|
||||
env.require(balance("alice", XRP(9999.99998)));
|
||||
sendmax(XRP(5)), ter(tecPATH_PARTIAL));
|
||||
env.require(balance("alice", XRP(9999.99999)));
|
||||
env.require(balance("bob", XRP(10000)));
|
||||
|
||||
// DeliverMin greater than destination amount
|
||||
env(pay("alice", "bob", USD(5)), paths(XRP),
|
||||
delivermin(USD(50)), txflags(tfPartialPayment),
|
||||
sendmax(XRP(5)));
|
||||
env.require(balance("bob", USD(5)));
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -162,7 +162,7 @@ public:
|
||||
open ledger at the moment of the call.
|
||||
Transactions applied after the call to open()
|
||||
will not be visible.
|
||||
|
||||
|
||||
*/
|
||||
std::shared_ptr<ReadView const>
|
||||
open() const;
|
||||
@@ -220,18 +220,25 @@ public:
|
||||
With no arguments, trace all
|
||||
*/
|
||||
void
|
||||
trace(int howMany = -1)
|
||||
trace (int howMany = -1)
|
||||
{
|
||||
trace_ = howMany;
|
||||
}
|
||||
|
||||
/** Turn off JSON tracing. */
|
||||
void
|
||||
notrace()
|
||||
notrace ()
|
||||
{
|
||||
trace_ = 0;
|
||||
}
|
||||
|
||||
/** Turn off testing. */
|
||||
void
|
||||
disable_testing ()
|
||||
{
|
||||
testing_ = false;
|
||||
}
|
||||
|
||||
/** Associate AccountID with account. */
|
||||
void
|
||||
memoize (Account const& account);
|
||||
@@ -305,7 +312,7 @@ public:
|
||||
}
|
||||
|
||||
/** Check a set of requirements.
|
||||
|
||||
|
||||
The requirements are formed
|
||||
from condition functors.
|
||||
*/
|
||||
@@ -444,6 +451,7 @@ public:
|
||||
|
||||
protected:
|
||||
int trace_ = 0;
|
||||
bool testing_ = true;
|
||||
|
||||
void
|
||||
autofill_sig (JTx& jt);
|
||||
|
||||
Reference in New Issue
Block a user