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>
43 JLOG(j.trace()) <<
"Malformed transaction: Invalid flags set.";
52 if (saLimitAmount.
native())
54 JLOG(j.trace()) <<
"Malformed transaction: specifies native limit "
61 JLOG(j.trace()) <<
"Malformed transaction: specifies XRP as IOU";
65 if (saLimitAmount < beast::zero)
67 JLOG(j.trace()) <<
"Malformed transaction: Negative credit limit.";
72 auto const& issuer = saLimitAmount.
getIssuer();
76 JLOG(j.trace()) <<
"Malformed transaction: no destination account.";
98 JLOG(ctx.
j.
trace()) <<
"Retry: Auth not required.";
104 auto const currency = saLimitAmount.getCurrency();
105 auto const uDstAccountID = saLimitAmount.getIssuer();
109 if (
id == uDstAccountID)
114 if (
id == uDstAccountID)
119 auto const sleDelete =
125 <<
"Malformed transaction: Can not extend credit to self.";
140 auto const dstFlags = sleDst->getFlags();
161 bool const bHigh =
account_ > uDstAccountID;
188 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
189 :
view().fees().accountReserve(uOwnerCount + 1));
195 if (bQualityOut && QUALITY_ONE == uQualityOut)
200 bool const bSetAuth = (uTxFlags &
tfSetfAuth);
228 <<
"Delay transaction: Destination account does not exist.";
232 STAmount saLimitAllow = saLimitAmount;
248 auto const& uLowAccountID = !bHigh ?
account_ : uDstAccountID;
249 auto const& uHighAccountID = bHigh ?
account_ : uDstAccountID;
250 SLE::ref sleLowAccount = !bHigh ? sle : sleDst;
251 SLE::ref sleHighAccount = bHigh ? sle : sleDst;
257 saLowBalance = sleRippleState->getFieldAmount(
sfBalance);
258 saHighBalance = -saLowBalance;
264 sleRippleState->setFieldAmount(
268 !bHigh ? saLimitAllow : sleRippleState->getFieldAmount(
sfLowLimit);
270 bHigh ? saLimitAllow : sleRippleState->getFieldAmount(
sfHighLimit);
287 sleRippleState->setFieldU32(
290 uLowQualityIn = !bHigh
293 uHighQualityIn = bHigh
301 sleRippleState->makeFieldAbsent(
310 if (QUALITY_ONE == uLowQualityIn)
313 if (QUALITY_ONE == uHighQualityIn)
327 else if (uQualityOut)
331 sleRippleState->setFieldU32(
334 uLowQualityOut = !bHigh
337 uHighQualityOut = bHigh
345 sleRippleState->makeFieldAbsent(
357 if (bSetNoRipple && !bClearNoRipple)
359 if ((bHigh ? saHighBalance : saLowBalance) >= beast::zero)
366 else if (bClearNoRipple && !bSetNoRipple)
371 if (bSetFreeze && !bClearFreeze && !sle->isFlag(
lsfNoFreeze))
375 else if (bClearFreeze && !bSetFreeze)
380 if (QUALITY_ONE == uLowQualityOut)
383 if (QUALITY_ONE == uHighQualityOut)
387 bool const bHighDefRipple =
390 bool const bLowReserveSet = uLowQualityIn || uLowQualityOut ||
393 saLowBalance > beast::zero;
394 bool const bLowReserveClear = !bLowReserveSet;
396 bool const bHighReserveSet = uHighQualityIn || uHighQualityOut ||
399 saHighBalance > beast::zero;
400 bool const bHighReserveClear = !bHighReserveSet;
402 bool const bDefault = bLowReserveClear && bHighReserveClear;
407 bool bReserveIncrease =
false;
414 if (bLowReserveSet && !bLowReserved)
421 bReserveIncrease =
true;
424 if (bLowReserveClear && bLowReserved)
431 if (bHighReserveSet && !bHighReserved)
438 bReserveIncrease =
true;
441 if (bHighReserveClear && bHighReserved)
448 if (uFlagsIn != uFlagsOut)
449 sleRippleState->setFieldU32(
sfFlags, uFlagsOut);
456 view(), sleRippleState, uLowAccountID, uHighAccountID, viewJ);
462 <<
"Delay transaction: Insufficent reserve to add trust line.";
472 JLOG(
j_.
trace()) <<
"Modify ripple line";
478 (!bQualityIn || !uQualityIn) &&
480 (!bQualityOut || !uQualityOut) &&
485 <<
"Redundant: Setting non-existent ripple line to defaults.";
490 JLOG(
j_.
trace()) <<
"Delay transaction: Line does not exist. "
491 "Insufficent reserve to create line.";
504 JLOG(
j_.
trace()) <<
"doTrustSet: Creating ripple line: "
516 bSetNoRipple && !bClearNoRipple,
517 bSetFreeze && !bClearFreeze,