20 #include <ripple/app/tx/impl/SetTrust.h>
21 #include <ripple/basics/Log.h>
22 #include <ripple/ledger/View.h>
23 #include <ripple/protocol/AMMCore.h>
24 #include <ripple/protocol/Feature.h>
25 #include <ripple/protocol/Indexes.h>
26 #include <ripple/protocol/Quality.h>
27 #include <ripple/protocol/st.h>
44 JLOG(j.trace()) <<
"Malformed transaction: Invalid flags set.";
53 if (saLimitAmount.
native())
55 JLOG(j.trace()) <<
"Malformed transaction: specifies native limit "
62 JLOG(j.trace()) <<
"Malformed transaction: specifies XRP as IOU";
66 if (saLimitAmount < beast::zero)
68 JLOG(j.trace()) <<
"Malformed transaction: Negative credit limit.";
73 auto const& issuer = saLimitAmount.
getIssuer();
77 JLOG(j.trace()) <<
"Malformed transaction: no destination account.";
99 JLOG(ctx.
j.
trace()) <<
"Retry: Auth not required.";
105 auto const currency = saLimitAmount.getCurrency();
106 auto const uDstAccountID = saLimitAmount.getIssuer();
110 if (
id == uDstAccountID)
115 if (
id == uDstAccountID)
120 auto const sleDelete =
126 <<
"Malformed transaction: Can not extend credit to self.";
167 if (sleDst->isFieldPresent(
sfAMMID) &&
170 if (
auto const ammSle =
171 ctx.
view.
read({ltAMM, sleDst->getFieldH256(sfAMMID)}))
173 if (
auto const lpTokens =
175 lpTokens == beast::zero)
177 else if (lpTokens.getCurrency() != saLimitAmount.getCurrency())
201 bool const bHigh =
account_ > uDstAccountID;
228 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
229 :
view().fees().accountReserve(uOwnerCount + 1));
235 if (bQualityOut && QUALITY_ONE == uQualityOut)
240 bool const bSetAuth = (uTxFlags &
tfSetfAuth);
268 <<
"Delay transaction: Destination account does not exist.";
272 STAmount saLimitAllow = saLimitAmount;
288 auto const& uLowAccountID = !bHigh ?
account_ : uDstAccountID;
289 auto const& uHighAccountID = bHigh ?
account_ : uDstAccountID;
290 SLE::ref sleLowAccount = !bHigh ? sle : sleDst;
291 SLE::ref sleHighAccount = bHigh ? sle : sleDst;
297 saLowBalance = sleRippleState->getFieldAmount(
sfBalance);
298 saHighBalance = -saLowBalance;
304 sleRippleState->setFieldAmount(
308 !bHigh ? saLimitAllow : sleRippleState->getFieldAmount(
sfLowLimit);
310 bHigh ? saLimitAllow : sleRippleState->getFieldAmount(
sfHighLimit);
327 sleRippleState->setFieldU32(
330 uLowQualityIn = !bHigh
333 uHighQualityIn = bHigh
341 sleRippleState->makeFieldAbsent(
350 if (QUALITY_ONE == uLowQualityIn)
353 if (QUALITY_ONE == uHighQualityIn)
367 else if (uQualityOut)
371 sleRippleState->setFieldU32(
374 uLowQualityOut = !bHigh
377 uHighQualityOut = bHigh
385 sleRippleState->makeFieldAbsent(
397 if (bSetNoRipple && !bClearNoRipple)
399 if ((bHigh ? saHighBalance : saLowBalance) >= beast::zero)
406 else if (bClearNoRipple && !bSetNoRipple)
411 if (bSetFreeze && !bClearFreeze && !sle->isFlag(
lsfNoFreeze))
415 else if (bClearFreeze && !bSetFreeze)
420 if (QUALITY_ONE == uLowQualityOut)
423 if (QUALITY_ONE == uHighQualityOut)
427 bool const bHighDefRipple =
430 bool const bLowReserveSet = uLowQualityIn || uLowQualityOut ||
433 saLowBalance > beast::zero;
434 bool const bLowReserveClear = !bLowReserveSet;
436 bool const bHighReserveSet = uHighQualityIn || uHighQualityOut ||
439 saHighBalance > beast::zero;
440 bool const bHighReserveClear = !bHighReserveSet;
442 bool const bDefault = bLowReserveClear && bHighReserveClear;
447 bool bReserveIncrease =
false;
454 if (bLowReserveSet && !bLowReserved)
461 bReserveIncrease =
true;
464 if (bLowReserveClear && bLowReserved)
471 if (bHighReserveSet && !bHighReserved)
478 bReserveIncrease =
true;
481 if (bHighReserveClear && bHighReserved)
488 if (uFlagsIn != uFlagsOut)
489 sleRippleState->setFieldU32(
sfFlags, uFlagsOut);
496 view(), sleRippleState, uLowAccountID, uHighAccountID, viewJ);
502 <<
"Delay transaction: Insufficent reserve to add trust line.";
512 JLOG(
j_.
trace()) <<
"Modify ripple line";
518 (!bQualityIn || !uQualityIn) &&
520 (!bQualityOut || !uQualityOut) &&
525 <<
"Redundant: Setting non-existent ripple line to defaults.";
530 JLOG(
j_.
trace()) <<
"Delay transaction: Line does not exist. "
531 "Insufficent reserve to create line.";
544 JLOG(
j_.
trace()) <<
"doTrustSet: Creating ripple line: "
556 bSetNoRipple && !bClearNoRipple,
557 bSetFreeze && !bClearFreeze,