xrpld
Loading...
Searching...
No Matches
CheckCash.cpp
1#include <xrpl/tx/transactors/check/CheckCash.h>
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/scope.h>
5#include <xrpl/beast/utility/Zero.h>
6#include <xrpl/core/ServiceRegistry.h>
7#include <xrpl/ledger/ApplyView.h>
8#include <xrpl/ledger/PaymentSandbox.h>
9#include <xrpl/ledger/View.h>
10#include <xrpl/ledger/entries/CheckEntry.h>
11#include <xrpl/ledger/helpers/AccountRootHelpers.h>
12#include <xrpl/ledger/helpers/MPTokenHelpers.h>
13#include <xrpl/ledger/helpers/RippleStateHelpers.h>
14#include <xrpl/ledger/helpers/SponsorHelpers.h>
15#include <xrpl/ledger/helpers/TokenHelpers.h>
16#include <xrpl/protocol/AccountID.h>
17#include <xrpl/protocol/Asset.h>
18#include <xrpl/protocol/Feature.h>
19#include <xrpl/protocol/Indexes.h>
20#include <xrpl/protocol/Issue.h>
21#include <xrpl/protocol/Keylet.h>
22#include <xrpl/protocol/LedgerFormats.h>
23#include <xrpl/protocol/MPTAmount.h>
24#include <xrpl/protocol/MPTIssue.h>
25#include <xrpl/protocol/Quality.h>
26#include <xrpl/protocol/SField.h>
27#include <xrpl/protocol/STAmount.h>
28#include <xrpl/protocol/STLedgerEntry.h>
29#include <xrpl/protocol/STTx.h>
30#include <xrpl/protocol/TER.h>
31#include <xrpl/protocol/UintTypes.h>
32#include <xrpl/protocol/XRPAmount.h>
33#include <xrpl/tx/Transactor.h>
34#include <xrpl/tx/paths/Flow.h>
35#include <xrpl/tx/paths/detail/Steps.h>
36
37#include <algorithm>
38#include <memory>
39#include <optional>
40
41namespace xrpl {
42
43bool
45{
46 auto const optAmount = ctx.tx[~sfAmount];
47 auto const optDeliverMin = ctx.tx[~sfDeliverMin];
48
49 return ctx.rules.enabled(featureMPTokensV2) ||
50 (!(optAmount && optAmount->holds<MPTIssue>()) &&
51 !(optDeliverMin && optDeliverMin->holds<MPTIssue>()));
52}
53
56{
57 if (ctx.rules.enabled(fixCleanup3_3_0) && ctx.tx[sfCheckID] == beast::kZero)
58 return temMALFORMED;
59
60 // Exactly one of Amount or DeliverMin must be present.
61 auto const optAmount = ctx.tx[~sfAmount];
62 auto const optDeliverMin = ctx.tx[~sfDeliverMin];
63
64 if (static_cast<bool>(optAmount) == static_cast<bool>(optDeliverMin))
65 {
66 JLOG(ctx.j.debug()) << "Malformed transaction: "
67 "does not specify exactly one of Amount and DeliverMin.";
68 return temMALFORMED;
69 }
70
71 // Make sure the amount is valid.
72 STAmount const value{optAmount ? *optAmount : *optDeliverMin};
73 if (!isLegalNet(value) || value.signum() <= 0)
74 {
75 JLOG(ctx.j.debug()) << "Malformed transaction: bad amount: " << value.getFullText();
76 return temBAD_AMOUNT;
77 }
78
79 if (badAsset() == value.asset())
80 {
81 JLOG(ctx.j.debug()) << "Malformed transaction: Bad currency.";
82 return temBAD_CURRENCY;
83 }
84
85 return tesSUCCESS;
86}
87
88TER
90{
91 CheckEntryR const sleCheck(ctx.tx[sfCheckID], ctx.view);
92 if (!sleCheck)
93 {
94 JLOG(ctx.j.debug()) << "Check does not exist.";
95 return tecNO_ENTRY;
96 }
97
98 // Only cash a check with this account as the destination.
99 AccountID const dstId = sleCheck->at(sfDestination);
100 if (ctx.tx[sfAccount] != dstId)
101 {
102 JLOG(ctx.j.debug()) << "Cashing a check with wrong Destination.";
103 return tecNO_PERMISSION;
104 }
105 AccountID const srcId = sleCheck->at(sfAccount);
106 if (srcId == dstId)
107 {
108 // They wrote a check to themselves. This should be caught when
109 // the check is created, but better late than never.
110 // LCOV_EXCL_START
111 JLOG(ctx.j.error()) << "Malformed transaction: Cashing check to self.";
112 return tecINTERNAL;
113 // LCOV_EXCL_STOP
114 }
115 {
116 auto const sleSrc = ctx.view.read(keylet::account(srcId));
117 auto const sleDst = ctx.view.read(keylet::account(dstId));
118 if (!sleSrc || !sleDst)
119 {
120 // If the check exists this should never occur.
121 JLOG(ctx.j.debug()) << "Malformed transaction: source or destination not in ledger";
122 return tecNO_ENTRY;
123 }
124
125 if (sleDst->isFlag(lsfRequireDestTag) && !sleCheck->isFieldPresent(sfDestinationTag))
126 {
127 // The tag is basically account-specific information we don't
128 // understand, but we can require someone to fill it in.
129 JLOG(ctx.j.debug()) << "Malformed transaction: DestinationTag required in check.";
130 return tecDST_TAG_NEEDED;
131 }
132 }
133
134 if (hasExpired(ctx.view, sleCheck->at(~sfExpiration)))
135 {
136 JLOG(ctx.j.debug()) << "Cashing a check that has already expired.";
137 return tecEXPIRED;
138 }
139
140 {
141 // Preflight verified exactly one of Amount or DeliverMin is present.
142 // Make sure the requested amount is reasonable.
143 STAmount const value{
144 [](STTx const& tx) {
145 auto const optAmount = tx[~sfAmount];
146 return optAmount ? *optAmount : tx[sfDeliverMin];
147 }(ctx.tx),
148 };
149
150 STAmount const sendMax = sleCheck->at(sfSendMax);
151 // A legacy Check may contain a non-canonical MPT sfSendMax. Universal
152 // preflight only validates the CheckCash transaction, not the stored Check.
153 if (ctx.view.rules().enabled(fixCleanup3_2_0) && !isLegalMPT(sendMax))
154 return tefBAD_LEDGER;
155
156 if (!equalTokens(value.asset(), sendMax.asset()))
157 {
158 JLOG(ctx.j.debug()) << "Check cash does not match check currency.";
159 return temMALFORMED;
160 }
161 AccountID const issuerId{value.getIssuer()};
162 if (issuerId != sendMax.getIssuer())
163 {
164 JLOG(ctx.j.debug()) << "Check cash does not match check issuer.";
165 return temMALFORMED;
166 }
167 if (value > sendMax)
168 {
169 JLOG(ctx.j.debug()) << "Check cashed for more than check sendMax.";
170 return tecPATH_PARTIAL;
171 }
172
173 // Make sure the check owner holds at least value. If they have
174 // less than value the check cannot be cashed.
175 {
176 STAmount availableFunds{
178 ctx.view,
179 sleCheck->at(sfAccount),
180 value,
183 ctx.j),
184 };
185
186 // Note that src will have one reserve's worth of additional XRP
187 // once the check is cashed, since the check's reserve will no
188 // longer be required. So, if we're dealing in XRP, we add one
189 // reserve's worth to the available funds.
190 if (value.native() && !sleCheck->isFieldPresent(sfSponsor))
191 availableFunds += XRPAmount{ctx.view.fees().increment};
192
193 if (value > availableFunds)
194 {
195 JLOG(ctx.j.debug()) << "Check cashed for more than owner's balance.";
196 return tecPATH_PARTIAL;
197 }
198 }
199
200 // An issuer can always accept their own currency.
201 if (!value.native() && (value.getIssuer() != dstId))
202 {
203 return value.asset().visit(
204 [&](Issue const& issue) -> TER {
205 Currency const currency{issue.currency};
206 auto const sleTrustLine =
207 ctx.view.read(keylet::trustLine(dstId, issuerId, currency));
208
209 auto const sleIssuer = ctx.view.read(keylet::account(issuerId));
210 if (!sleIssuer)
211 {
212 JLOG(ctx.j.debug()) << "Can't receive IOUs from "
213 "non-existent issuer: "
214 << to_string(issuerId);
215 return tecNO_ISSUER;
216 }
217
218 if (sleIssuer->isFlag(lsfRequireAuth))
219 {
220 if (!sleTrustLine)
221 {
222 // We can only create a trust line if the issuer
223 // does not have lsfRequireAuth set.
224 return tecNO_AUTH;
225 }
226
227 // Entries have a canonical representation,
228 // determined by a lexicographical "greater than"
229 // comparison employing strict weak ordering.
230 // Determine which entry we need to access.
231 bool const canonicalGt(dstId > issuerId);
232
233 bool const isAuthorized(
234 (sleTrustLine->at(sfFlags) &
235 (canonicalGt ? lsfLowAuth : lsfHighAuth)) != 0u);
236
237 if (!isAuthorized)
238 {
239 JLOG(ctx.j.debug()) << "Can't receive IOUs from "
240 "issuer without auth.";
241 return tecNO_AUTH;
242 }
243 }
244
245 // The trustline from source to issuer does not need to
246 // be checked for freezing, since we already verified
247 // that the source has sufficient non-frozen funds
248 // available.
249
250 // However, the trustline from destination to issuer may
251 // not be frozen.
252 if (isFrozen(ctx.view, dstId, currency, issuerId))
253 {
254 JLOG(ctx.j.debug()) << "Cashing a check to a frozen trustline.";
255 return tecFROZEN;
256 }
257
258 return tesSUCCESS;
259 },
260 [&](MPTIssue const& issue) -> TER {
261 auto const sleIssuer = ctx.view.read(keylet::account(issuerId));
262 if (!sleIssuer)
263 {
264 JLOG(ctx.j.debug()) << "Can't receive MPTs from "
265 "non-existent issuer: "
266 << to_string(issuerId);
267 return tecNO_ISSUER;
268 }
269
270 if (auto const err = requireAuth(ctx.view, issue, dstId, AuthType::WeakAuth);
271 !isTesSuccess(err))
272 {
273 JLOG(ctx.j.debug()) << "Cashing a check to a MPT requiring auth.";
274 return err;
275 }
276
277 if (isFrozen(ctx.view, dstId, issue))
278 {
279 JLOG(ctx.j.debug()) << "Cashing a check to a frozen MPT.";
280 return tecLOCKED;
281 }
282
283 if (auto const err = canTransfer(ctx.view, issue, srcId, dstId);
284 !isTesSuccess(err))
285 {
286 JLOG(ctx.j.debug()) << "MPT transfer is disabled.";
287 return err;
288 }
289
290 return tesSUCCESS;
291 });
292 }
293 }
294 return tesSUCCESS;
295}
296
297TER
299{
300 // Flow requires that we operate on a PaymentSandbox, rather than
301 // directly on a View.
302 PaymentSandbox psb(&ctx_.view());
303
305 sleCheck.emplace(ctx_.tx[sfCheckID], psb, j_);
306 if (!*sleCheck)
307 {
308 // LCOV_EXCL_START
309 JLOG(j_.fatal()) << "Precheck did not verify check's existence.";
311 // LCOV_EXCL_STOP
312 }
313
314 AccountID const srcId{(*sleCheck)->getAccountID(sfAccount)};
315 if (!psb.exists(keylet::account(srcId)) || !psb.exists(keylet::account(accountID_)))
316 {
317 // LCOV_EXCL_START
318 JLOG(ctx_.journal.fatal()) << "Precheck did not verify source or destination's existence.";
320 // LCOV_EXCL_STOP
321 }
322
323 auto const sponsorCheckSle = getLedgerEntryReserveSponsor(psb, sleCheck->rawSle());
324
325 // Preclaim already checked that source has at least the requested
326 // funds.
327 //
328 // Therefore, if this is a check written to self, (and it shouldn't be)
329 // we know they have sufficient funds to pay the check. Since they are
330 // taking the funds from their own pocket and putting it back in their
331 // pocket no balance will change.
332 //
333 // If it is not a check to self (as should be the case), then there's
334 // work to do...
335 auto viewJ = ctx_.registry.get().getJournal("View");
336 auto const optDeliverMin = ctx_.tx[~sfDeliverMin];
337
338 if (srcId != accountID_)
339 {
340 STAmount const sendMax = (*sleCheck)->at(sfSendMax);
341
342 // Flow() doesn't do XRP to XRP transfers.
343 if (sendMax.native())
344 {
345 // Here we need to calculate the amount of XRP src can send.
346 // The amount they have available is their balance minus their
347 // reserve.
348 //
349 // Since (if we're successful) we're about to remove an entry
350 // from src's directory, we allow them to send that additional
351 // incremental reserve amount in the transfer. Hence the -1
352 // argument.
353 STAmount const srcLiquid{xrpLiquid(psb, srcId, sponsorCheckSle ? 0 : -1, viewJ)};
354
355 // Now, how much do they need in order to be successful?
356 STAmount const xrpDeliver{
357 optDeliverMin ? std::max(*optDeliverMin, std::min(sendMax, srcLiquid))
358 : ctx_.tx.getFieldAmount(sfAmount)};
359
360 if (srcLiquid < xrpDeliver)
361 {
362 // Vote no. However the transaction might succeed if applied
363 // in a different order.
364 JLOG(j_.trace()) << "Cash Check: Insufficient XRP: " << srcLiquid.getFullText()
365 << " < " << xrpDeliver.getFullText();
366 return tecUNFUNDED_PAYMENT;
367 }
368
369 if (optDeliverMin)
370 {
371 // Set the DeliveredAmount metadata.
372 ctx_.deliver(xrpDeliver);
373 }
374
375 // The source account has enough XRP so make the ledger change.
376 if (TER const ter{transferXRP(psb, srcId, accountID_, xrpDeliver, viewJ)};
377 !isTesSuccess(ter))
378 {
379 // The transfer failed. Return the error code.
380 return ter;
381 }
382 }
383 else
384 {
385 // Note that for DeliverMin we don't know exactly how much
386 // currency we want flow to deliver. For IOUs, use a value
387 // higher than any real delivery as the request. MPTs are
388 // bounded integral amounts, so use the maximum output the check
389 // can actually deliver without exceeding SendMax.
390 auto const maxDeliverMin = [&] {
391 return optDeliverMin->asset().visit(
392 [&](Issue const&) {
393 return STAmount(
394 optDeliverMin->asset(), STAmount::kMaxValue / 2, STAmount::kMaxOffset);
395 },
396 [&](MPTIssue const& issue) {
397 MPTAmount maxDeliver = sendMax.mpt();
398 auto const& issuer = issue.getIssuer();
399 if (srcId != issuer && accountID_ != issuer)
400 {
401 auto const rate = transferRate(psb, issue.getMptID());
402 // Request at most floor(SendMax / rate). The endpoint reverse pass
403 // will quote ceil(output * rate), so this keeps the input
404 // representable and within SendMax.
405 maxDeliver =
406 mulRatio(maxDeliver, QUALITY_ONE, rate.value, /*roundUp*/ false);
407 }
408 return STAmount(maxDeliver, issue);
409 });
410 };
411 STAmount const flowDeliver{
412 optDeliverMin ? maxDeliverMin() : ctx_.tx.getFieldAmount(sfAmount),
413 };
414
415 auto applyViewContext = ApplyViewContext({.view = psb, .tx = ctx_.tx});
416 auto const sponsorSle = getTxReserveSponsor(applyViewContext);
417 if (!sponsorSle)
418 return sponsorSle.error(); // LCOV_EXCL_LINE
419
420 // Check reserve. Return destination account SLE if enough reserve,
421 // otherwise return nullptr.
422 auto checkDstReserve = [&] -> SLE::pointer {
423 auto sleDst = psb.peek(keylet::account(accountID_));
424
425 // Can the account cover the trust line's or MPT reserve?
426 if (auto const ret = checkReserve(
427 applyViewContext,
428 sleDst,
430 *sponsorSle,
431 {.ownerCountDelta = 1},
432 j_);
433 !isTesSuccess(ret))
434 {
435 JLOG(j_.trace()) << "Trust line does not exist. "
436 "Insufficient reserve to create line.";
437
438 return nullptr;
439 }
440 return sleDst;
441 };
442
443 std::optional<Keylet> trustLineKey;
444 STAmount savedLimit;
445 bool destLow = false;
446 AccountID const& deliverIssuer = flowDeliver.getIssuer();
447 auto const err = flowDeliver.asset().visit(
448 [&](Issue const& issue) -> std::optional<TER> {
449 // An issuer needs no holder-limit waiver to receive its own currency.
450 if (deliverIssuer == accountID_ && ctx_.view().rules().enabled(fixCleanup3_4_0))
451 {
452 return std::nullopt;
453 }
454
455 // If a trust line does not exist yet create one.
456 Issue const& trustLineIssue = issue;
457 AccountID const truster = deliverIssuer == accountID_ ? srcId : accountID_;
458 trustLineKey = keylet::trustLine(truster, trustLineIssue);
459 destLow = deliverIssuer > accountID_;
460
461 if (!psb.exists(*trustLineKey))
462 {
463 // 1. Can the check casher meet the reserve for the
464 // trust line?
465 // 2. Create trust line between destination (this)
466 // account
467 // and the issuer.
468 // 3. Apply correct noRipple settings on trust line.
469 // Use...
470 // a. this (destination) account and
471 // b. issuing account (not sending account).
472
473 auto const sleDst = checkDstReserve();
474 if (sleDst == nullptr)
476
477 Currency const& currency = issue.currency;
478 STAmount initialBalance(flowDeliver.asset());
479 initialBalance.get<Issue>().account = noAccount();
480
481 if (TER const ter = trustCreate(
482 psb, // payment sandbox
483 destLow, // is dest low?
484 deliverIssuer, // source
485 accountID_, // destination
486 trustLineKey->key, // ledger index
487 sleDst, // Account to add to
488 false, // authorize account
489 !sleDst->isFlag(lsfDefaultRipple), //
490 false, // freeze trust line
491 false, // deep freeze trust line
492 initialBalance, // zero initial balance
493 Issue(currency, accountID_), // limit of zero
494 0, // quality in
495 0, // quality out
496 *sponsorSle, // sponsor
497 viewJ); // journal
498 !isTesSuccess(ter))
499 {
500 return ter;
501 }
502
503 psb.update(sleDst);
504
505 // Note that we _don't_ need to be careful about
506 // destroying the trust line if the check cashing
507 // fails. The transaction machinery will
508 // automatically clean it up.
509 }
510
511 // Since the destination is signing the check, they
512 // clearly want the funds even if their new total funds
513 // would exceed the limit on their trust line. So we
514 // tweak the trust line limits before calling flow and
515 // then restore the trust line limits afterwards.
516 auto const sleTrustLine = psb.peek(*trustLineKey);
517 if (!sleTrustLine)
518 return tecNO_LINE;
519
520 SF_AMOUNT const& tweakedLimit = destLow ? sfLowLimit : sfHighLimit;
521 savedLimit = sleTrustLine->at(tweakedLimit);
522
523 // Set the trust line limit to the highest possible
524 // value while flow runs.
525 STAmount const bigAmount(
527 sleTrustLine->at(tweakedLimit) = bigAmount;
528
529 return std::nullopt;
530 },
531 [&](MPTIssue const& issue) -> std::optional<TER> {
532 if (accountID_ != deliverIssuer)
533 {
534 auto const& mptID = issue.getMptID();
535 // Create MPT if it doesn't exist
536 auto const mptokenKey = keylet::mptoken(mptID, accountID_);
537 if (!psb.exists(mptokenKey))
538 {
539 auto const sleDst = checkDstReserve();
540 if (sleDst == nullptr)
542
543 if (auto const err =
544 checkCreateMPT(psb, mptID, accountID_, *sponsorSle, 0, j_);
545 !isTesSuccess(err))
546 {
547 return err;
548 }
549 }
550 }
551
552 return std::nullopt;
553 });
554 if (err)
555 return *err;
556 // Make sure the tweaked limits are restored when we leave
557 // scope.
558 ScopeExit const fixup([&psb, &trustLineKey, destLow, &savedLimit] {
559 if (trustLineKey)
560 {
561 SF_AMOUNT const& tweakedLimit = destLow ? sfLowLimit : sfHighLimit;
562 if (auto const sleTrustLine = psb.peek(*trustLineKey))
563 sleTrustLine->at(tweakedLimit) = savedLimit;
564 }
565 });
566
567 // Let flow() do the heavy lifting on a check for an IOU.
568 auto const result = flow(
569 psb,
570 flowDeliver,
571 srcId,
573 STPathSet{},
574 true, // default path
575 static_cast<bool>(optDeliverMin), // partial payment
576 true, // owner pays transfer fee
578 std::nullopt,
579 (*sleCheck)->getFieldAmount(sfSendMax),
580 std::nullopt, // check does not support domain
581 viewJ);
582
583 if (!isTesSuccess(result.result()))
584 {
585 JLOG(ctx_.journal.debug()) << "flow failed when cashing check.";
586 return result.result();
587 }
588
589 // Make sure that deliverMin was satisfied.
590 if (optDeliverMin)
591 {
592 if (result.actualAmountOut < *optDeliverMin)
593 {
594 JLOG(ctx_.journal.debug()) << "flow did not produce DeliverMin.";
595 return tecPATH_PARTIAL;
596 }
597 ctx_.deliver(result.actualAmountOut);
598 }
599
600 // Set the delivered amount metadata in all cases, not just
601 // for DeliverMin.
602 ctx_.deliver(result.actualAmountOut);
603
604 sleCheck.emplace(ctx_.tx[sfCheckID], psb, j_);
605 }
606 }
607
608 // Check was cashed. If not a self send (and it shouldn't be), remove
609 // check link from destination directory.
610 if (srcId != accountID_ &&
611 !psb.dirRemove(
613 (*sleCheck)->at(sfDestinationNode),
614 (*sleCheck)->key(),
615 true))
616 {
617 // LCOV_EXCL_START
618 JLOG(j_.fatal()) << "Unable to delete check from destination.";
619 return tefBAD_LEDGER;
620 // LCOV_EXCL_STOP
621 }
622
623 // Remove check from check owner's directory.
624 if (!psb.dirRemove(
625 keylet::ownerDir(srcId), (*sleCheck)->at(sfOwnerNode), (*sleCheck)->key(), true))
626 {
627 // LCOV_EXCL_START
628 JLOG(j_.fatal()) << "Unable to delete check from owner.";
629 return tefBAD_LEDGER;
630 // LCOV_EXCL_STOP
631 }
632
633 // If we succeeded, update the check owner's reserve.
634 decreaseOwnerCountForObject(psb, srcId, sleCheck->mutableRawSle(), 1, viewJ);
635
636 // Remove check from ledger.
637 sleCheck->erase();
638
639 psb.apply(ctx_.rawView());
640 return tesSUCCESS;
641}
642
643void
645{
646 // No transaction-specific invariants yet (future work).
647}
648
649bool
651{
652 // No transaction-specific invariants yet (future work).
653 return true;
654}
655
656} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Stream error() const
Definition Journal.h:362
Stream debug() const
Definition Journal.h:344
bool dirRemove(Keylet const &directory, std::uint64_t page, UInt256 const &key, bool keepRoot)
Remove an entry from a directory.
constexpr auto visit(Visitors &&... visitors) const -> decltype(auto)
Definition Asset.h:117
TER doApply() override
static TER preclaim(PreclaimContext const &ctx)
Definition CheckCash.cpp:89
void visitInvariantEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after) override
Inspect a single ledger entry modified by this transaction.
static NotTEC preflight(PreflightContext const &ctx)
Definition CheckCash.cpp:55
static bool checkExtraFeatures(PreflightContext const &ctx)
Definition CheckCash.cpp:44
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
A currency issued by an account.
Definition Issue.h:18
Currency currency
Definition Issue.h:20
A wrapper which makes credits unavailable to balances.
void apply(RawView &to)
Apply changes to base view.
A view into a ledger.
Definition ReadView.h:41
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(UInt256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:182
constexpr TIss const & get() const
std::string getFullText() const override
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
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1077
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:464
beast::Journal const j_
Definition Transactor.h:164
AccountID const accountID_
Definition Transactor.h:166
XRPAmount preFeeBalance_
Definition Transactor.h:167
ApplyContext & ctx_
Definition Transactor.h:162
SLE::pointer peek(Keylet const &k) override
Prepare to modify the SLE associated with key.
void update(SLE::Ref sle) override
Indicate changes to a peeked SLE.
bool exists(Keylet const &k) const override
Determine if a state item exists.
T emplace(T... args)
T max(T... args)
T min(T... args)
constexpr Zero kZero
Definition Zero.h:30
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:415
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 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
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
Calculate liquid XRP balance for an account.
bool isLegalMPT(STAmount const &value)
Definition STAmount.h:622
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp, ExpiryComparison comparison=ExpiryComparison::Inclusive)
Determines whether the given expiration time has passed.
Definition View.cpp:52
CheckEntry< ReadView > CheckEntryR
Definition CheckEntry.h:43
TER checkCreateMPT(xrpl::ApplyView &view, xrpl::MPTIssue const &mptIssue, xrpl::AccountID const &holder, SLE::Ref sponsorSle, std::uint32_t flags, beast::Journal j)
@ tefBAD_LEDGER
Definition TER.h:164
bool isLegalNet(STAmount const &value)
Definition STAmount.h:616
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition UintTypes.h:42
TER checkReserve(ApplyViewContext ctx, SLE::ConstRef accSle, XRPAmount accBalance, SLE::ConstRef sponsorSle, Adjustment adj, beast::Journal j, TER insufReserveCode=tecINSUFFICIENT_RESERVE)
Check if an account has sufficient reserve.
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.
TypedField< STAmount > SF_AMOUNT
Definition SField.h:357
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
std::expected< SLE::pointer, TER > getTxReserveSponsor(ApplyViewContext ctx)
Return a mutable SLE for the transaction's reserve sponsor account.
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:617
void decreaseOwnerCountForObject(ApplyView &view, SLE::Ref accountSle, SLE::Ref objectSle, std::uint32_t count, beast::Journal j)
Decrease owner-count fields for an existing ledger object.
StrandResult< TInAmt, TOutAmt > flow(PaymentSandbox const &baseView, Strand const &strand, std::optional< TInAmt > const &maxIn, TOutAmt const &out, beast::Journal j)
Request out amount from a strand.
Definition StrandFlow.h:101
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
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.
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.
@ temBAD_CURRENCY
Definition TER.h:78
@ temMALFORMED
Definition TER.h:75
@ temBAD_AMOUNT
Definition TER.h:77
bool isTesSuccess(TER x) noexcept
Definition TER.h:686
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
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.
@ tecLOCKED
Definition TER.h:369
@ tecNO_LINE_INSUF_RESERVE
Definition TER.h:303
@ tecPATH_PARTIAL
Definition TER.h:293
@ tecUNFUNDED_PAYMENT
Definition TER.h:296
@ tecNO_ENTRY
Definition TER.h:317
@ tecNO_AUTH
Definition TER.h:311
@ tecINTERNAL
Definition TER.h:321
@ tecFAILED_PROCESSING
Definition TER.h:297
@ tecFROZEN
Definition TER.h:314
@ tecEXPIRED
Definition TER.h:325
@ tecNO_LINE
Definition TER.h:312
@ tecINSUFFICIENT_RESERVE
Definition TER.h:318
@ tecNO_PERMISSION
Definition TER.h:316
@ tecDST_TAG_NEEDED
Definition TER.h:320
@ tecNO_ISSUER
Definition TER.h:310
BadAsset const & badAsset()
Definition Asset.h:40
@ tesSUCCESS
Definition TER.h:253
constexpr bool equalTokens(Asset const &lhs, Asset const &rhs)
Definition Asset.h:286
Bundles the mutable ledger view and the transaction being applied.
Definition ApplyView.h:451
XRPAmount increment
Additional XRP reserve required per owned ledger object.
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:92
ReadView const & view
Definition Transactor.h:95
beast::Journal const j
Definition Transactor.h:100
State information when preflighting a tx.
Definition Transactor.h:39
beast::Journal const j
Definition Transactor.h:46
std::uint32_t value
Definition Rate.h:22