20 #include <ripple/app/tx/impl/SetTrust.h>
21 #include <ripple/basics/Log.h>
22 #include <ripple/ledger/View.h>
23 #include <ripple/protocol/Feature.h>
24 #include <ripple/protocol/Indexes.h>
25 #include <ripple/protocol/Quality.h>
26 #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();
108 if (
id == uDstAccountID)
113 auto const sleDelete =
119 <<
"Malformed transaction: Can not extend credit to self.";
140 bool const bHigh =
account_ > uDstAccountID;
167 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
168 :
view().fees().accountReserve(uOwnerCount + 1));
174 if (bQualityOut && QUALITY_ONE == uQualityOut)
179 bool const bSetAuth = (uTxFlags &
tfSetfAuth);
196 JLOG(
j_.
warn()) <<
"Clearing redundant line.";
206 <<
"Delay transaction: Destination account does not exist.";
210 STAmount saLimitAllow = saLimitAmount;
226 auto const& uLowAccountID = !bHigh ?
account_ : uDstAccountID;
227 auto const& uHighAccountID = bHigh ?
account_ : uDstAccountID;
228 SLE::ref sleLowAccount = !bHigh ? sle : sleDst;
229 SLE::ref sleHighAccount = bHigh ? sle : sleDst;
235 saLowBalance = sleRippleState->getFieldAmount(
sfBalance);
236 saHighBalance = -saLowBalance;
242 sleRippleState->setFieldAmount(
246 !bHigh ? saLimitAllow : sleRippleState->getFieldAmount(
sfLowLimit);
248 bHigh ? saLimitAllow : sleRippleState->getFieldAmount(
sfHighLimit);
265 sleRippleState->setFieldU32(
268 uLowQualityIn = !bHigh
271 uHighQualityIn = bHigh
279 sleRippleState->makeFieldAbsent(
288 if (QUALITY_ONE == uLowQualityIn)
291 if (QUALITY_ONE == uHighQualityIn)
305 else if (uQualityOut)
309 sleRippleState->setFieldU32(
312 uLowQualityOut = !bHigh
315 uHighQualityOut = bHigh
323 sleRippleState->makeFieldAbsent(
335 if (bSetNoRipple && !bClearNoRipple)
337 if ((bHigh ? saHighBalance : saLowBalance) >= beast::zero)
344 else if (bClearNoRipple && !bSetNoRipple)
349 if (bSetFreeze && !bClearFreeze && !sle->isFlag(
lsfNoFreeze))
353 else if (bClearFreeze && !bSetFreeze)
358 if (QUALITY_ONE == uLowQualityOut)
361 if (QUALITY_ONE == uHighQualityOut)
365 bool const bHighDefRipple =
368 bool const bLowReserveSet = uLowQualityIn || uLowQualityOut ||
371 saLowBalance > beast::zero;
372 bool const bLowReserveClear = !bLowReserveSet;
374 bool const bHighReserveSet = uHighQualityIn || uHighQualityOut ||
377 saHighBalance > beast::zero;
378 bool const bHighReserveClear = !bHighReserveSet;
380 bool const bDefault = bLowReserveClear && bHighReserveClear;
385 bool bReserveIncrease =
false;
392 if (bLowReserveSet && !bLowReserved)
399 bReserveIncrease =
true;
402 if (bLowReserveClear && bLowReserved)
409 if (bHighReserveSet && !bHighReserved)
416 bReserveIncrease =
true;
419 if (bHighReserveClear && bHighReserved)
426 if (uFlagsIn != uFlagsOut)
427 sleRippleState->setFieldU32(
sfFlags, uFlagsOut);
434 view(), sleRippleState, uLowAccountID, uHighAccountID, viewJ);
440 <<
"Delay transaction: Insufficent reserve to add trust line.";
450 JLOG(
j_.
trace()) <<
"Modify ripple line";
456 (!bQualityIn || !uQualityIn) &&
458 (!bQualityOut || !uQualityOut) &&
463 <<
"Redundant: Setting non-existent ripple line to defaults.";
468 JLOG(
j_.
trace()) <<
"Delay transaction: Line does not exist. "
469 "Insufficent reserve to create line.";
482 JLOG(
j_.
trace()) <<
"doTrustSet: Creating ripple line: "
494 bSetNoRipple && !bClearNoRipple,
495 bSetFreeze && !bClearFreeze,