xrpld
Loading...
Searching...
No Matches
View.cpp
1#include <xrpl/ledger/View.h>
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/basics/chrono.h>
6#include <xrpl/basics/safe_cast.h>
7#include <xrpl/beast/utility/Journal.h>
8#include <xrpl/beast/utility/Zero.h>
9#include <xrpl/beast/utility/instrumentation.h>
10#include <xrpl/ledger/ApplyView.h>
11#include <xrpl/ledger/ReadView.h>
12#include <xrpl/ledger/entries/AmendmentsEntry.h>
13#include <xrpl/ledger/entries/DepositPreauthEntry.h>
14#include <xrpl/ledger/entries/LedgerHashesEntry.h>
15#include <xrpl/ledger/helpers/AccountRootHelpers.h>
16#include <xrpl/ledger/helpers/CredentialHelpers.h>
17#include <xrpl/ledger/helpers/DirectoryHelpers.h>
18#include <xrpl/ledger/helpers/MPTokenHelpers.h>
19#include <xrpl/ledger/helpers/RippleStateHelpers.h>
20#include <xrpl/ledger/helpers/SponsorHelpers.h>
21#include <xrpl/ledger/helpers/TokenHelpers.h>
22#include <xrpl/protocol/AccountID.h>
23#include <xrpl/protocol/Asset.h>
24#include <xrpl/protocol/Feature.h>
25#include <xrpl/protocol/Indexes.h>
26#include <xrpl/protocol/Issue.h>
27#include <xrpl/protocol/Keylet.h>
28#include <xrpl/protocol/LedgerFormats.h>
29#include <xrpl/protocol/MPTIssue.h>
30#include <xrpl/protocol/Protocol.h>
31#include <xrpl/protocol/SField.h>
32#include <xrpl/protocol/STAmount.h>
33#include <xrpl/protocol/STLedgerEntry.h>
34#include <xrpl/protocol/STTx.h>
35#include <xrpl/protocol/TER.h>
36#include <xrpl/protocol/XRPAmount.h>
37
38#include <cstdint>
39#include <optional>
40#include <set>
41#include <vector>
42
43namespace xrpl {
44
45//------------------------------------------------------------------------------
46//
47// Observers
48//
49//------------------------------------------------------------------------------
50
51bool
53 ReadView const& view,
55 ExpiryComparison comparison)
56{
57 using D = NetClock::duration;
58 using Tp = NetClock::time_point;
59
60 if (!exp)
61 return false;
62 auto const boundary = Tp{D{*exp}};
63 return comparison == ExpiryComparison::Inclusive //
64 ? view.parentCloseTime() >= boundary
65 : view.parentCloseTime() > boundary;
66}
67
68namespace {
69
71checkVaultPseudoAccountFrozenPreconditions(ReadView const& view, std::uint8_t depth)
72{
73 if (!view.rules().enabled(featureSingleAssetVault))
74 return false;
75
76 if (depth >= kMaxAssetCheckDepth)
77 {
78 // LCOV_EXCL_START
79 UNREACHABLE(
80 "xrpl::View::checkVaultPseudoAccountFrozenPreconditions : reached asset check depth");
81 return true;
82 // LCOV_EXCL_STOP
83 }
84
85 return std::nullopt;
86}
87
88bool
89isVaultPseudoAccountFrozenForIssuance(
90 ReadView const& view,
91 AccountID const& account,
92 SLE const& issuanceSle,
93 std::uint8_t depth)
94{
95 XRPL_ASSERT(
96 issuanceSle.getType() == ltMPTOKEN_ISSUANCE,
97 "xrpl::isVaultPseudoAccountFrozenForIssuance : MPTokenIssuance SLE");
98
99 auto const issuer = issuanceSle.getAccountID(sfIssuer);
100
101 // Post-fixCleanup3_2_0: vault shares carry sfReferenceHolding pointing
102 // to the vault pseudo's MPToken or RippleState for the underlying.
103 // Read it to derive the underlying asset and recurse, skipping the
104 // issuer-account-then-vault chain. Pre-amendment shares (no field)
105 // fall back to the chain lookup below.
106 if (issuanceSle.isFieldPresent(sfReferenceHolding))
107 {
108 auto const sleHolding =
109 view.read(keylet::unchecked(issuanceSle.getFieldH256(sfReferenceHolding)));
110 if (!sleHolding)
111 {
112 // LCOV_EXCL_START
113 UNREACHABLE("xrpl::isVaultPseudoAccountFrozen : dangling sfReferenceHolding");
114 return false;
115 // LCOV_EXCL_STOP
116 }
117 return isAnyFrozen(
118 view, {issuer, account}, assetOfHolding(issuanceSle, *sleHolding), depth + 1);
119 }
120
121 auto const mptIssuer = view.read(keylet::account(issuer));
122 if (mptIssuer == nullptr)
123 {
124 // LCOV_EXCL_START
125 UNREACHABLE("xrpl::isVaultPseudoAccountFrozen : null MPToken issuer");
126 return false;
127 // LCOV_EXCL_STOP
128 }
129
130 if (!mptIssuer->isFieldPresent(sfVaultID))
131 return false; // not a Vault pseudo-account, common case
132
133 auto const vault = view.read(keylet::vault(mptIssuer->getFieldH256(sfVaultID)));
134 if (vault == nullptr)
135 { // LCOV_EXCL_START
136 UNREACHABLE("xrpl::isVaultPseudoAccountFrozen : null vault");
137 return false;
138 // LCOV_EXCL_STOP
139 }
140
141 return isAnyFrozen(view, {issuer, account}, vault->at(sfAsset), depth + 1);
142}
143
144} // namespace
145
146bool
148 ReadView const& view,
149 AccountID const& account,
150 SLE const& issuanceSle,
151 std::uint8_t depth)
152{
153 if (auto const result = checkVaultPseudoAccountFrozenPreconditions(view, depth))
154 return *result;
155
156 return isVaultPseudoAccountFrozenForIssuance(view, account, issuanceSle, depth);
157}
158
159bool
161 ReadView const& view,
162 AccountID const& account,
163 MPTIssue const& mptShare,
164 std::uint8_t depth)
165{
166 if (auto const result = checkVaultPseudoAccountFrozenPreconditions(view, depth))
167 return *result;
168
169 auto const issuanceSle = view.read(keylet::mptokenIssuance(mptShare.getMptID()));
170 if (issuanceSle == nullptr)
171 return false; // zero MPToken won't block deletion of MPTokenIssuance
172
173 return isVaultPseudoAccountFrozenForIssuance(view, account, *issuanceSle, depth);
174}
175
176bool
178 ReadView const& view,
179 AccountID const& account,
180 Asset const& asset,
181 Asset const& asset2)
182{
183 return isFrozen(view, account, asset) || isFrozen(view, account, asset2);
184}
185
186TER
188 ReadView const& view,
189 AccountID const& from,
190 AccountID const& to,
191 AccountID const& lpTokenIssuer)
192{
193 // Only AMM-issued LPTokens are subject to this check. The LPToken's issuer
194 // is the AMM account; if it is not an AMM, this is not an LPToken.
195 auto const sleIssuer = view.read(keylet::account(lpTokenIssuer));
196 if (!sleIssuer || !sleIssuer->isFieldPresent(sfAMMID))
197 return tesSUCCESS;
198
199 auto const sleAmm = view.read(keylet::amm((*sleIssuer)[sfAMMID]));
200 if (!sleAmm)
201 return tecINTERNAL; // LCOV_EXCL_LINE
202
203 auto const transferable = [&](Asset const& a) -> TER {
204 if (!a.holds<MPTIssue>())
205 return tesSUCCESS;
206 return canTransfer(view, a.get<MPTIssue>(), from, to);
207 };
208 if (auto const err = transferable((*sleAmm)[sfAsset]); !isTesSuccess(err))
209 return err;
210 return transferable((*sleAmm)[sfAsset2]);
211}
212
213bool
215 ReadView const& validLedger,
216 ReadView const& testLedger,
217 beast::Journal::Stream const& s,
218 char const* reason)
219{
220 bool ret = true;
221
222 if (validLedger.header().seq < testLedger.header().seq)
223 {
224 // valid -> ... -> test
225 auto hash = hashOfSeq(
226 testLedger, validLedger.header().seq, beast::Journal{beast::Journal::getNullSink()});
227 if (hash && (*hash != validLedger.header().hash))
228 {
229 JLOG(s) << reason << " incompatible with valid ledger";
230
231 JLOG(s) << "Hash(VSeq): " << to_string(*hash);
232
233 ret = false;
234 }
235 }
236 else if (validLedger.header().seq > testLedger.header().seq)
237 {
238 // test -> ... -> valid
239 auto hash = hashOfSeq(
240 validLedger, testLedger.header().seq, beast::Journal{beast::Journal::getNullSink()});
241 if (hash && (*hash != testLedger.header().hash))
242 {
243 JLOG(s) << reason << " incompatible preceding ledger";
244
245 JLOG(s) << "Hash(NSeq): " << to_string(*hash);
246
247 ret = false;
248 }
249 }
250 else if (
251 (validLedger.header().seq == testLedger.header().seq) &&
252 (validLedger.header().hash != testLedger.header().hash))
253 {
254 // Same sequence number, different hash
255 JLOG(s) << reason << " incompatible ledger";
256
257 ret = false;
258 }
259
260 if (!ret)
261 {
262 JLOG(s) << "Val: " << validLedger.header().seq << " "
263 << to_string(validLedger.header().hash);
264
265 JLOG(s) << "New: " << testLedger.header().seq << " " << to_string(testLedger.header().hash);
266 }
267
268 return ret;
269}
270
271bool
273 UInt256 const& validHash,
274 LedgerIndex validIndex,
275 ReadView const& testLedger,
276 beast::Journal::Stream const& s,
277 char const* reason)
278{
279 bool ret = true;
280
281 if (testLedger.header().seq > validIndex)
282 {
283 // Ledger we are testing follows last valid ledger
284 auto hash =
285 hashOfSeq(testLedger, validIndex, beast::Journal{beast::Journal::getNullSink()});
286 if (hash && (*hash != validHash))
287 {
288 JLOG(s) << reason << " incompatible following ledger";
289 JLOG(s) << "Hash(VSeq): " << to_string(*hash);
290
291 ret = false;
292 }
293 }
294 else if ((validIndex == testLedger.header().seq) && (testLedger.header().hash != validHash))
295 {
296 JLOG(s) << reason << " incompatible ledger";
297
298 ret = false;
299 }
300
301 if (!ret)
302 {
303 JLOG(s) << "Val: " << validIndex << " " << to_string(validHash);
304
305 JLOG(s) << "New: " << testLedger.header().seq << " " << to_string(testLedger.header().hash);
306 }
307
308 return ret;
309}
310
313{
314 return AmendmentsEntryR(view).enabledAmendments();
315}
316
319{
321}
322
324hashOfSeq(ReadView const& ledger, LedgerIndex seq, beast::Journal journal)
325{
326 // Easy cases...
327 if (seq > ledger.seq())
328 {
329 JLOG(journal.warn()) << "Can't get seq " << seq << " from " << ledger.seq() << " future";
330 return std::nullopt;
331 }
332 if (seq == ledger.seq())
333 return ledger.header().hash;
334 if (seq == (ledger.seq() - 1))
335 return ledger.header().parentHash;
336
337 if (int const diff = ledger.seq() - seq; diff <= 256)
338 {
339 // Within 256...
340 LedgerHashesEntryR const hashIndex(ledger, journal);
341 if (hashIndex)
342 {
343 XRPL_ASSERT(
344 hashIndex->getFieldU32(sfLastLedgerSequence) == (ledger.seq() - 1),
345 "xrpl::hashOfSeq : matching ledger sequence");
346 if (auto const hash = hashIndex.hashAt(diff - 1))
347 return hash;
348 JLOG(journal.warn()) << "Ledger " << ledger.seq() << " missing hash for " << seq << " ("
349 << hashIndex->getFieldV256(sfHashes).size() << "," << diff << ")";
350 }
351 else
352 {
353 JLOG(journal.warn()) << "Ledger " << ledger.seq() << ":" << ledger.header().hash
354 << " missing normal list";
355 }
356 }
357
358 if ((seq & 0xff) != 0)
359 {
360 JLOG(journal.debug()) << "Can't get seq " << seq << " from " << ledger.seq() << " past";
361 return std::nullopt;
362 }
363
364 // in skiplist
365 LedgerHashesEntryR const hashIndex(keylet::skip(seq), ledger, journal);
366 if (hashIndex)
367 {
368 auto const lastSeq = hashIndex->getFieldU32(sfLastLedgerSequence);
369 XRPL_ASSERT(lastSeq >= seq, "xrpl::hashOfSeq : minimum last ledger");
370 XRPL_ASSERT((lastSeq & 0xff) == 0, "xrpl::hashOfSeq : valid last ledger");
371 if (auto const hash = hashIndex.hashAt((lastSeq - seq) >> 8))
372 return hash;
373 }
374 JLOG(journal.warn()) << "Can't get seq " << seq << " from " << ledger.seq() << " error";
375 return std::nullopt;
376}
377
378//------------------------------------------------------------------------------
379//
380// Modifiers
381//
382//------------------------------------------------------------------------------
383
384TER
385dirLink(ApplyView& view, AccountID const& owner, SLE::pointer const& object, SF_UINT64 const& node)
386{
387 auto const page =
388 view.dirInsert(keylet::ownerDir(owner), object->key(), describeOwnerDir(owner));
389 if (!page)
390 return tecDIR_FULL; // LCOV_EXCL_LINE
391 object->setFieldU64(node, *page);
392 return tesSUCCESS;
393}
394
395/*
396 * Checks if a withdrawal amount into the destination account exceeds
397 * any applicable receiving limit.
398 * Called by VaultWithdraw and LoanBrokerCoverWithdraw.
399 *
400 * IOU : Performs the trustline check against the destination account's
401 * credit limit to ensure the account's trust maximum is not exceeded.
402 *
403 * MPT: The limit check is effectively skipped (returns true). This is
404 * because MPT MaximumAmount relates to token supply, and withdrawal does not
405 * involve minting new tokens that could exceed the global cap.
406 * On withdrawal, tokens are simply transferred from the vault's pseudo-account
407 * to the destination account. Since no new MPT tokens are minted during this
408 * transfer, the withdrawal cannot violate the MPT MaximumAmount/supply cap
409 * even if `from` is the issuer.
410 */
411static TER
413 ReadView const& view,
414 AccountID const& from,
415 AccountID const& to,
416 STAmount const& amount)
417{
418 auto const& issuer = amount.getIssuer();
419 if (from == to || to == issuer || isXRP(issuer))
420 return tesSUCCESS;
421
422 return amount.asset().visit(
423 [&](Issue const& issue) -> TER {
424 auto const& currency = issue.currency;
425 auto const owed = creditBalance(view, to, issuer, currency);
426 if (owed <= beast::kZero)
427 {
428 auto const limit = creditLimit(view, to, issuer, currency);
429 if (-owed >= limit || amount > (limit + owed))
430 return tecNO_LINE;
431 }
432 return tesSUCCESS;
433 },
434 [](MPTIssue const&) -> TER { return tesSUCCESS; });
435}
436
437[[nodiscard]] TER
439 ReadView const& view,
440 AccountID const& from,
441 AccountID const& to,
442 SLE::ConstRef toSle,
443 STAmount const& amount,
444 bool hasDestinationTag,
445 std::optional<std::vector<UInt256>> const& credentialIDs)
446{
447 if (auto const ret = checkDestinationAndTag(toSle, hasDestinationTag))
448 return ret;
449
450 if (from == to)
451 return tesSUCCESS;
452
453 if (toSle->isFlag(lsfDepositAuth))
454 {
455 if (!DepositPreauthEntryR(to, from, view))
456 {
457 if (credentialIDs.has_value())
458 {
459 STVector256 const credIDs{*credentialIDs};
460
461 // Callers must have validated these in preclaim, so a missing
462 // credential here is an invariant violation.
463 for (auto const& h : credIDs)
464 {
465 if (!view.exists(keylet::credential(h)))
466 return tecINTERNAL; // LCOV_EXCL_LINE
467 }
468
469 if (auto const ret = credentials::authorizedDepositPreauth(view, credIDs, to);
470 !isTesSuccess(ret))
471 return ret;
472 }
473 else
474 {
475 return tecNO_PERMISSION;
476 }
477 }
478 }
479
480 return withdrawToDestExceedsLimit(view, from, to, amount);
481}
482
483[[nodiscard]] TER
485 ReadView const& view,
486 AccountID const& from,
487 AccountID const& to,
488 STAmount const& amount,
489 bool hasDestinationTag,
490 std::optional<std::vector<UInt256>> const& credentialIDs)
491{
492 auto const toSle = view.read(keylet::account(to));
493
494 return canWithdraw(view, from, to, toSle, amount, hasDestinationTag, credentialIDs);
495}
496
497[[nodiscard]] TER
498canWithdraw(ReadView const& view, STTx const& tx)
499{
500 auto const from = tx[sfAccount];
501 auto const to = tx[~sfDestination].value_or(from);
502
503 return canWithdraw(
504 view, from, to, tx[sfAmount], tx.isFieldPresent(sfDestinationTag), tx[~sfCredentialIDs]);
505}
506
507TER
510 AccountID const& senderAcct,
511 AccountID const& dstAcct,
512 AccountID const& sourceAcct,
513 XRPAmount priorBalance,
514 STAmount const& destinationAmount,
515 STAmount const& sourceAmount,
517{
518 XRPL_ASSERT(
519 destinationAmount.asset() == sourceAmount.asset(),
520 "xrpl::doWithdraw : delivered and source amounts use the same asset");
521
522 auto const dstSle = ctx.view.read(keylet::account(dstAcct));
523
524 // Create a trust line or MPToken for a self-destination only when there
525 // is a payout to credit. Post-fixCleanup3_4_0, a zero-value withdraw
526 // (e.g. share redemption from a fully impaired vault) must not insert
527 // an empty holding: that records a one-sided zero delta and can also
528 // create+delete MPTokens in the same transaction.
529 if (dstAcct == senderAcct)
530 {
531 if (destinationAmount > beast::kZero || !ctx.view.rules().enabled(fixCleanup3_4_0))
532 {
533 if (auto const ter =
534 addEmptyHolding(ctx, senderAcct, priorBalance, destinationAmount.asset(), j);
535 !isTesSuccess(ter) && ter != tecDUPLICATE)
536 return ter;
537 }
538 }
539 else
540 {
541 if (auto err = verifyDepositPreauth(ctx.tx, ctx.view, senderAcct, dstAcct, dstSle, j))
542 return err;
543 }
544
545 // Sanity check
546 if (accountHolds(
547 ctx.view,
548 sourceAcct,
549 destinationAmount.asset(),
552 j) < sourceAmount)
553 {
554 // LCOV_EXCL_START
555 JLOG(j.error()) << "doWithdraw: source account holds fewer assets than the withdrawal.";
556 return tefINTERNAL;
557 // LCOV_EXCL_STOP
558 }
559
560 // A transfer fee applies. Redeem the gross amount with the issuer, then
561 // issue the net amount to the destination.
562 if (sourceAmount != destinationAmount)
563 {
564 auto const issuer = destinationAmount.getIssuer();
565 XRPL_ASSERT(
566 !destinationAmount.native() && sourceAcct != issuer && dstAcct != issuer,
567 "xrpl::doWithdraw : transfer fee applies between token holders");
568
569 if (auto const ter = directSendNoFee(ctx.view, sourceAcct, issuer, sourceAmount, false, j);
570 !isTesSuccess(ter))
571 return ter; // LCOV_EXCL_LINE
572
573 return directSendNoFee(ctx.view, issuer, dstAcct, destinationAmount, false, j);
574 }
575
576 // A reserve sponsor only covers tx.Account's own objects, so resolve the
577 // sponsor against the destination. accountSend can auto-create a holding
578 // for dstAcct; keying on the destination ensures a third-party destination's
579 // holding is never stamped with the tx's reserve sponsor.
580 auto const sponsorSle = getEffectiveTxReserveSponsor(ctx, dstSle);
581 if (!sponsorSle)
582 return sponsorSle.error(); // LCOV_EXCL_LINE
583
584 // Move the funds directly from the broker's pseudo-account to the
585 // dstAcct
586 return accountSend(
587 ctx.view, sourceAcct, dstAcct, destinationAmount, j, *sponsorSle, WaiveTransferFee::Yes);
588}
589
590TER
592 ApplyView& view,
593 Keylet const& ownerDirKeylet,
594 EntryDeleter const& deleter,
596 std::optional<uint16_t> maxNodesToDelete)
597{
598 // Delete all the entries in the account directory.
599 SLE::pointer sleDirNode{};
600 unsigned int uDirEntry{0};
601 UInt256 dirEntry{beast::kZero};
602 std::uint32_t deleted = 0;
603
604 if (view.exists(ownerDirKeylet) &&
605 dirFirst(view, ownerDirKeylet.key, sleDirNode, uDirEntry, dirEntry))
606 {
607 do
608 {
609 if (maxNodesToDelete && ++deleted > *maxNodesToDelete)
610 return tecINCOMPLETE;
611
612 // Choose the right way to delete each directory node.
613 auto sleItem = view.peek(keylet::child(dirEntry));
614 if (!sleItem)
615 {
616 // Directory node has an invalid index. Bail out.
617 // LCOV_EXCL_START
618 JLOG(j.fatal()) << "DeleteAccount: Directory node in ledger " << view.seq()
619 << " has index to object that is missing: " << to_string(dirEntry);
620 return tefBAD_LEDGER;
621 // LCOV_EXCL_STOP
622 }
623
624 LedgerEntryType const nodeType{
625 safeCast<LedgerEntryType>(sleItem->getFieldU16(sfLedgerEntryType)),
626 };
627
628 // Deleter handles the details of specific account-owned object
629 // deletion
630 auto const [ter, skipEntry] = deleter(nodeType, dirEntry, sleItem);
631 if (!isTesSuccess(ter))
632 return ter;
633
634 // dirFirst() and dirNext() are like iterators with exposed
635 // internal state. We'll take advantage of that exposed state
636 // to solve a common C++ problem: iterator invalidation while
637 // deleting elements from a container.
638 //
639 // We have just deleted one directory entry, which means our
640 // "iterator state" is invalid.
641 //
642 // 1. During the process of getting an entry from the
643 // directory uDirEntry was incremented from 'it' to 'it'+1.
644 //
645 // 2. We then deleted the entry at index 'it', which means the
646 // entry that was at 'it'+1 has now moved to 'it'.
647 //
648 // 3. So we verify that uDirEntry is indeed 'it'+1. Then we jam it
649 // back to 'it' to "un-invalidate" the iterator.
650 XRPL_ASSERT(uDirEntry >= 1, "xrpl::cleanupOnAccountDelete : minimum dir entries");
651 if (uDirEntry == 0)
652 {
653 // LCOV_EXCL_START
654 JLOG(j.error()) << "DeleteAccount iterator re-validation failed.";
655 return tefBAD_LEDGER;
656 // LCOV_EXCL_STOP
657 }
658 if (skipEntry == SkipEntry::No)
659 uDirEntry--;
660
661 } while (dirNext(view, ownerDirKeylet.key, sleDirNode, uDirEntry, dirEntry));
662 }
663
664 return tesSUCCESS;
665}
666
667bool
669{
670 return now.time_since_epoch().count() > mark;
671}
672
673} // namespace xrpl
Provide a light-weight way to check active() before string formatting.
Definition Journal.h:199
A generic endpoint for log messages.
Definition Journal.h:44
Stream fatal() const
Definition Journal.h:368
Stream error() const
Definition Journal.h:362
Stream debug() const
Definition Journal.h:344
static Sink & getNullSink()
Returns a Sink which does nothing.
Stream warn() const
Definition Journal.h:356
std::set< UInt256 > enabledAmendments() const
Returns the set of amendments this entry reports as enabled.
std::map< UInt256, NetClock::time_point > majorityAmendments() const
Returns a map of amendments that have achieved majority, to the time majority was reached.
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.
std::optional< std::uint64_t > dirInsert(Keylet const &directory, UInt256 const &key, std::function< void(SLE::Ref)> const &describe)
Insert an entry to a directory.
Definition ApplyView.h:373
constexpr auto visit(Visitors &&... visitors) const -> decltype(auto)
Definition Asset.h:117
A currency issued by an account.
Definition Issue.h:18
Currency currency
Definition Issue.h:20
std::optional< UInt256 > hashAt(std::size_t diff) const
Looks up a hash diff slots back from the most recent entry in the sfHashes vector (diff == 0 is the m...
constexpr MPTID const & getMptID() const
Definition MPTIssue.h:43
std::chrono::time_point< NetClock > time_point
Definition chrono.h:48
std::chrono::duration< rep, period > duration
Definition chrono.h:47
A view into a ledger.
Definition ReadView.h:41
virtual Rules const & rules() const =0
Returns the tx processing rules.
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
Definition ReadView.h:106
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
Definition ReadView.h:115
bool enabled(UInt256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:182
bool native() const noexcept
Definition STAmount.h:471
Asset const & asset() const
Definition STAmount.h:496
AccountID const & getIssuer() const
Definition STAmount.h:516
UInt256 const & key() const
Returns the 'key' (or 'index') of this item.
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & ConstRef
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:601
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:464
STVector256 const & getFieldV256(SField const &field) const
Definition STObject.cpp:671
std::size_t size() const
constexpr Zero kZero
Definition Zero.h:30
TER authorizedDepositPreauth(ReadView const &view, STVector256 const &ctx, AccountID const &dst)
Keylet const & skip() noexcept
The index of the "short" skip list.
Definition Indexes.cpp:245
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:415
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Definition Indexes.cpp:483
Keylet unchecked(UInt256 const &key) noexcept
Any ledger entry.
Definition Indexes.cpp:409
Keylet vault(AccountID const &owner, SeqProxy const &seq) noexcept
Definition Indexes.cpp:565
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:233
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Definition Indexes.cpp:559
Keylet child(UInt256 const &key) noexcept
Any item that can be in an owner dir.
Definition Indexes.cpp:239
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
Definition Indexes.cpp:541
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::optional< UInt256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
Definition View.cpp:324
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
TypedField< STInteger< std::uint64_t > > SF_UINT64
Definition SField.h:344
bool isXRP(AccountID const &c)
Definition AccountID.h:84
TER doWithdraw(ApplyViewContext ctx, AccountID const &senderAcct, AccountID const &dstAcct, AccountID const &sourceAcct, XRPAmount priorBalance, STAmount const &destinationAmount, STAmount const &sourceAmount, beast::Journal j)
Pays out a withdrawal from a vault or loan broker pseudo-account.
Definition View.cpp:508
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:409
std::set< UInt256 > getEnabledAmendments(ReadView const &view)
Definition View.cpp:312
TER checkDestinationAndTag(SLE::ConstRef toSle, bool hasDestinationTag)
Checks the destination and tag.
bool dirNext(ApplyView &view, UInt256 const &root, SLE::pointer &page, unsigned int &index, UInt256 &entry)
@ tefBAD_LEDGER
Definition TER.h:164
@ tefINTERNAL
Definition TER.h:167
TER addEmptyHolding(ApplyViewContext ctx, AccountID const &accountID, XRPAmount priorBalance, MPTIssue const &mptIssue, beast::Journal journal)
bool areCompatible(ReadView const &validLedger, ReadView const &testLedger, beast::Journal::Stream const &s, char const *reason)
Return false if the test ledger is provably incompatible with the valid ledger, that is,...
Definition View.cpp:214
ExpiryComparison
Whether an expiration check should be inclusive or exclusive.
Definition View.h:42
Asset assetOfHolding(SLE const &sleShareIssuance, SLE const &sleHolding)
Resolve the underlying asset of a vault share.
std::expected< SLE::pointer, TER > getEffectiveTxReserveSponsor(ApplyViewContext ctx, SLE::ConstRef accountSle)
The transaction's reserve sponsor for the given account, if applicable.
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.
STAmount creditLimit(ReadView const &view, AccountID const &account, AccountID const &issuer, Currency const &currency)
Calculate the maximum amount of IOUs that an account can hold.
constexpr Dest safeCast(Src s) noexcept
Definition safe_cast.h:21
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
STLedgerEntry SLE
BaseUInt< 256 > UInt256
Definition base_uint.h:581
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 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.
bool dirFirst(ApplyView &view, UInt256 const &root, SLE::pointer &page, unsigned int &index, UInt256 &entry)
constexpr std::uint8_t kMaxAssetCheckDepth
Maximum recursion depth for vault shares being put as an asset inside another vault; counted from 0.
Definition Protocol.h:399
static TER withdrawToDestExceedsLimit(ReadView const &view, AccountID const &from, AccountID const &to, STAmount const &amount)
Definition View.cpp:412
TER canWithdraw(ReadView const &view, AccountID const &from, AccountID const &to, SLE::ConstRef toSle, STAmount const &amount, bool hasDestinationTag, std::optional< std::vector< UInt256 > > const &credentialIDs=std::nullopt)
Checks that can withdraw funds from an object to itself or a destination.
Definition View.cpp:438
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:668
STAmount creditBalance(ReadView const &view, AccountID const &account, AccountID const &issuer, Currency const &currency)
Returns the amount of IOUs issued by issuer that are held by an account.
DepositPreauthEntry< ReadView > DepositPreauthEntryR
std::map< UInt256, NetClock::time_point > MajorityAmendmentsT
Definition View.h:121
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.
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
std::function< std::pair< TER, SkipEntry >(LedgerEntryType, UInt256 const &, SLE::pointer &)> EntryDeleter
Deleter function prototype.
Definition View.h:291
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)
TER dirLink(ApplyView &view, AccountID const &owner, SLE::pointer const &object, SF_UINT64 const &node=sfOwnerNode)
Definition View.cpp:385
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
LedgerEntryType
Identifiers for on-ledger objects.
@ tecDIR_FULL
Definition TER.h:298
@ tecINCOMPLETE
Definition TER.h:346
@ tecINTERNAL
Definition TER.h:321
@ tecNO_LINE
Definition TER.h:312
@ tecNO_PERMISSION
Definition TER.h:316
@ tecDUPLICATE
Definition TER.h:326
LedgerHashesEntry< ReadView > LedgerHashesEntryR
TER verifyDepositPreauth(STTx const &tx, ApplyView &view, AccountID const &src, AccountID const &dst, SLE::ConstRef sleDst, beast::Journal j)
std::function< void(SLE::Ref)> describeOwnerDir(AccountID const &account)
Returns a function that sets the owner on a directory SLE.
MajorityAmendmentsT getMajorityAmendments(ReadView const &view)
Definition View.cpp:318
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
TER cleanupOnAccountDelete(ApplyView &view, Keylet const &ownerDirKeylet, EntryDeleter const &deleter, beast::Journal j, std::optional< std::uint16_t > maxNodesToDelete=std::nullopt)
Cleanup owner directory entries on account delete.
AmendmentsEntry< ReadView > AmendmentsEntryR
Bundles the mutable ledger view and the transaction being applied.
Definition ApplyView.h:451
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20
UInt256 key
Definition Keylet.h:21
T time_since_epoch(T... args)