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.";
154 if (sleDst->isFieldPresent(
sfAMMID) &&
157 if (
auto const ammSle =
158 ctx.
view.
read({ltAMM, sleDst->getFieldH256(sfAMMID)}))
160 if (
auto const lpTokens =
162 lpTokens == beast::zero)
164 else if (lpTokens.getCurrency() != saLimitAmount.getCurrency())
188 bool const bHigh =
account_ > uDstAccountID;
215 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
216 :
view().fees().accountReserve(uOwnerCount + 1));
222 if (bQualityOut && QUALITY_ONE == uQualityOut)
227 bool const bSetAuth = (uTxFlags &
tfSetfAuth);
255 <<
"Delay transaction: Destination account does not exist.";
259 STAmount saLimitAllow = saLimitAmount;
275 auto const& uLowAccountID = !bHigh ?
account_ : uDstAccountID;
276 auto const& uHighAccountID = bHigh ?
account_ : uDstAccountID;
277 SLE::ref sleLowAccount = !bHigh ? sle : sleDst;
278 SLE::ref sleHighAccount = bHigh ? sle : sleDst;
284 saLowBalance = sleRippleState->getFieldAmount(
sfBalance);
285 saHighBalance = -saLowBalance;
291 sleRippleState->setFieldAmount(
295 !bHigh ? saLimitAllow : sleRippleState->getFieldAmount(
sfLowLimit);
297 bHigh ? saLimitAllow : sleRippleState->getFieldAmount(
sfHighLimit);
314 sleRippleState->setFieldU32(
317 uLowQualityIn = !bHigh
320 uHighQualityIn = bHigh
328 sleRippleState->makeFieldAbsent(
337 if (QUALITY_ONE == uLowQualityIn)
340 if (QUALITY_ONE == uHighQualityIn)
354 else if (uQualityOut)
358 sleRippleState->setFieldU32(
361 uLowQualityOut = !bHigh
364 uHighQualityOut = bHigh
372 sleRippleState->makeFieldAbsent(
384 if (bSetNoRipple && !bClearNoRipple)
386 if ((bHigh ? saHighBalance : saLowBalance) >= beast::zero)
393 else if (bClearNoRipple && !bSetNoRipple)
398 if (bSetFreeze && !bClearFreeze && !sle->isFlag(
lsfNoFreeze))
402 else if (bClearFreeze && !bSetFreeze)
407 if (QUALITY_ONE == uLowQualityOut)
410 if (QUALITY_ONE == uHighQualityOut)
414 bool const bHighDefRipple =
417 bool const bLowReserveSet = uLowQualityIn || uLowQualityOut ||
420 saLowBalance > beast::zero;
421 bool const bLowReserveClear = !bLowReserveSet;
423 bool const bHighReserveSet = uHighQualityIn || uHighQualityOut ||
426 saHighBalance > beast::zero;
427 bool const bHighReserveClear = !bHighReserveSet;
429 bool const bDefault = bLowReserveClear && bHighReserveClear;
434 bool bReserveIncrease =
false;
441 if (bLowReserveSet && !bLowReserved)
448 bReserveIncrease =
true;
451 if (bLowReserveClear && bLowReserved)
458 if (bHighReserveSet && !bHighReserved)
465 bReserveIncrease =
true;
468 if (bHighReserveClear && bHighReserved)
475 if (uFlagsIn != uFlagsOut)
476 sleRippleState->setFieldU32(
sfFlags, uFlagsOut);
483 view(), sleRippleState, uLowAccountID, uHighAccountID, viewJ);
489 <<
"Delay transaction: Insufficent reserve to add trust line.";
499 JLOG(
j_.
trace()) <<
"Modify ripple line";
505 (!bQualityIn || !uQualityIn) &&
507 (!bQualityOut || !uQualityOut) &&
512 <<
"Redundant: Setting non-existent ripple line to defaults.";
517 JLOG(
j_.
trace()) <<
"Delay transaction: Line does not exist. "
518 "Insufficent reserve to create line.";
531 JLOG(
j_.
trace()) <<
"doTrustSet: Creating ripple line: "
543 bSetNoRipple && !bClearNoRipple,
544 bSetFreeze && !bClearFreeze,