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();
107 if (
id == uDstAccountID)
112 auto const sleDelete =
118 <<
"Malformed transaction: Can not extend credit to self.";
139 bool const bHigh =
account_ > uDstAccountID;
166 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
167 :
view().fees().accountReserve(uOwnerCount + 1));
173 if (bQualityOut && QUALITY_ONE == uQualityOut)
178 bool const bSetAuth = (uTxFlags &
tfSetfAuth);
195 JLOG(
j_.
warn()) <<
"Clearing redundant line.";
205 <<
"Delay transaction: Destination account does not exist.";
209 STAmount saLimitAllow = saLimitAmount;
225 auto const& uLowAccountID = !bHigh ?
account_ : uDstAccountID;
226 auto const& uHighAccountID = bHigh ?
account_ : uDstAccountID;
227 SLE::ref sleLowAccount = !bHigh ? sle : sleDst;
228 SLE::ref sleHighAccount = bHigh ? sle : sleDst;
234 saLowBalance = sleRippleState->getFieldAmount(
sfBalance);
235 saHighBalance = -saLowBalance;
241 sleRippleState->setFieldAmount(
245 !bHigh ? saLimitAllow : sleRippleState->getFieldAmount(
sfLowLimit);
247 bHigh ? saLimitAllow : sleRippleState->getFieldAmount(
sfHighLimit);
264 sleRippleState->setFieldU32(
267 uLowQualityIn = !bHigh
270 uHighQualityIn = bHigh
278 sleRippleState->makeFieldAbsent(
287 if (QUALITY_ONE == uLowQualityIn)
290 if (QUALITY_ONE == uHighQualityIn)
304 else if (uQualityOut)
308 sleRippleState->setFieldU32(
311 uLowQualityOut = !bHigh
314 uHighQualityOut = bHigh
322 sleRippleState->makeFieldAbsent(
334 if (bSetNoRipple && !bClearNoRipple)
336 if ((bHigh ? saHighBalance : saLowBalance) >= beast::zero)
343 else if (bClearNoRipple && !bSetNoRipple)
348 if (bSetFreeze && !bClearFreeze && !sle->isFlag(
lsfNoFreeze))
352 else if (bClearFreeze && !bSetFreeze)
357 if (QUALITY_ONE == uLowQualityOut)
360 if (QUALITY_ONE == uHighQualityOut)
364 bool const bHighDefRipple =
367 bool const bLowReserveSet = uLowQualityIn || uLowQualityOut ||
370 saLowBalance > beast::zero;
371 bool const bLowReserveClear = !bLowReserveSet;
373 bool const bHighReserveSet = uHighQualityIn || uHighQualityOut ||
376 saHighBalance > beast::zero;
377 bool const bHighReserveClear = !bHighReserveSet;
379 bool const bDefault = bLowReserveClear && bHighReserveClear;
384 bool bReserveIncrease =
false;
391 if (bLowReserveSet && !bLowReserved)
398 bReserveIncrease =
true;
401 if (bLowReserveClear && bLowReserved)
408 if (bHighReserveSet && !bHighReserved)
415 bReserveIncrease =
true;
418 if (bHighReserveClear && bHighReserved)
425 if (uFlagsIn != uFlagsOut)
426 sleRippleState->setFieldU32(
sfFlags, uFlagsOut);
433 view(), sleRippleState, uLowAccountID, uHighAccountID, viewJ);
439 <<
"Delay transaction: Insufficent reserve to add trust line.";
449 JLOG(
j_.
trace()) <<
"Modify ripple line";
455 (!bQualityIn || !uQualityIn) &&
457 (!bQualityOut || !uQualityOut) &&
462 <<
"Redundant: Setting non-existent ripple line to defaults.";
467 JLOG(
j_.
trace()) <<
"Delay transaction: Line does not exist. "
468 "Insufficent reserve to create line.";
481 JLOG(
j_.
trace()) <<
"doTrustSet: Creating ripple line: "
493 bSetNoRipple && !bClearNoRipple,
494 bSetFreeze && !bClearFreeze,