xrpld
Loading...
Searching...
No Matches
libxrpl/ledger/helpers/TokenHelpers.cpp
1#include <xrpl/ledger/helpers/TokenHelpers.h>
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/MathUtilities.h>
5#include <xrpl/basics/Number.h>
6#include <xrpl/beast/utility/Journal.h>
7#include <xrpl/beast/utility/Zero.h>
8#include <xrpl/beast/utility/instrumentation.h>
9#include <xrpl/ledger/ApplyView.h>
10#include <xrpl/ledger/ReadView.h>
11#include <xrpl/ledger/View.h>
12#include <xrpl/ledger/helpers/AccountRootHelpers.h>
13#include <xrpl/ledger/helpers/MPTokenHelpers.h>
14#include <xrpl/ledger/helpers/RippleStateHelpers.h>
15#include <xrpl/ledger/helpers/SponsorHelpers.h>
16#include <xrpl/protocol/AccountID.h>
17#include <xrpl/protocol/Asset.h>
18#include <xrpl/protocol/Concepts.h>
19#include <xrpl/protocol/Feature.h>
20#include <xrpl/protocol/Indexes.h>
21#include <xrpl/protocol/Issue.h>
22#include <xrpl/protocol/LedgerFormats.h>
23#include <xrpl/protocol/MPTAmount.h>
24#include <xrpl/protocol/MPTIssue.h>
25#include <xrpl/protocol/Protocol.h>
26#include <xrpl/protocol/Quality.h>
27#include <xrpl/protocol/Rate.h>
28#include <xrpl/protocol/SField.h>
29#include <xrpl/protocol/STAmount.h>
30#include <xrpl/protocol/STLedgerEntry.h>
31#include <xrpl/protocol/TER.h>
32#include <xrpl/protocol/UintTypes.h>
33#include <xrpl/protocol/XRPAmount.h>
34
35#include <algorithm>
36#include <cstdint>
37#include <initializer_list>
38#include <limits>
39#include <string>
40#include <variant>
41
42namespace xrpl {
43
44//------------------------------------------------------------------------------
45//
46// Freeze checking (Asset-based)
47//
48//------------------------------------------------------------------------------
49
50bool
51isGlobalFrozen(ReadView const& view, Asset const& asset)
52{
53 return asset.visit(
54 [&](Issue const& issue) { return isGlobalFrozen(view, issue.getIssuer()); },
55 [&](MPTIssue const& issue) { return isGlobalFrozen(view, issue); });
56}
57
58TER
59checkGlobalFrozen(ReadView const& view, Asset const& asset)
60{
61 if (isGlobalFrozen(view, asset))
62 return asset.holds<MPTIssue>() ? tecLOCKED : tecFROZEN;
63 return tesSUCCESS;
64}
65
66bool
67isIndividualFrozen(ReadView const& view, AccountID const& account, Asset const& asset)
68{
69 return std::visit(
70 [&](auto const& issue) { return isIndividualFrozen(view, account, issue); }, asset.value());
71}
72
73TER
74checkIndividualFrozen(ReadView const& view, AccountID const& account, Asset const& asset)
75{
76 if (isIndividualFrozen(view, account, asset))
77 return asset.holds<MPTIssue>() ? tecLOCKED : tecFROZEN;
78 return tesSUCCESS;
79}
80
81bool
82isFrozen(ReadView const& view, AccountID const& account, Asset const& asset, std::uint8_t depth)
83{
84 return std::visit(
85 [&](auto const& issue) { return isFrozen(view, account, issue, depth); }, asset.value());
86}
87
88TER
89checkFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
90{
91 return isFrozen(view, account, issue) ? (TER)tecFROZEN : (TER)tesSUCCESS;
92}
93
94TER
95checkFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue)
96{
97 return isFrozen(view, account, mptIssue) ? (TER)tecLOCKED : (TER)tesSUCCESS;
98}
99
100TER
101checkFrozen(ReadView const& view, AccountID const& account, Asset const& asset)
102{
103 return std::visit(
104 [&](auto const& issue) { return checkFrozen(view, account, issue); }, asset.value());
105}
106
107bool
109 ReadView const& view,
110 std::initializer_list<AccountID> const& accounts,
111 Issue const& issue)
112{
113 return std::ranges::any_of(accounts, [&](auto const& account) {
114 return isFrozen(view, account, issue.currency, issue.account);
115 });
116}
117
118bool
120 ReadView const& view,
121 std::initializer_list<AccountID> const& accounts,
122 Asset const& asset,
123 std::uint8_t depth)
124{
125 return asset.visit(
126 [&](Issue const& issue) { return isAnyFrozen(view, accounts, issue); },
127 [&](MPTIssue const& issue) { return isAnyFrozen(view, accounts, issue, depth); });
128}
129
130bool
132 ReadView const& view,
133 AccountID const& account,
134 MPTIssue const& mptIssue,
135 std::uint8_t depth)
136{
137 // Unlike IOUs, frozen / locked MPTs are not allowed to send or receive
138 // funds, so checking "deep frozen" is the same as checking "frozen".
139 return isFrozen(view, account, mptIssue, depth);
140}
141
142bool
143isDeepFrozen(ReadView const& view, AccountID const& account, Asset const& asset, std::uint8_t depth)
144{
145 return std::visit(
146 [&](auto const& issue) { return isDeepFrozen(view, account, issue, depth); },
147 asset.value());
148}
149
150TER
151checkDeepFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue)
152{
153 return isDeepFrozen(view, account, mptIssue) ? (TER)tecLOCKED : (TER)tesSUCCESS;
154}
155
156TER
157checkDeepFrozen(ReadView const& view, AccountID const& account, Asset const& asset)
158{
159 return std::visit(
160 [&](auto const& issue) { return checkDeepFrozen(view, account, issue); }, asset.value());
161}
162
163[[nodiscard]] TER
165 ReadView const& view,
166 AccountID const& pseudoAcct,
167 AccountID const& submitterAcct,
168 AccountID const& dstAcct,
169 Asset const& asset)
170{
171 XRPL_ASSERT(
172 isPseudoAccount(view, pseudoAcct),
173 "xrpl::checkWithdrawFreeze : source is a pseudo-account");
174 XRPL_ASSERT(
175 !isPseudoAccount(view, submitterAcct),
176 "xrpl::checkWithdrawFreeze : submitter is not a pseudo-account");
177 XRPL_ASSERT(
178 !isPseudoAccount(view, dstAcct),
179 "xrpl::checkWithdrawFreeze : destination is not a pseudo-account");
180 // The asset being withdrawn must not be issued by a pseudo-account
181 XRPL_ASSERT(
182 !isPseudoAccount(view, asset.getIssuer()),
183 "xrpl::checkWithdrawFreeze : asset issuer cannot be a pseudo-account");
184
185 // Funds can always be sent to the issuer
186 if (dstAcct == asset.getIssuer())
187 return tesSUCCESS;
188
189 // If the asset is globally frozen, other checks are redundant
190 if (auto const ret = checkGlobalFrozen(view, asset); !isTesSuccess(ret))
191 return ret;
192
193 // The transfer is from Submitter to Destination via Source (pseudo-account)
194 // Both Source and Submitter must not be frozen to allow sending funds
195 if (auto const ret = checkIndividualFrozen(view, pseudoAcct, asset); !isTesSuccess(ret))
196 return ret;
197
198 // Check submitter's individual freeze only when Submitter != Destination (a regular freeze
199 // should not block self-withdrawal).
200 if (submitterAcct != dstAcct)
201 {
202 if (auto const ret = checkIndividualFrozen(view, submitterAcct, asset); !isTesSuccess(ret))
203 return ret;
204 }
205
206 // The destination account must not be deep frozen to receive the funds
207 if (auto const ret = checkDeepFrozen(view, dstAcct, asset); !isTesSuccess(ret))
208 return ret;
209
210 if (asset.holds<MPTIssue>() &&
211 isVaultPseudoAccountFrozen(view, pseudoAcct, asset.get<MPTIssue>(), 0))
212 {
213 // LCOV_EXCL_START
214 UNREACHABLE("xrpl::checkWithdrawFreeze : pseudo-account backed object holds shares");
215 return tecINTERNAL;
216 // LCOV_EXCL_STOP
217 }
218
219 return tesSUCCESS;
220}
221
222[[nodiscard]] TER
224 ReadView const& view,
225 AccountID const& srcAcct,
226 AccountID const& pseudoAcct,
227 Asset const& asset)
228{
229 XRPL_ASSERT(
230 isPseudoAccount(view, pseudoAcct),
231 "xrpl::checkDepositFreeze : destination is a pseudo-account");
232 XRPL_ASSERT(
233 !isPseudoAccount(view, srcAcct),
234 "xrpl::checkDepositFreeze : source is not a pseudo-account");
235 // The asset being deposited must not be issued by a pseudo-account
236 XRPL_ASSERT(
237 !isPseudoAccount(view, asset.getIssuer()),
238 "xrpl::checkDepositFreeze : asset issuer cannot be a pseudo-account");
239
240 if (auto const ret = checkGlobalFrozen(view, asset); !isTesSuccess(ret))
241 return ret;
242
243 if (srcAcct != asset.getIssuer())
244 {
245 if (auto const ret = checkIndividualFrozen(view, srcAcct, asset); !isTesSuccess(ret))
246 return ret;
247 }
248
249 // Unlike regular accounts, pseudo-accounts cannot receive deposits under a regular freeze
250 // because those funds cannot be later withdrawn
251 if (auto const ret = checkIndividualFrozen(view, pseudoAcct, asset); !isTesSuccess(ret))
252 return ret;
253
254 if (asset.holds<MPTIssue>() &&
255 isVaultPseudoAccountFrozen(view, pseudoAcct, asset.get<MPTIssue>(), 0))
256 {
257 // LCOV_EXCL_START
258 UNREACHABLE("xrpl::checkDepositFreeze : pseudo-account backed object holds shares");
259 return tecINTERNAL;
260 // LCOV_EXCL_STOP
261 }
262
263 return tesSUCCESS;
264}
265
266//------------------------------------------------------------------------------
267//
268// Account balance functions
269//
270//------------------------------------------------------------------------------
271
274 ReadView const& view,
275 AccountID const& account,
276 Currency const& currency,
277 AccountID const& issuer,
278 FreezeHandling zeroIfFrozen,
280{
281 auto sle = view.read(keylet::trustLine(account, issuer, currency));
282
283 if (!sle)
284 {
285 return nullptr;
286 }
287
288 if (zeroIfFrozen == FreezeHandling::ZeroIfFrozen)
289 {
290 if (isFrozen(view, account, currency, issuer) ||
291 isDeepFrozen(view, account, currency, issuer))
292 {
293 return nullptr;
294 }
295
296 // when fixFrozenLPTokenTransfer is enabled, if currency is lptoken,
297 // we need to check if the associated assets have been frozen
298 if (view.rules().enabled(fixFrozenLPTokenTransfer))
299 {
300 auto const sleIssuer = view.read(keylet::account(issuer));
301 if (!sleIssuer)
302 {
303 return nullptr; // LCOV_EXCL_LINE
304 }
305 if (sleIssuer->isFieldPresent(sfAMMID))
306 {
307 auto const sleAmm = view.read(keylet::amm((*sleIssuer)[sfAMMID]));
308
309 if (!sleAmm ||
310 isLPTokenFrozen(view, account, (*sleAmm)[sfAsset], (*sleAmm)[sfAsset2]))
311 {
312 return nullptr;
313 }
314 }
315 }
316
317 // An LPToken whose AMM pool contains an MPT that forbids transfers is not
318 // spendable. Issuer is the LPToken's AMM account; canTransferLPToken is
319 // a no-op for non-AMM issuers and non-MPT pool assets, so this is implicitly
320 // gated by featureMPTokensV2.
321 if (!isTesSuccess(canTransferLPToken(view, account, account, issuer)))
322 {
323 return nullptr;
324 }
325 }
326
327 return sle;
328}
329
330static STAmount
332 ReadView const& view,
333 SLE::ConstRef sle,
334 AccountID const& account,
335 Currency const& currency,
336 AccountID const& issuer,
337 bool includeOppositeLimit,
339{
340 STAmount amount;
341 if (sle)
342 {
343 amount = sle->getFieldAmount(sfBalance);
344 bool const accountHigh = account > issuer;
345 auto const& oppositeField = accountHigh ? sfLowLimit : sfHighLimit;
346 if (accountHigh)
347 {
348 // Put balance in account terms.
349 amount.negate();
350 }
351 if (includeOppositeLimit)
352 {
353 amount += sle->getFieldAmount(oppositeField);
354 }
355 amount.get<Issue>().account = issuer;
356 }
357 else
358 {
359 amount.clear(Issue{currency, issuer});
360 }
361
362 JLOG(j.trace()) << "getTrustLineBalance:" << " account=" << to_string(account)
363 << " amount=" << amount.getFullText();
364
365 return view.balanceHookIOU(account, issuer, amount);
366}
367
368STAmount
370 ReadView const& view,
371 AccountID const& account,
372 Currency const& currency,
373 AccountID const& issuer,
374 FreezeHandling zeroIfFrozen,
376 SpendableHandling includeFullBalance)
377{
378 STAmount const amount;
379 if (isXRP(currency))
380 {
381 return {xrpLiquid(view, account, 0, j)};
382 }
383
384 bool const returnSpendable = (includeFullBalance == SpendableHandling::FullBalance);
385 if (returnSpendable && account == issuer)
386 {
387 // If the account is the issuer, then their limit is effectively
388 // infinite
389 return STAmount{Issue{currency, issuer}, STAmount::kMaxValue, STAmount::kMaxOffset};
390 }
391
392 // IOU: Return balance on trust line modulo freeze
393 SLE::const_pointer const sle =
394 getLineIfUsable(view, account, currency, issuer, zeroIfFrozen, j);
395
396 return getTrustLineBalance(view, sle, account, currency, issuer, returnSpendable, j);
397}
398
399STAmount
401 ReadView const& view,
402 AccountID const& account,
403 Issue const& issue,
404 FreezeHandling zeroIfFrozen,
406 SpendableHandling includeFullBalance)
407{
408 return accountHolds(
409 view, account, issue.currency, issue.account, zeroIfFrozen, j, includeFullBalance);
410}
411
412STAmount
414 ReadView const& view,
415 AccountID const& account,
416 MPTIssue const& mptIssue,
417 FreezeHandling zeroIfFrozen,
418 AuthHandling zeroIfUnauthorized,
420 SpendableHandling includeFullBalance)
421{
422 bool const returnSpendable = (includeFullBalance == SpendableHandling::FullBalance);
423 STAmount amount{mptIssue};
424 auto const& issuer = mptIssue.getIssuer();
425 bool const mptokensV2 = view.rules().enabled(featureMPTokensV2);
426
427 if (returnSpendable && account == mptIssue.getIssuer())
428 {
429 // if the account is the issuer, and the issuance exists, their limit is
430 // the issuance limit minus the outstanding value
431 auto const issuance = view.read(keylet::mptokenIssuance(mptIssue.getMptID()));
432
433 if (!issuance)
434 {
435 return amount;
436 }
437 auto const available = availableMPTAmount(*issuance);
438 if (!mptokensV2)
439 return STAmount{mptIssue, available};
440 return view.balanceHookMPT(issuer, mptIssue, available);
441 }
442
443 auto const sleMpt = view.read(keylet::mptoken(mptIssue.getMptID(), account));
444
445 if (!sleMpt ||
446 (zeroIfFrozen == FreezeHandling::ZeroIfFrozen && isFrozen(view, account, *sleMpt)))
447 {
448 amount.clear(mptIssue);
449 }
450 else
451 {
452 amount = STAmount{mptIssue, sleMpt->getFieldU64(sfMPTAmount)};
453
454 // Only if auth check is needed, as it needs to do an additional read
455 // operation. Note featureSingleAssetVault will affect error codes.
456 if (zeroIfUnauthorized == AuthHandling::ZeroIfUnauthorized &&
457 (view.rules().enabled(featureSingleAssetVault) ||
458 view.rules().enabled(featureConfidentialTransfer)))
459 {
460 if (auto const err = requireAuth(view, mptIssue, account, AuthType::StrongAuth);
461 !isTesSuccess(err))
462 amount.clear(mptIssue);
463 }
464 else if (zeroIfUnauthorized == AuthHandling::ZeroIfUnauthorized)
465 {
466 auto const sleIssuance = view.read(keylet::mptokenIssuance(mptIssue.getMptID()));
467
468 // if auth is enabled on the issuance and mpt is not authorized,
469 // clear amount
470 if (sleIssuance && sleIssuance->isFlag(lsfMPTRequireAuth) &&
471 !sleMpt->isFlag(lsfMPTAuthorized))
472 amount.clear(mptIssue);
473 }
474 }
475
476 if (view.rules().enabled(featureMPTokensV2))
477 return view.balanceHookMPT(account, mptIssue, amount.mpt().value());
478 return amount;
479}
480
481[[nodiscard]] STAmount
483 ReadView const& view,
484 AccountID const& account,
485 Asset const& asset,
486 FreezeHandling zeroIfFrozen,
487 AuthHandling zeroIfUnauthorized,
489 SpendableHandling includeFullBalance)
490{
491 return asset.visit(
492 [&](Issue const& issue) {
493 return accountHolds(view, account, issue, zeroIfFrozen, j, includeFullBalance);
494 },
495 [&](MPTIssue const& issue) {
496 return accountHolds(
497 view, account, issue, zeroIfFrozen, zeroIfUnauthorized, j, includeFullBalance);
498 });
499}
500
501STAmount
503 ReadView const& view,
504 AccountID const& id,
505 STAmount const& saDefault,
506 FreezeHandling freezeHandling,
508{
509 XRPL_ASSERT(saDefault.holds<Issue>(), "xrpl::accountFunds: saDefault holds Issue");
510
511 if (!saDefault.native() && saDefault.getIssuer() == id)
512 return saDefault;
513
514 return accountHolds(
515 view, id, saDefault.get<Issue>().currency, saDefault.getIssuer(), freezeHandling, j);
516}
517
518STAmount
520 ReadView const& view,
521 AccountID const& id,
522 STAmount const& saDefault,
523 FreezeHandling freezeHandling,
524 AuthHandling authHandling,
526{
527 return saDefault.asset().visit(
528 [&](Issue const&) { return accountFunds(view, id, saDefault, freezeHandling, j); },
529 [&](MPTIssue const&) {
530 return accountHolds(
531 view,
532 id,
533 saDefault.asset(),
534 freezeHandling,
535 authHandling,
536 j,
538 });
539}
540
541Rate
542transferRate(ReadView const& view, Asset const& asset)
543{
544 return asset.visit(
545 [&](Issue const& issue) { return transferRate(view, issue.getIssuer()); },
546 [&](MPTIssue const& issue) { return transferRate(view, issue.getMptID()); });
547}
548
549Rate
550transferRate(ReadView const& view, STAmount const& amount)
551{
552 return transferRate(view, amount.asset());
553}
554
555STAmount
556addTransferFee(STAmount const& amount, Rate const& rate)
557{
558 if (rate == kParityRate)
559 return amount;
560 return mulRatio(amount, rate.value, QUALITY_ONE, Number::RoundingMode::Upward);
561}
562
563STAmount
564subtractTransferFee(STAmount const& amount, Rate const& rate)
565{
566 if (rate == kParityRate)
567 return amount;
568 return mulRatio(amount, QUALITY_ONE, rate.value, Number::RoundingMode::Downward);
569}
570
571//------------------------------------------------------------------------------
572//
573// Holding operations
574//
575//------------------------------------------------------------------------------
576
577[[nodiscard]] TER
578canAddHolding(ReadView const& view, Issue const& issue)
579{
580 if (issue.native())
581 {
582 return tesSUCCESS; // No special checks for XRP
583 }
584
585 auto const issuer = view.read(keylet::account(issue.getIssuer()));
586 if (!issuer)
587 {
588 return terNO_ACCOUNT;
589 }
590 if (!issuer->isFlag(lsfDefaultRipple))
591 {
592 return terNO_RIPPLE;
593 }
594
595 return tesSUCCESS;
596}
597
598[[nodiscard]] TER
599canAddHolding(ReadView const& view, Asset const& asset)
600{
601 return std::visit(
602 [&]<ValidIssueType TIss>(TIss const& issue) -> TER { return canAddHolding(view, issue); },
603 asset.value());
604}
605
606[[nodiscard]] bool
607holdingExists(ReadView const& view, AccountID const& account, Issue const& issue)
608{
609 if (issue.native() || account == issue.getIssuer())
610 return true;
611 return view.exists(keylet::trustLine(account, issue));
612}
613
614[[nodiscard]] bool
615holdingExists(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue)
616{
617 if (account == mptIssue.getIssuer())
618 return true;
619 return view.exists(keylet::mptoken(mptIssue.getMptID(), account));
620}
621
622[[nodiscard]] bool
623holdingExists(ReadView const& view, AccountID const& account, Asset const& asset)
624{
625 return std::visit(
626 [&]<ValidIssueType TIss>(TIss const& issue) -> bool {
627 return holdingExists(view, account, issue);
628 },
629 asset.value());
630}
631
632TER
635 AccountID const& accountID,
636 XRPAmount priorBalance,
637 Asset const& asset,
638 beast::Journal journal)
639{
640 return std::visit(
641 [&]<ValidIssueType TIss>(TIss const& issue) -> TER {
642 return addEmptyHolding(ctx, accountID, priorBalance, issue, journal);
643 },
644 asset.value());
645}
646
647TER
650 AccountID const& accountID,
651 Asset const& asset,
652 beast::Journal journal)
653{
654 return std::visit(
655 [&]<ValidIssueType TIss>(TIss const& issue) -> TER {
656 return removeEmptyHolding(ctx, accountID, issue, journal);
657 },
658 asset.value());
659}
660
661//------------------------------------------------------------------------------
662//
663// Authorization and transfer checks
664//
665//------------------------------------------------------------------------------
666
667TER
668requireAuth(ReadView const& view, Asset const& asset, AccountID const& account, AuthType authType)
669{
670 return std::visit(
671 [&]<ValidIssueType TIss>(TIss const& issue) {
672 return requireAuth(view, issue, account, authType);
673 },
674 asset.value());
675}
676
677TER
679 ReadView const& view,
680 Asset const& asset,
681 AccountID const& from,
682 AccountID const& to,
684 std::uint8_t depth)
685{
686 return asset.visit(
687 [&](MPTIssue const& issue) -> TER {
688 return canTransfer(view, issue, from, to, waive, depth);
689 },
690 [&](Issue const& issue) -> TER { return canTransfer(view, issue, from, to); });
691}
692
693//------------------------------------------------------------------------------
694//
695// Money Transfers
696//
697//------------------------------------------------------------------------------
698
699// Direct send w/o fees:
700// - Redeeming IOUs and/or sending sender's own IOUs.
701// - Create trust line if needed.
702// --> bCheckIssuer : normally require issuer to be involved.
703static TER
705 ApplyView& view,
706 AccountID const& uSenderID,
707 AccountID const& uReceiverID,
708 STAmount const& saAmount,
709 bool bCheckIssuer,
710 SLE::Ref sponsorSle,
712{
713 AccountID const& issuer = saAmount.getIssuer();
714 Currency const& currency = saAmount.get<Issue>().currency;
715
716 // Make sure issuer is involved.
717 XRPL_ASSERT(
718 !bCheckIssuer || uSenderID == issuer || uReceiverID == issuer,
719 "xrpl::directSendNoFeeIOU : matching issuer or don't care");
720 (void)issuer;
721
722 // Disallow sending to self.
723 XRPL_ASSERT(uSenderID != uReceiverID, "xrpl::directSendNoFeeIOU : sender is not receiver");
724
725 bool const bSenderHigh = uSenderID > uReceiverID;
726 auto const index = keylet::trustLine(uSenderID, uReceiverID, currency);
727
728 XRPL_ASSERT(
729 !isXRP(uSenderID) && uSenderID != noAccount(),
730 "xrpl::directSendNoFeeIOU : sender is not XRP");
731 XRPL_ASSERT(
732 !isXRP(uReceiverID) && uReceiverID != noAccount(),
733 "xrpl::directSendNoFeeIOU : receiver is not XRP");
734
735 // If the line exists, modify it accordingly.
736 if (auto const sleRippleState = view.peek(index))
737 {
738 STAmount saBalance = sleRippleState->getFieldAmount(sfBalance);
739
740 if (bSenderHigh)
741 saBalance.negate(); // Put balance in sender terms.
742
743 view.creditHookIOU(uSenderID, uReceiverID, saAmount, saBalance);
744
745 STAmount const saBefore = saBalance;
746
747 saBalance -= saAmount;
748
749 JLOG(j.trace()) << "directSendNoFeeIOU: " << to_string(uSenderID) << " -> "
750 << to_string(uReceiverID) << " : before=" << saBefore.getFullText()
751 << " amount=" << saAmount.getFullText()
752 << " after=" << saBalance.getFullText();
753
754 bool bDelete = false;
755
756 auto const senderReserveFlag = bSenderHigh ? lsfHighReserve : lsfLowReserve;
757 auto const senderNoRippleFlag = bSenderHigh ? lsfHighNoRipple : lsfLowNoRipple;
758 auto const senderFreezeFlag = bSenderHigh ? lsfHighFreeze : lsfLowFreeze;
759 auto const receiverReserveFlag = bSenderHigh ? lsfLowReserve : lsfHighReserve;
760
761 // FIXME This NEEDS to be cleaned up and simplified. It's impossible
762 // for anyone to understand.
763 if (saBefore > beast::kZero
764 // Sender balance was positive.
765 && saBalance <= beast::kZero
766 // Sender is zero or negative.
767 && sleRippleState->isFlag(senderReserveFlag)
768 // Sender reserve is set.
769 && sleRippleState->isFlag(senderNoRippleFlag) !=
770 view.read(keylet::account(uSenderID))->isFlag(lsfDefaultRipple) &&
771 !sleRippleState->isFlag(senderFreezeFlag) &&
772 !sleRippleState->getFieldAmount(bSenderHigh ? sfHighLimit : sfLowLimit)
773 // Sender trust limit is 0.
774 && (sleRippleState->getFieldU32(bSenderHigh ? sfHighQualityIn : sfLowQualityIn) == 0u)
775 // Sender quality in is 0.
776 &&
777 (sleRippleState->getFieldU32(bSenderHigh ? sfHighQualityOut : sfLowQualityOut) == 0u))
778 // Sender quality out is 0.
779 {
780 // Clear the reserve of the sender, possibly delete the line!
781 auto const currentSponsor = getLedgerEntryReserveSponsor(
782 view, sleRippleState, !bSenderHigh ? sfLowSponsor : sfHighSponsor);
783 decreaseOwnerCount(view, view.peek(keylet::account(uSenderID)), currentSponsor, 1, j);
784
786 sleRippleState, !bSenderHigh ? sfLowSponsor : sfHighSponsor);
787
788 // Clear reserve flag.
789 sleRippleState->clearFlag(senderReserveFlag);
790
791 // Balance is zero, receiver reserve is clear.
792 bDelete = !saBalance // Balance is zero.
793 && !sleRippleState->isFlag(receiverReserveFlag);
794 // Receiver reserve is clear.
795 }
796
797 if (bSenderHigh)
798 saBalance.negate();
799
800 // Want to reflect balance to zero even if we are deleting line.
801 sleRippleState->setFieldAmount(sfBalance, saBalance);
802 // ONLY: Adjust balance.
803
804 if (bDelete)
805 {
806 return trustDelete(
807 view,
808 sleRippleState,
809 bSenderHigh ? uReceiverID : uSenderID,
810 bSenderHigh ? uSenderID : uReceiverID,
811 j);
812 }
813
814 view.update(sleRippleState);
815 return tesSUCCESS;
816 }
817
818 STAmount const saReceiverLimit(Issue{currency, uReceiverID});
819 STAmount saBalance{saAmount};
820
821 saBalance.get<Issue>().account = noAccount();
822
823 JLOG(j.debug()) << "directSendNoFeeIOU: "
824 "create line: "
825 << to_string(uSenderID) << " -> " << to_string(uReceiverID) << " : "
826 << saAmount.getFullText();
827
828 auto const sleAccount = view.peek(keylet::account(uReceiverID));
829 if (!sleAccount)
830 return tefINTERNAL; // LCOV_EXCL_LINE
831
832 bool const noRipple = !sleAccount->isFlag(lsfDefaultRipple);
833
834 return trustCreate(
835 view,
836 bSenderHigh,
837 uSenderID,
838 uReceiverID,
839 index.key,
840 sleAccount,
841 false,
842 noRipple,
843 false,
844 false,
845 saBalance,
846 saReceiverLimit,
847 0,
848 0,
849 sponsorSle,
850 j);
851}
852
853// Send regardless of limits.
854// --> saAmount: Amount/currency/issuer to deliver to receiver.
855// <-- saActual: Amount actually cost. Sender pays fees.
856static TER
858 ApplyView& view,
859 AccountID const& uSenderID,
860 AccountID const& uReceiverID,
861 STAmount const& saAmount,
862 STAmount& saActual,
864 SLE::Ref sponsorSle,
865 WaiveTransferFee waiveFee)
866{
867 auto const& issuer = saAmount.getIssuer();
868
869 XRPL_ASSERT(
870 !isXRP(uSenderID) && !isXRP(uReceiverID),
871 "xrpl::directSendNoLimitIOU : neither sender nor receiver is XRP");
872 XRPL_ASSERT(uSenderID != uReceiverID, "xrpl::directSendNoLimitIOU : sender is not receiver");
873
874 if (uSenderID == issuer || uReceiverID == issuer || issuer == noAccount())
875 {
876 // Direct send: redeeming IOUs and/or sending own IOUs.
877 auto const ter =
878 directSendNoFeeIOU(view, uSenderID, uReceiverID, saAmount, false, sponsorSle, j);
879 if (!isTesSuccess(ter))
880 return ter;
881 saActual = saAmount;
882 return tesSUCCESS;
883 }
884
885 // Sending 3rd party IOUs: transit.
886
887 // Calculate the amount to transfer accounting
888 // for any transfer fees if the fee is not waived:
889 saActual = (waiveFee == WaiveTransferFee::Yes) ? saAmount
890 : multiply(saAmount, transferRate(view, issuer));
891
892 JLOG(j.debug()) << "directSendNoLimitIOU> " << to_string(uSenderID) << " - > "
893 << to_string(uReceiverID) << " : deliver=" << saAmount.getFullText()
894 << " cost=" << saActual.getFullText();
895
896 TER terResult = directSendNoFeeIOU(view, issuer, uReceiverID, saAmount, true, sponsorSle, j);
897
898 if (tesSUCCESS == terResult)
899 {
900 terResult = directSendNoFeeIOU(view, uSenderID, issuer, saActual, true, sponsorSle, j);
901 }
902
903 return terResult;
904}
905
906// Send regardless of limits.
907// --> receivers: Amount/currency/issuer to deliver to receivers.
908// <-- saActual: Amount actually cost to sender. Sender pays fees.
909static TER
911 ApplyView& view,
912 AccountID const& senderID,
913 Issue const& issue,
914 MultiplePaymentDestinations const& receivers,
915 STAmount& actual,
917 WaiveTransferFee waiveFee)
918{
919 auto const& issuer = issue.getIssuer();
920
921 XRPL_ASSERT(!isXRP(senderID), "xrpl::directSendNoLimitMultiIOU : sender is not XRP");
922
923 // These may diverge
924 STAmount takeFromSender{issue};
925 actual = takeFromSender;
926
927 // Failures return immediately.
928 for (auto const& r : receivers)
929 {
930 auto const& receiverID = r.first;
931 STAmount const amount{issue, r.second};
932
933 /* If we aren't sending anything or if the sender is the same as the
934 * receiver then we don't need to do anything.
935 */
936 if (!amount || (senderID == receiverID))
937 continue;
938
939 XRPL_ASSERT(!isXRP(receiverID), "xrpl::directSendNoLimitMultiIOU : receiver is not XRP");
940
941 if (senderID == issuer || receiverID == issuer || issuer == noAccount())
942 {
943 // Direct send: redeeming IOUs and/or sending own IOUs.
944 if (auto const ter =
945 directSendNoFeeIOU(view, senderID, receiverID, amount, false, {}, j);
946 !isTesSuccess(ter))
947 return ter;
948 actual += amount;
949 // Do not add amount to takeFromSender, because directSendNoFeeIOU took
950 // it.
951
952 continue;
953 }
954
955 // Sending 3rd party IOUs: transit.
956
957 // Calculate the amount to transfer accounting
958 // for any transfer fees if the fee is not waived:
959 STAmount const actualSend = (waiveFee == WaiveTransferFee::Yes)
960 ? amount
961 : multiply(amount, transferRate(view, issuer));
962 actual += actualSend;
963 takeFromSender += actualSend;
964
965 JLOG(j.debug()) << "directSendNoLimitMultiIOU> " << to_string(senderID) << " - > "
966 << to_string(receiverID) << " : deliver=" << amount.getFullText()
967 << " cost=" << actual.getFullText();
968
969 if (TER const terResult = directSendNoFeeIOU(view, issuer, receiverID, amount, true, {}, j))
970 return terResult;
971 }
972
973 if (senderID != issuer && takeFromSender)
974 {
975 if (TER const terResult =
976 directSendNoFeeIOU(view, senderID, issuer, takeFromSender, true, {}, j))
977 return terResult;
978 }
979
980 return tesSUCCESS;
981}
982
983static TER
985 ApplyView& view,
986 AccountID const& uSenderID,
987 AccountID const& uReceiverID,
988 STAmount const& saAmount,
990 SLE::Ref sponsorSle,
991 WaiveTransferFee waiveFee)
992{
993 if (saAmount < beast::kZero || saAmount.holds<MPTIssue>())
994 {
995 // LCOV_EXCL_START
996 JLOG(j.fatal()) << "accountSendIOU: negative amount or invalid asset";
997 return tecINTERNAL;
998 // LCOV_EXCL_STOP
999 }
1000
1001 /* If we aren't sending anything or if the sender is the same as the
1002 * receiver then we don't need to do anything.
1003 */
1004 if (!saAmount || (uSenderID == uReceiverID))
1005 return tesSUCCESS;
1006
1007 if (!saAmount.native())
1008 {
1009 STAmount saActual;
1010
1011 JLOG(j.trace()) << "accountSendIOU: " << to_string(uSenderID) << " -> "
1012 << to_string(uReceiverID) << " : " << saAmount.getFullText();
1013
1014 return directSendNoLimitIOU(
1015 view, uSenderID, uReceiverID, saAmount, saActual, j, sponsorSle, waiveFee);
1016 }
1017
1018 /* XRP send which does not check reserve and can do pure adjustment.
1019 * Note that sender or receiver may be null and this not a mistake; this
1020 * setup is used during pathfinding and it is carefully controlled to
1021 * ensure that transfers are balanced.
1022 */
1023 TER terResult(tesSUCCESS);
1024
1025 SLE::pointer const sender =
1026 uSenderID != beast::kZero ? view.peek(keylet::account(uSenderID)) : SLE::pointer();
1027 SLE::pointer const receiver =
1028 uReceiverID != beast::kZero ? view.peek(keylet::account(uReceiverID)) : SLE::pointer();
1029
1030 if (auto const stream = j.trace())
1031 {
1032 std::string senderBal("-");
1033 std::string receiverBal("-");
1034
1035 if (sender)
1036 senderBal = sender->getFieldAmount(sfBalance).getFullText();
1037
1038 if (receiver)
1039 receiverBal = receiver->getFieldAmount(sfBalance).getFullText();
1040
1041 stream << "accountSendIOU> " << to_string(uSenderID) << " (" << senderBal << ") -> "
1042 << to_string(uReceiverID) << " (" << receiverBal << ") : " << saAmount.getFullText();
1043 }
1044
1045 if (sender)
1046 {
1047 if (sender->getFieldAmount(sfBalance) < saAmount)
1048 {
1049 // VFALCO Its laborious to have to mutate the
1050 // TER based on params everywhere
1051 // LCOV_EXCL_START
1052 terResult = view.open() ? TER{telFAILED_PROCESSING} : TER{tecFAILED_PROCESSING};
1053 // LCOV_EXCL_STOP
1054 }
1055 else
1056 {
1057 auto const sndBal = sender->getFieldAmount(sfBalance);
1058 view.creditHookIOU(uSenderID, xrpAccount(), saAmount, sndBal);
1059
1060 // Decrement XRP balance.
1061 sender->setFieldAmount(sfBalance, sndBal - saAmount);
1062 view.update(sender);
1063 }
1064 }
1065
1066 if (tesSUCCESS == terResult && receiver)
1067 {
1068 // Increment XRP balance.
1069 auto const rcvBal = receiver->getFieldAmount(sfBalance);
1070 receiver->setFieldAmount(sfBalance, rcvBal + saAmount);
1071 view.creditHookIOU(xrpAccount(), uReceiverID, saAmount, -rcvBal);
1072
1073 view.update(receiver);
1074 }
1075
1076 if (auto const stream = j.trace())
1077 {
1078 std::string senderBal("-");
1079 std::string receiverBal("-");
1080
1081 if (sender)
1082 senderBal = sender->getFieldAmount(sfBalance).getFullText();
1083
1084 if (receiver)
1085 receiverBal = receiver->getFieldAmount(sfBalance).getFullText();
1086
1087 stream << "accountSendIOU< " << to_string(uSenderID) << " (" << senderBal << ") -> "
1088 << to_string(uReceiverID) << " (" << receiverBal << ") : " << saAmount.getFullText();
1089 }
1090
1091 return terResult;
1092}
1093
1094static TER
1096 ApplyView& view,
1097 AccountID const& senderID,
1098 Issue const& issue,
1099 MultiplePaymentDestinations const& receivers,
1101 WaiveTransferFee waiveFee)
1102{
1103 XRPL_ASSERT_PARTS(
1104 receivers.size() > 1, "xrpl::accountSendMultiIOU", "multiple recipients provided");
1105
1106 if (!issue.native())
1107 {
1108 STAmount actual;
1109 JLOG(j.trace()) << "accountSendMultiIOU: " << to_string(senderID) << " sending "
1110 << receivers.size() << " IOUs";
1111
1112 return directSendNoLimitMultiIOU(view, senderID, issue, receivers, actual, j, waiveFee);
1113 }
1114
1115 /* XRP send which does not check reserve and can do pure adjustment.
1116 * Note that sender or receiver may be null and this not a mistake; this
1117 * setup could be used during pathfinding and it is carefully controlled to
1118 * ensure that transfers are balanced.
1119 */
1120
1121 SLE::pointer const sender =
1122 senderID != beast::kZero ? view.peek(keylet::account(senderID)) : SLE::pointer();
1123
1124 if (auto const stream = j.trace())
1125 {
1126 std::string senderBal("-");
1127
1128 if (sender)
1129 senderBal = sender->getFieldAmount(sfBalance).getFullText();
1130
1131 stream << "accountSendMultiIOU> " << to_string(senderID) << " (" << senderBal << ") -> "
1132 << receivers.size() << " receivers.";
1133 }
1134
1135 // Failures return immediately.
1136 STAmount takeFromSender{issue};
1137 for (auto const& r : receivers)
1138 {
1139 auto const& receiverID = r.first;
1140 STAmount const amount{issue, r.second};
1141
1142 if (amount < beast::kZero)
1143 {
1144 return tecINTERNAL; // LCOV_EXCL_LINE
1145 }
1146
1147 /* If we aren't sending anything or if the sender is the same as the
1148 * receiver then we don't need to do anything.
1149 */
1150 if (!amount || (senderID == receiverID))
1151 continue;
1152
1153 SLE::pointer const receiver =
1154 receiverID != beast::kZero ? view.peek(keylet::account(receiverID)) : SLE::pointer();
1155
1156 if (auto const stream = j.trace())
1157 {
1158 std::string receiverBal("-");
1159
1160 if (receiver)
1161 receiverBal = receiver->getFieldAmount(sfBalance).getFullText();
1162
1163 stream << "accountSendMultiIOU> " << to_string(senderID) << " -> "
1164 << to_string(receiverID) << " (" << receiverBal
1165 << ") : " << amount.getFullText();
1166 }
1167
1168 if (receiver)
1169 {
1170 // Confirm the running debit will not overflow before crediting.
1171 if (!checkedAdd(takeFromSender.xrp().drops(), amount.xrp().drops()))
1172 return tecINTERNAL;
1173
1174 // Increment XRP balance.
1175 auto const rcvBal = receiver->getFieldAmount(sfBalance);
1176 receiver->setFieldAmount(sfBalance, rcvBal + amount);
1177 view.creditHookIOU(xrpAccount(), receiverID, amount, -rcvBal);
1178
1179 view.update(receiver);
1180
1181 // Take what is actually sent.
1182 takeFromSender += amount;
1183 }
1184
1185 if (auto const stream = j.trace())
1186 {
1187 std::string receiverBal("-");
1188
1189 if (receiver)
1190 receiverBal = receiver->getFieldAmount(sfBalance).getFullText();
1191
1192 stream << "accountSendMultiIOU< " << to_string(senderID) << " -> "
1193 << to_string(receiverID) << " (" << receiverBal
1194 << ") : " << amount.getFullText();
1195 }
1196 }
1197
1198 if (sender)
1199 {
1200 if (sender->getFieldAmount(sfBalance) < takeFromSender)
1201 {
1202 return TER{tecFAILED_PROCESSING};
1203 }
1204 auto const sndBal = sender->getFieldAmount(sfBalance);
1205 view.creditHookIOU(senderID, xrpAccount(), takeFromSender, sndBal);
1206
1207 // Decrement XRP balance.
1208 sender->setFieldAmount(sfBalance, sndBal - takeFromSender);
1209 view.update(sender);
1210 }
1211
1212 if (auto const stream = j.trace())
1213 {
1214 std::string senderBal("-");
1215
1216 if (sender)
1217 senderBal = sender->getFieldAmount(sfBalance).getFullText();
1218
1219 stream << "accountSendMultiIOU< " << to_string(senderID) << " (" << senderBal << ") -> "
1220 << receivers.size() << " receivers.";
1221 }
1222 return tesSUCCESS;
1223}
1224
1225static TER
1227 ApplyView& view,
1228 AccountID const& uSenderID,
1229 AccountID const& uReceiverID,
1230 STAmount const& saAmount,
1232{
1233 // Do not check MPT authorization here - it must have been checked earlier
1234 auto const mptID = keylet::mptokenIssuance(saAmount.get<MPTIssue>().getMptID());
1235 auto const& issuer = saAmount.getIssuer();
1236 auto const sleIssuance = view.peek(mptID);
1237 if (!sleIssuance)
1238 return tecOBJECT_NOT_FOUND;
1239
1240 auto const maxAmount = maxMPTAmount(*sleIssuance);
1241 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
1242 auto const available = availableMPTAmount(*sleIssuance);
1243 auto const amt = saAmount.mpt().value();
1244
1245 if (uSenderID == issuer)
1246 {
1247 if (view.rules().enabled(featureMPTokensV2))
1248 {
1249 if (isMPTOverflow(amt, outstanding, maxAmount, AllowMPTOverflow::Yes))
1250 return tecPATH_DRY;
1251 }
1252 (*sleIssuance)[sfOutstandingAmount] += amt;
1253 view.update(sleIssuance);
1254 }
1255 else
1256 {
1257 auto const mptokenID = keylet::mptoken(mptID.key, uSenderID);
1258 if (auto const sle = view.peek(mptokenID))
1259 {
1260 auto const senderBalance = sle->getFieldU64(sfMPTAmount);
1261 if (senderBalance < amt)
1262 return tecINSUFFICIENT_FUNDS;
1263 view.creditHookMPT(uSenderID, uReceiverID, saAmount, (*sle)[sfMPTAmount], available);
1264 (*sle)[sfMPTAmount] = senderBalance - amt;
1265 view.update(sle);
1266 }
1267 else
1268 {
1269 return tecNO_AUTH;
1270 }
1271 }
1272
1273 if (uReceiverID == issuer)
1274 {
1275 if (outstanding >= amt)
1276 {
1277 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - amt);
1278 view.update(sleIssuance);
1279 }
1280 else
1281 {
1282 return tecINTERNAL; // LCOV_EXCL_LINE
1283 }
1284 }
1285 else
1286 {
1287 auto const mptokenID = keylet::mptoken(mptID.key, uReceiverID);
1288 if (auto const sle = view.peek(mptokenID))
1289 {
1290 if (view.rules().enabled(featureMPTokensV2))
1291 {
1292 if ((*sle)[sfMPTAmount] > (std::numeric_limits<std::uint64_t>::max() - amt))
1293 {
1294 return tecINTERNAL; // LCOV_EXCL_LINE
1295 }
1296 }
1297 view.creditHookMPT(uSenderID, uReceiverID, saAmount, (*sle)[sfMPTAmount], available);
1298 (*sle)[sfMPTAmount] += amt;
1299 view.update(sle);
1300 }
1301 else
1302 {
1303 return tecNO_AUTH;
1304 }
1305 }
1306
1307 return tesSUCCESS;
1308}
1309
1310static TER
1312 ApplyView& view,
1313 AccountID const& uSenderID,
1314 AccountID const& uReceiverID,
1315 STAmount const& saAmount,
1316 STAmount& saActual,
1318 WaiveTransferFee waiveFee,
1319 AllowMPTOverflow allowOverflow)
1320{
1321 XRPL_ASSERT(uSenderID != uReceiverID, "xrpl::directSendNoLimitMPT : sender is not receiver");
1322
1323 // Safe to get MPT since directSendNoLimitMPT is only called by accountSendMPT
1324 auto const& issuer = saAmount.getIssuer();
1325
1326 auto const sle = view.read(keylet::mptokenIssuance(saAmount.get<MPTIssue>().getMptID()));
1327 if (!sle)
1328 return tecOBJECT_NOT_FOUND;
1329
1330 if (uSenderID == issuer || uReceiverID == issuer)
1331 {
1332 // if sender is issuer, check that the new OutstandingAmount will not
1333 // exceed MaximumAmount
1334 if (uSenderID == issuer)
1335 {
1336 auto const sendAmount = saAmount.mpt().value();
1337 auto const maxAmount = maxMPTAmount(*sle);
1338 auto const outstanding = sle->getFieldU64(sfOutstandingAmount);
1339 auto const mptokensV2 = view.rules().enabled(featureMPTokensV2);
1340 allowOverflow = (allowOverflow == AllowMPTOverflow::Yes && mptokensV2)
1343 if (isMPTOverflow(sendAmount, outstanding, maxAmount, allowOverflow))
1344 return tecPATH_DRY;
1345 }
1346
1347 // Direct send: redeeming MPTs and/or sending own MPTs.
1348 auto const ter = directSendNoFeeMPT(view, uSenderID, uReceiverID, saAmount, j);
1349 if (!isTesSuccess(ter))
1350 return ter;
1351 saActual = saAmount;
1352 return tesSUCCESS;
1353 }
1354
1355 // Sending 3rd party MPTs: transit.
1356 if (waiveFee == WaiveTransferFee::Yes)
1357 {
1358 saActual = saAmount;
1359 }
1360 else
1361 {
1362 auto const rate = transferRate(view, saAmount.get<MPTIssue>().getMptID());
1363 if (view.rules().enabled(fixCleanup3_5_0))
1364 {
1365 // Number math loses precision on large MPT amounts, which can
1366 // overcharge the sender. MPTs are integral, so compute the cost
1367 // exactly, matching the payment engine.
1368 saActual = addTransferFee(saAmount, rate);
1369 }
1370 else
1371 {
1372 saActual = multiply(saAmount, rate);
1373 }
1374 }
1375
1376 JLOG(j.debug()) << "directSendNoLimitMPT> " << to_string(uSenderID) << " - > "
1377 << to_string(uReceiverID) << " : deliver=" << saAmount.getFullText()
1378 << " cost=" << saActual.getFullText();
1379
1380 if (auto const terResult = directSendNoFeeMPT(view, issuer, uReceiverID, saAmount, j);
1381 !isTesSuccess(terResult))
1382 return terResult;
1383
1384 return directSendNoFeeMPT(view, uSenderID, issuer, saActual, j);
1385}
1386
1387static TER
1389 ApplyView& view,
1390 AccountID const& senderID,
1391 MPTIssue const& mptIssue,
1392 MultiplePaymentDestinations const& receivers,
1393 STAmount& actual,
1395 WaiveTransferFee waiveFee)
1396{
1397 auto const& issuer = mptIssue.getIssuer();
1398
1399 auto const sle = view.read(keylet::mptokenIssuance(mptIssue.getMptID()));
1400 if (!sle)
1401 return tecOBJECT_NOT_FOUND;
1402
1403 // For the issuer-as-sender case, track the running total to validate
1404 // against MaximumAmount. The read-only SLE (view.read) is not updated
1405 // by directSendNoFeeMPT, so a per-iteration SLE read would be stale.
1406 // Use uint64_t, not STAmount, to keep MaximumAmount comparisons in exact
1407 // integer arithmetic. STAmount implicitly converts to Number, whose
1408 // small-scale mantissa (~16 digits) can lose precision for values near
1409 // kMaxMpTokenAmount (19 digits).
1410 std::uint64_t totalSendAmount{0};
1411 std::uint64_t const maximumAmount = sle->at(~sfMaximumAmount).value_or(kMaxMpTokenAmount);
1412 std::uint64_t const outstandingAmount = sle->getFieldU64(sfOutstandingAmount);
1413
1414 // actual accumulates the total cost to the sender (includes transfer
1415 // fees for third-party transit sends). takeFromSender accumulates only
1416 // the transit portion that is debited to the issuer in bulk after the
1417 // loop. They diverge when there are transfer fees.
1418 STAmount takeFromSender{mptIssue};
1419 actual = takeFromSender;
1420
1421 for (auto const& [receiverID, amt] : receivers)
1422 {
1423 STAmount const amount{mptIssue, amt};
1424
1425 if (amount < beast::kZero)
1426 return tecINTERNAL; // LCOV_EXCL_LINE
1427
1428 if (!amount || senderID == receiverID)
1429 continue;
1430
1431 if (senderID == issuer || receiverID == issuer)
1432 {
1433 if (senderID == issuer)
1434 {
1435 XRPL_ASSERT_PARTS(
1436 takeFromSender == beast::kZero,
1437 "xrpl::directSendNoLimitMultiMPT",
1438 "sender == issuer, takeFromSender == zero");
1439
1440 std::uint64_t const sendAmount = amount.mpt().value();
1441
1442 if (view.rules().enabled(fixCleanup3_1_3))
1443 {
1444 // Post-fixCleanup3_1_3: aggregate MaximumAmount
1445 // check. WARNING: the order of conditions is
1446 // critical — each guards the subtraction in the
1447 // next against unsigned underflow. Do not reorder.
1448 bool const exceedsMaximumAmount =
1449 // This send alone exceeds the max cap
1450 sendAmount > maximumAmount ||
1451 // The aggregate of all sends exceeds the max cap
1452 totalSendAmount > maximumAmount - sendAmount ||
1453 // Outstanding + aggregate exceeds the max cap
1454 outstandingAmount > maximumAmount - sendAmount - totalSendAmount;
1455
1456 if (exceedsMaximumAmount)
1457 return tecPATH_DRY;
1458 totalSendAmount += sendAmount;
1459 }
1460 else
1461 {
1462 // Pre-fixCleanup3_1_3: per-iteration MaximumAmount
1463 // check. Reads sfOutstandingAmount from a stale
1464 // view.read() snapshot — incorrect for multi-destination
1465 // sends but retained for ledger replay compatibility.
1466 if (sendAmount > maximumAmount ||
1467 outstandingAmount > maximumAmount - sendAmount)
1468 return tecPATH_DRY;
1469 }
1470 }
1471
1472 // Direct send: redeeming MPTs and/or sending own MPTs.
1473 if (!checkedAdd(actual.mpt().value(), amount.mpt().value()))
1474 return tecINTERNAL;
1475 if (auto const ter = directSendNoFeeMPT(view, senderID, receiverID, amount, j);
1476 !isTesSuccess(ter))
1477 return ter;
1478 actual += amount;
1479 // Do not add amount to takeFromSender, because directSendNoFeeMPT took it.
1480
1481 continue;
1482 }
1483
1484 // Sending 3rd party MPTs: transit.
1485 STAmount actualSend = amount;
1486 if (waiveFee != WaiveTransferFee::Yes)
1487 {
1488 auto const rate = transferRate(view, amount.get<MPTIssue>().getMptID());
1489 if (view.rules().enabled(fixCleanup3_5_0))
1490 {
1491 // Number math loses precision on large MPT amounts, which can
1492 // overcharge the sender. MPTs are integral, so compute the
1493 // cost exactly, matching the payment engine.
1494 actualSend = addTransferFee(amount, rate);
1495 }
1496 else
1497 {
1498 actualSend = multiply(amount, rate);
1499 }
1500 }
1501 // actual is a superset of takeFromSender, so checking it before both add
1502 // sites also protects the debit accumulator.
1503 if (!checkedAdd(actual.mpt().value(), actualSend.mpt().value()))
1504 return tecINTERNAL;
1505 actual += actualSend;
1506 takeFromSender += actualSend;
1507
1508 JLOG(j.debug()) << "directSendNoLimitMultiMPT> " << to_string(senderID) << " - > "
1509 << to_string(receiverID) << " : deliver=" << amount.getFullText()
1510 << " cost=" << actualSend.getFullText();
1511
1512 if (auto const ter = directSendNoFeeMPT(view, issuer, receiverID, amount, j);
1513 !isTesSuccess(ter))
1514 return ter;
1515 }
1516 if (senderID != issuer && takeFromSender)
1517 {
1518 if (auto const ter = directSendNoFeeMPT(view, senderID, issuer, takeFromSender, j);
1519 !isTesSuccess(ter))
1520 return ter;
1521 }
1522
1523 return tesSUCCESS;
1524}
1525
1526static TER
1528 ApplyView& view,
1529 AccountID const& uSenderID,
1530 AccountID const& uReceiverID,
1531 STAmount const& saAmount,
1533 WaiveTransferFee waiveFee,
1534 AllowMPTOverflow allowOverflow)
1535{
1536 XRPL_ASSERT(
1537 saAmount >= beast::kZero && saAmount.holds<MPTIssue>(),
1538 "xrpl::accountSendMPT : minimum amount and MPT");
1539
1540 /* If we aren't sending anything or if the sender is the same as the
1541 * receiver then we don't need to do anything.
1542 */
1543 if (!saAmount || (uSenderID == uReceiverID))
1544 return tesSUCCESS;
1545
1546 STAmount saActual{saAmount.asset()};
1547
1548 return directSendNoLimitMPT(
1549 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee, allowOverflow);
1550}
1551
1552static TER
1554 ApplyView& view,
1555 AccountID const& senderID,
1556 MPTIssue const& mptIssue,
1557 MultiplePaymentDestinations const& receivers,
1559 WaiveTransferFee waiveFee)
1560{
1561 STAmount actual;
1562
1563 return directSendNoLimitMultiMPT(view, senderID, mptIssue, receivers, actual, j, waiveFee);
1564}
1565
1566//------------------------------------------------------------------------------
1567//
1568// Public Dispatcher Functions
1569//
1570//------------------------------------------------------------------------------
1571
1572TER
1574 ApplyView& view,
1575 AccountID const& uSenderID,
1576 AccountID const& uReceiverID,
1577 STAmount const& saAmount,
1578 bool bCheckIssuer,
1580{
1581 return saAmount.asset().visit(
1582 [&](Issue const&) {
1583 return directSendNoFeeIOU(view, uSenderID, uReceiverID, saAmount, bCheckIssuer, {}, j);
1584 },
1585 [&](MPTIssue const&) {
1586 XRPL_ASSERT(!bCheckIssuer, "xrpl::directSendNoFee : not checking issuer");
1587 return directSendNoFeeMPT(view, uSenderID, uReceiverID, saAmount, j);
1588 });
1589}
1590
1591TER
1593 ApplyView& view,
1594 AccountID const& uSenderID,
1595 AccountID const& uReceiverID,
1596 STAmount const& saAmount,
1598 SLE::Ref sponsorSle,
1599 WaiveTransferFee waiveFee,
1600 AllowMPTOverflow allowOverflow)
1601{
1602 return saAmount.asset().visit(
1603 [&](Issue const&) {
1604 return accountSendIOU(view, uSenderID, uReceiverID, saAmount, j, sponsorSle, waiveFee);
1605 },
1606 [&](MPTIssue const&) {
1607 return accountSendMPT(
1608 view, uSenderID, uReceiverID, saAmount, j, waiveFee, allowOverflow);
1609 });
1610}
1611
1612TER
1614 ApplyView& view,
1615 AccountID const& senderID,
1616 Asset const& asset,
1617 MultiplePaymentDestinations const& receivers,
1619 WaiveTransferFee waiveFee)
1620{
1621 XRPL_ASSERT_PARTS(
1622 receivers.size() > 1, "xrpl::accountSendMulti", "multiple recipients provided");
1623 return asset.visit(
1624 [&](Issue const& issue) {
1625 return accountSendMultiIOU(view, senderID, issue, receivers, j, waiveFee);
1626 },
1627 [&](MPTIssue const& issue) {
1628 return accountSendMultiMPT(view, senderID, issue, receivers, j, waiveFee);
1629 });
1630}
1631
1632TER
1634 ApplyView& view,
1635 AccountID const& from,
1636 AccountID const& to,
1637 STAmount const& amount,
1639{
1640 XRPL_ASSERT(from != beast::kZero, "xrpl::transferXRP : nonzero from account");
1641 XRPL_ASSERT(to != beast::kZero, "xrpl::transferXRP : nonzero to account");
1642 XRPL_ASSERT(from != to, "xrpl::transferXRP : sender is not receiver");
1643 XRPL_ASSERT(amount.native(), "xrpl::transferXRP : amount is XRP");
1644
1645 SLE::pointer const sender = view.peek(keylet::account(from));
1646 SLE::pointer const receiver = view.peek(keylet::account(to));
1647 if (!sender || !receiver)
1648 return tefINTERNAL; // LCOV_EXCL_LINE
1649
1650 JLOG(j.trace()) << "transferXRP: " << to_string(from) << " -> " << to_string(to)
1651 << ") : " << amount.getFullText();
1652
1653 if (sender->getFieldAmount(sfBalance) < amount)
1654 {
1655 // VFALCO Its unfortunate we have to keep
1656 // mutating these TER everywhere
1657 // FIXME: this logic should be moved to callers maybe?
1658 // LCOV_EXCL_START
1660 // LCOV_EXCL_STOP
1661 }
1662
1663 // Decrement XRP balance.
1664 sender->setFieldAmount(sfBalance, sender->getFieldAmount(sfBalance) - amount);
1665 view.update(sender);
1666
1667 receiver->setFieldAmount(sfBalance, receiver->getFieldAmount(sfBalance) + amount);
1668 view.update(receiver);
1669
1670 return tesSUCCESS;
1671}
1672
1673} // namespace xrpl
T any_of(T... args)
A generic endpoint for log messages.
Definition Journal.h:44
Stream fatal() const
Definition Journal.h:368
Stream debug() const
Definition Journal.h:344
Stream trace() const
Severity stream access functions.
Definition Journal.h:338
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:141
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void creditHookIOU(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance)
Definition ApplyView.h:248
virtual void creditHookMPT(AccountID const &from, AccountID const &to, STAmount const &amount, std::uint64_t preCreditBalanceHolder, std::int64_t preCreditBalanceIssuer)
Definition ApplyView.h:258
virtual void update(SLE::Ref sle)=0
Indicate changes to a peeked SLE.
constexpr auto visit(Visitors &&... visitors) const -> decltype(auto)
Definition Asset.h:117
constexpr TIss const & get() const
AccountID const & getIssuer() const
Definition Asset.cpp:21
constexpr bool holds() const
Definition Asset.h:177
constexpr value_type const & value() const
Definition Asset.h:201
A currency issued by an account.
Definition Issue.h:18
Currency currency
Definition Issue.h:20
AccountID account
Definition Issue.h:21
bool native() const
Definition Issue.cpp:54
AccountID const & getIssuer() const
Definition Issue.h:30
constexpr value_type value() const
Returns the underlying value.
Definition MPTAmount.h:135
constexpr MPTID const & getMptID() const
Definition MPTIssue.h:43
AccountID const & getIssuer() const
Definition MPTIssue.cpp:29
A view into a ledger.
Definition ReadView.h:41
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual STAmount balanceHookMPT(AccountID const &account, MPTIssue const &issue, std::int64_t amount) const
Definition ReadView.h:190
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
virtual bool open() const =0
Returns true if this reflects an open ledger.
virtual STAmount balanceHookIOU(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
Definition ReadView.h:180
bool enabled(UInt256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:182
constexpr bool holds() const noexcept
Definition STAmount.h:478
constexpr TIss const & get() const
std::string getFullText() const override
void negate()
Definition STAmount.h:586
bool native() const noexcept
Definition STAmount.h:471
Asset const & asset() const
Definition STAmount.h:496
AccountID const & getIssuer() const
Definition STAmount.h:516
static constexpr std::uint64_t kMaxValue
Definition STAmount.h:67
static constexpr int kMaxOffset
Definition STAmount.h:62
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & ConstRef
std::shared_ptr< STLedgerEntry > const & Ref
std::shared_ptr< STLedgerEntry const > const_pointer
void setFieldAmount(SField const &field, STAmount const &)
Definition STObject.cpp:803
STAmount const & getFieldAmount(SField const &field) const
Definition STObject.cpp:657
constexpr value_type drops() const
Returns the number of drops.
Definition XRPAmount.h:163
T max(T... args)
constexpr Zero kZero
Definition Zero.h:30
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Definition Indexes.cpp:483
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Definition Indexes.cpp:547
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:233
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
Definition Indexes.cpp:541
Keylet trustLine(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition Indexes.cpp:287
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
void removeSponsorFromLedgerEntry(SLE::Ref sle, SF_ACCOUNT const &field=sfSponsor)
Remove the reserve sponsor field from a ledger entry.
TER checkDeepFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
@ telFAILED_PROCESSING
Definition TER.h:42
@ terNO_RIPPLE
Definition TER.h:226
@ terNO_ACCOUNT
Definition TER.h:219
std::int64_t maxMPTAmount(SLE const &sleIssuance)
MaximumAmount doesn't exceed 2**63-1.
constexpr std::optional< std::int64_t > checkedAdd(std::int64_t a, std::int64_t b) noexcept
Add two signed 64-bit integers, returning std::nullopt when the exact mathematical sum is not represe...
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
Calculate liquid XRP balance for an account.
FreezeHandling
Controls the treatment of frozen account balances.
static TER directSendNoLimitMultiIOU(ApplyView &view, AccountID const &senderID, Issue const &issue, MultiplePaymentDestinations const &receivers, STAmount &actual, beast::Journal j, WaiveTransferFee waiveFee)
static STAmount getTrustLineBalance(ReadView const &view, SLE::ConstRef sle, AccountID const &account, Currency const &currency, AccountID const &issuer, bool includeOppositeLimit, beast::Journal j)
SpendableHandling
Controls whether to include the account's full spendable balance.
STAmount subtractTransferFee(STAmount const &amount, Rate const &rate)
Returns the amount a receiver gets when amount leaves the sender and the issuer takes the transfer fe...
TER checkIndividualFrozen(ReadView const &view, AccountID const &account, Asset const &asset)
bool isXRP(AccountID const &c)
Definition AccountID.h:84
bool isIndividualFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue)
Returns true if account's MPToken for mptIssue carries the individual-lock flag (lsfMPTLocked).
TER checkDepositFreeze(ReadView const &view, AccountID const &srcAcct, AccountID const &pseudoAcct, Asset const &asset)
Checks freeze compliance for depositing an asset into a pseudo-account (e.g.
AllowMPTOverflow
Controls whether accountSend is allowed to overflow OutstandingAmount *.
static TER accountSendMultiIOU(ApplyView &view, AccountID const &senderID, Issue const &issue, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee)
TER removeEmptyHolding(ApplyViewContext ctx, AccountID const &accountID, MPTIssue const &mptIssue, beast::Journal journal)
TER checkFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
@ tefINTERNAL
Definition TER.h:167
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition UintTypes.h:42
TER addEmptyHolding(ApplyViewContext ctx, AccountID const &accountID, XRPAmount priorBalance, MPTIssue const &mptIssue, beast::Journal journal)
WaiveTransferFee
TER trustCreate(ApplyView &view, bool const bSrcHigh, AccountID const &uSrcAccountID, AccountID const &uDstAccountID, UInt256 const &uIndex, SLE::Ref sleAccount, bool const bAuth, bool const bNoRipple, bool const bFreeze, bool bDeepFreeze, STAmount const &saBalance, STAmount const &saLimit, std::uint32_t uQualityIn, std::uint32_t uQualityOut, SLE::Ref sponsorSle, beast::Journal j)
Create a trust line.
TER canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to, WaiveMPTCanTransfer waive=WaiveMPTCanTransfer::No, std::uint8_t depth=0)
Check whether to may receive the given MPT from from.
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
static TER directSendNoFeeIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, SLE::Ref sponsorSle, beast::Journal j)
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
bool isVaultPseudoAccountFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptShare, std::uint8_t depth)
Definition View.cpp:160
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
static TER directSendNoLimitIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, STAmount &saActual, beast::Journal j, SLE::Ref sponsorSle, WaiveTransferFee waiveFee)
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
Check if the issuer has the global freeze flag set.
TER canTransferLPToken(ReadView const &view, AccountID const &from, AccountID const &to, AccountID const &lpTokenIssuer)
Check whether an AMM LPToken may be transferred between from and to.
Definition View.cpp:187
TER canAddHolding(ReadView const &view, MPTIssue const &mptIssue)
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, SLE::Ref sponsorSle={}, WaiveTransferFee waiveFee=WaiveTransferFee::No, AllowMPTOverflow allowOverflow=AllowMPTOverflow::No)
Calls static accountSendIOU if saAmount represents Issue.
void decreaseOwnerCount(ApplyView &view, SLE::Ref accountSle, SLE::Ref sponsorSle, std::uint32_t count, beast::Journal j)
Decrease owner-count fields when the caller supplies the sponsor.
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
AuthHandling
Controls the treatment of unauthorized MPT balances.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
static SLE::const_pointer getLineIfUsable(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
Rate const kParityRate
A transfer rate signifying a 1:1 exchange.
TER directSendNoFee(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
Calls static directSendNoFeeIOU if saAmount represents Issue.
std::int64_t availableMPTAmount(SLE const &sleIssuance)
OutstandingAmount may overflow and available amount might be negative.
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
WaiveMPTCanTransfer
Controls whether canTransfer enforces lsfMPTCanTransfer on MPTs.
bool isFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue, std::uint8_t depth=0)
Returns true if account cannot send or receive tokens of mptIssue because a freeze applies.
TER checkGlobalFrozen(ReadView const &view, Asset const &asset)
bool isPseudoAccount(SLE::const_pointer sleAcct)
Returns true if and only if sleAcct is a pseudo-account of any kind (i.e.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
AccountID const & noAccount()
A placeholder for empty accounts.
static TER directSendNoLimitMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, STAmount &saActual, beast::Journal j, WaiveTransferFee waiveFee, AllowMPTOverflow allowOverflow)
static TER accountSendMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee, AllowMPTOverflow allowOverflow)
bool isTesSuccess(TER x) noexcept
Definition TER.h:686
bool isAnyFrozen(ReadView const &view, std::initializer_list< AccountID > const &accounts, MPTIssue const &mptIssue, std::uint8_t depth=0)
SLE::pointer getLedgerEntryReserveSponsor(ApplyView &view, SLE::ConstRef sle, SF_ACCOUNT const &field=sfSponsor)
Return a mutable SLE for the reserve sponsor recorded on a ledger entry.
TERSubset< CanCvtToTER > TER
Definition TER.h:657
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Asset const &asset, Asset const &asset2)
Definition View.cpp:177
STAmount addTransferFee(STAmount const &amount, Rate const &rate)
Returns the amount a sender must part with for amount to reach the receiver once the issuer takes the...
TER requireAuth(ReadView const &view, MPTIssue const &mptIssue, AccountID const &account, AuthType authType=AuthType::Legacy, std::uint8_t depth=0)
Check if the account lacks required authorization for MPT.
static TER directSendNoLimitMultiMPT(ApplyView &view, AccountID const &senderID, MPTIssue const &mptIssue, MultiplePaymentDestinations const &receivers, STAmount &actual, beast::Journal j, WaiveTransferFee waiveFee)
AccountID const & xrpAccount()
Compute AccountID from public key.
@ tecLOCKED
Definition TER.h:369
@ tecPATH_DRY
Definition TER.h:305
@ tecOBJECT_NOT_FOUND
Definition TER.h:337
@ tecNO_AUTH
Definition TER.h:311
@ tecINTERNAL
Definition TER.h:321
@ tecFAILED_PROCESSING
Definition TER.h:297
@ tecFROZEN
Definition TER.h:314
@ tecINSUFFICIENT_FUNDS
Definition TER.h:336
STAmount multiply(STAmount const &amount, Number const &frac, Number::RoundingMode rm)
static TER accountSendMultiMPT(ApplyView &view, AccountID const &senderID, MPTIssue const &mptIssue, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee)
std::vector< std::pair< AccountID, Number > > MultiplePaymentDestinations
TER accountSendMulti(ApplyView &view, AccountID const &senderID, Asset const &asset, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Like accountSend, except one account is sending multiple payments (with the same asset!...
constexpr std::uint64_t kMaxMpTokenAmount
The maximum amount of MPTokenIssuance.
Definition Protocol.h:297
TER trustDelete(ApplyView &view, SLE::Ref sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
TER checkWithdrawFreeze(ReadView const &view, AccountID const &pseudoAcct, AccountID const &submitterAcct, AccountID const &dstAcct, Asset const &asset)
Checks freeze compliance for withdrawing an asset from a pseudo-account (e.g.
bool isMPTOverflow(std::int64_t sendAmount, std::uint64_t outstandingAmount, std::int64_t maximumAmount, AllowMPTOverflow allowOverflow)
Checks for two types of OutstandingAmount overflow during a send operation.
static TER accountSendIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, SLE::Ref sponsorSle, WaiveTransferFee waiveFee)
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j, SpendableHandling includeFullBalance=SpendableHandling::SimpleBalance)
@ tesSUCCESS
Definition TER.h:253
bool holdingExists(ReadView const &view, AccountID const &account, Asset const &asset)
True if the account already holds this asset (or is the issuer / XRP).
static TER directSendNoFeeMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j)
T size(T... args)
Bundles the mutable ledger view and the transaction being applied.
Definition ApplyView.h:451
Represents a transfer rate.
Definition Rate.h:21
std::uint32_t value
Definition Rate.h:22
T visit(T... args)