rippled
Loading...
Searching...
No Matches
View.h
1#ifndef XRPL_LEDGER_VIEW_H_INCLUDED
2#define XRPL_LEDGER_VIEW_H_INCLUDED
3
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/ledger/ApplyView.h>
6#include <xrpl/ledger/OpenView.h>
7#include <xrpl/ledger/ReadView.h>
8#include <xrpl/protocol/Asset.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/MPTIssue.h>
11#include <xrpl/protocol/Protocol.h>
12#include <xrpl/protocol/Rate.h>
13#include <xrpl/protocol/STLedgerEntry.h>
14#include <xrpl/protocol/STObject.h>
15#include <xrpl/protocol/Serializer.h>
16#include <xrpl/protocol/TER.h>
17
18#include <functional>
19#include <initializer_list>
20#include <map>
21#include <utility>
22
23namespace xrpl {
24
25enum class WaiveTransferFee : bool { No = false, Yes };
26enum class SkipEntry : bool { No = false, Yes };
27
28//------------------------------------------------------------------------------
29//
30// Observers
31//
32//------------------------------------------------------------------------------
33
55[[nodiscard]] bool
56hasExpired(ReadView const& view, std::optional<std::uint32_t> const& exp);
57
60
63
64[[nodiscard]] bool
65isGlobalFrozen(ReadView const& view, AccountID const& issuer);
66
67[[nodiscard]] bool
68isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue);
69
70[[nodiscard]] bool
71isGlobalFrozen(ReadView const& view, Asset const& asset);
72
73// Note, depth parameter is used to limit the recursion depth
74[[nodiscard]] bool
76 ReadView const& view,
77 AccountID const& account,
78 MPTIssue const& mptShare,
79 int depth);
80
81[[nodiscard]] bool
83 ReadView const& view,
84 AccountID const& account,
85 Currency const& currency,
86 AccountID const& issuer);
87
88[[nodiscard]] inline bool
90 ReadView const& view,
91 AccountID const& account,
92 Issue const& issue)
93{
94 return isIndividualFrozen(view, account, issue.currency, issue.account);
95}
96
97[[nodiscard]] bool
99 ReadView const& view,
100 AccountID const& account,
101 MPTIssue const& mptIssue);
102
103[[nodiscard]] inline bool
105 ReadView const& view,
106 AccountID const& account,
107 Asset const& asset)
108{
109 return std::visit(
110 [&](auto const& issue) {
111 return isIndividualFrozen(view, account, issue);
112 },
113 asset.value());
114}
115
116[[nodiscard]] bool
118 ReadView const& view,
119 AccountID const& account,
120 Currency const& currency,
121 AccountID const& issuer);
122
123[[nodiscard]] inline bool
125 ReadView const& view,
126 AccountID const& account,
127 Issue const& issue,
128 int = 0 /*ignored*/)
129{
130 return isFrozen(view, account, issue.currency, issue.account);
131}
132
133[[nodiscard]] bool
135 ReadView const& view,
136 AccountID const& account,
137 MPTIssue const& mptIssue,
138 int depth = 0);
139
145[[nodiscard]] inline bool
147 ReadView const& view,
148 AccountID const& account,
149 Asset const& asset,
150 int depth = 0)
151{
152 return std::visit(
153 [&](auto const& issue) {
154 return isFrozen(view, account, issue, depth);
155 },
156 asset.value());
157}
158
159[[nodiscard]] inline TER
160checkFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
161{
162 return isFrozen(view, account, issue) ? (TER)tecFROZEN : (TER)tesSUCCESS;
163}
164
165[[nodiscard]] inline TER
167 ReadView const& view,
168 AccountID const& account,
169 MPTIssue const& mptIssue)
170{
171 return isFrozen(view, account, mptIssue) ? (TER)tecLOCKED : (TER)tesSUCCESS;
172}
173
174[[nodiscard]] inline TER
175checkFrozen(ReadView const& view, AccountID const& account, Asset const& asset)
176{
177 return std::visit(
178 [&](auto const& issue) { return checkFrozen(view, account, issue); },
179 asset.value());
180}
181
182[[nodiscard]] bool
184 ReadView const& view,
185 std::initializer_list<AccountID> const& accounts,
186 MPTIssue const& mptIssue,
187 int depth = 0);
188
189[[nodiscard]] inline bool
191 ReadView const& view,
192 std::initializer_list<AccountID> const& accounts,
193 Issue const& issue)
194{
195 for (auto const& account : accounts)
196 {
197 if (isFrozen(view, account, issue.currency, issue.account))
198 return true;
199 }
200 return false;
201}
202
203[[nodiscard]] inline bool
205 ReadView const& view,
206 std::initializer_list<AccountID> const& accounts,
207 Asset const& asset,
208 int depth = 0)
209{
210 return std::visit(
211 [&]<ValidIssueType TIss>(TIss const& issue) {
212 if constexpr (std::is_same_v<TIss, Issue>)
213 return isAnyFrozen(view, accounts, issue);
214 else
215 return isAnyFrozen(view, accounts, issue, depth);
216 },
217 asset.value());
218}
219
220[[nodiscard]] bool
222 ReadView const& view,
223 AccountID const& account,
224 Currency const& currency,
225 AccountID const& issuer);
226
227[[nodiscard]] inline bool
229 ReadView const& view,
230 AccountID const& account,
231 Issue const& issue,
232 int = 0 /*ignored*/)
233{
234 return isDeepFrozen(view, account, issue.currency, issue.account);
235}
236
237[[nodiscard]] inline bool
239 ReadView const& view,
240 AccountID const& account,
241 MPTIssue const& mptIssue,
242 int depth = 0)
243{
244 // Unlike IOUs, frozen / locked MPTs are not allowed to send or receive
245 // funds, so checking "deep frozen" is the same as checking "frozen".
246 return isFrozen(view, account, mptIssue, depth);
247}
248
254[[nodiscard]] inline bool
256 ReadView const& view,
257 AccountID const& account,
258 Asset const& asset,
259 int depth = 0)
260{
261 return std::visit(
262 [&](auto const& issue) {
263 return isDeepFrozen(view, account, issue, depth);
264 },
265 asset.value());
266}
267
268[[nodiscard]] inline TER
270 ReadView const& view,
271 AccountID const& account,
272 Issue const& issue)
273{
274 return isDeepFrozen(view, account, issue) ? (TER)tecFROZEN
275 : (TER)tesSUCCESS;
276}
277
278[[nodiscard]] inline TER
280 ReadView const& view,
281 AccountID const& account,
282 MPTIssue const& mptIssue)
283{
284 return isDeepFrozen(view, account, mptIssue) ? (TER)tecLOCKED
285 : (TER)tesSUCCESS;
286}
287
288[[nodiscard]] inline TER
290 ReadView const& view,
291 AccountID const& account,
292 Asset const& asset)
293{
294 return std::visit(
295 [&](auto const& issue) {
296 return checkDeepFrozen(view, account, issue);
297 },
298 asset.value());
299}
300
301[[nodiscard]] bool
303 ReadView const& view,
304 AccountID const& account,
305 Issue const& asset,
306 Issue const& asset2);
307
308// Returns the amount an account can spend without going into debt.
309//
310// <-- saAmount: amount of currency held by account. May be negative.
311[[nodiscard]] STAmount
313 ReadView const& view,
314 AccountID const& account,
315 Currency const& currency,
316 AccountID const& issuer,
317 FreezeHandling zeroIfFrozen,
319
320[[nodiscard]] STAmount
322 ReadView const& view,
323 AccountID const& account,
324 Issue const& issue,
325 FreezeHandling zeroIfFrozen,
327
328[[nodiscard]] STAmount
330 ReadView const& view,
331 AccountID const& account,
332 MPTIssue const& mptIssue,
333 FreezeHandling zeroIfFrozen,
334 AuthHandling zeroIfUnauthorized,
336
337[[nodiscard]] STAmount
339 ReadView const& view,
340 AccountID const& account,
341 Asset const& asset,
342 FreezeHandling zeroIfFrozen,
343 AuthHandling zeroIfUnauthorized,
345
346// Returns the amount an account can spend total.
347//
348// These functions use accountHolds, but unlike accountHolds:
349// * The account can go into debt.
350// * If the account is the asset issuer the only limit is defined by the asset /
351// issuance.
352//
353// <-- saAmount: amount of currency held by account. May be negative.
354[[nodiscard]] STAmount
356 ReadView const& view,
357 AccountID const& account,
358 Currency const& currency,
359 AccountID const& issuer,
360 FreezeHandling zeroIfFrozen,
362
363[[nodiscard]] STAmount
365 ReadView const& view,
366 AccountID const& account,
367 Issue const& issue,
368 FreezeHandling zeroIfFrozen,
370
371[[nodiscard]] STAmount
373 ReadView const& view,
374 AccountID const& account,
375 MPTIssue const& mptIssue,
376 FreezeHandling zeroIfFrozen,
377 AuthHandling zeroIfUnauthorized,
379
380[[nodiscard]] STAmount
382 ReadView const& view,
383 AccountID const& account,
384 Asset const& asset,
385 FreezeHandling zeroIfFrozen,
386 AuthHandling zeroIfUnauthorized,
388
389// Returns the amount an account can spend of the currency type saDefault, or
390// returns saDefault if this account is the issuer of the currency in
391// question. Should be used in favor of accountHolds when questioning how much
392// an account can spend while also allowing currency issuers to spend
393// unlimited amounts of their own currency (since they can always issue more).
394[[nodiscard]] STAmount
396 ReadView const& view,
397 AccountID const& id,
398 STAmount const& saDefault,
399 FreezeHandling freezeHandling,
401
402// Return the account's liquid (not reserved) XRP. Generally prefer
403// calling accountHolds() over this interface. However, this interface
404// allows the caller to temporarily adjust the owner count should that be
405// necessary.
406//
407// @param ownerCountAdj positive to add to count, negative to reduce count.
408[[nodiscard]] XRPAmount
410 ReadView const& view,
411 AccountID const& id,
412 std::int32_t ownerCountAdj,
414
416void
418 ReadView const& view,
419 Keylet const& root,
420 std::function<void(std::shared_ptr<SLE const> const&)> const& f);
421
428bool
430 ReadView const& view,
431 Keylet const& root,
432 uint256 const& after,
433 std::uint64_t const hint,
434 unsigned int limit,
435 std::function<bool(std::shared_ptr<SLE const> const&)> const& f);
436
438inline void
440 ReadView const& view,
441 AccountID const& id,
442 std::function<void(std::shared_ptr<SLE const> const&)> const& f)
443{
444 return forEachItem(view, keylet::ownerDir(id), f);
445}
446
453inline bool
455 ReadView const& view,
456 AccountID const& id,
457 uint256 const& after,
458 std::uint64_t const hint,
459 unsigned int limit,
460 std::function<bool(std::shared_ptr<SLE const> const&)> const& f)
461{
462 return forEachItemAfter(view, keylet::ownerDir(id), after, hint, limit, f);
463}
464
470[[nodiscard]] Rate
471transferRate(ReadView const& view, AccountID const& issuer);
472
478[[nodiscard]] Rate
479transferRate(ReadView const& view, MPTID const& issuanceID);
480
485[[nodiscard]] Rate
486transferRate(ReadView const& view, STAmount const& amount);
487
491[[nodiscard]] bool
492dirIsEmpty(ReadView const& view, Keylet const& k);
493
494// Return the list of enabled amendments
495[[nodiscard]] std::set<uint256>
496getEnabledAmendments(ReadView const& view);
497
498// Return a map of amendments that have achieved majority
500[[nodiscard]] majorityAmendments_t
502
512[[nodiscard]] std::optional<uint256>
513hashOfSeq(ReadView const& ledger, LedgerIndex seq, beast::Journal journal);
514
527inline LedgerIndex
529{
530 return (requested + 255) & (~255);
531}
532
538[[nodiscard]] bool
540 ReadView const& validLedger,
541 ReadView const& testLedger,
543 char const* reason);
544
545[[nodiscard]] bool
547 uint256 const& validHash,
548 LedgerIndex validIndex,
549 ReadView const& testLedger,
551 char const* reason);
552
553//------------------------------------------------------------------------------
554//
555// Modifiers
556//
557//------------------------------------------------------------------------------
558
560void
562 ApplyView& view,
563 std::shared_ptr<SLE> const& sle,
564 std::int32_t amount,
566
582bool
584 ReadView const& view,
585 uint256 const& root,
587 unsigned int& index,
588 uint256& entry);
589
590bool
592 ApplyView& view,
593 uint256 const& root,
595 unsigned int& index,
596 uint256& entry);
614bool
616 ReadView const& view,
617 uint256 const& root,
619 unsigned int& index,
620 uint256& entry);
621
622bool
623dirNext(
624 ApplyView& view,
625 uint256 const& root,
627 unsigned int& index,
628 uint256& entry);
631[[nodiscard]] std::function<void(SLE::ref)>
632describeOwnerDir(AccountID const& account);
633
634[[nodiscard]] TER
635dirLink(
636 ApplyView& view,
637 AccountID const& owner,
638 std::shared_ptr<SLE>& object,
639 SF_UINT64 const& node = sfOwnerNode);
640
642pseudoAccountAddress(ReadView const& view, uint256 const& pseudoOwnerKey);
643
652[[nodiscard]] Expected<std::shared_ptr<SLE>, TER>
654 ApplyView& view,
655 uint256 const& pseudoOwnerKey,
656 SField const& ownerField);
657
658// Returns true iff sleAcct is a pseudo-account or specific
659// pseudo-accounts in pseudoFieldFilter.
660//
661// Returns false if sleAcct is
662// * NOT a pseudo-account OR
663// * NOT a ltACCOUNT_ROOT OR
664// * null pointer
665[[nodiscard]] bool
668 std::set<SField const*> const& pseudoFieldFilter = {});
669
670// Returns the list of fields that define an ACCOUNT_ROOT as a pseudo-account if
671// set
672// Pseudo-account designator fields MUST be maintained by including the
673// SField::sMD_PseudoAccount flag in the SField definition. (Don't forget to
674// "| SField::sMD_Default"!) The fields do NOT need to be amendment-gated,
675// since a non-active amendment will not set any field, by definition.
676// Specific properties of a pseudo-account are NOT checked here, that's what
677// InvariantCheck is for.
678[[nodiscard]] std::vector<SField const*> const&
680
681[[nodiscard]] inline bool
683 ReadView const& view,
684 AccountID const& accountId,
685 std::set<SField const*> const& pseudoFieldFilter = {})
686{
687 return isPseudoAccount(
688 view.read(keylet::account(accountId)), pseudoFieldFilter);
689}
690
691[[nodiscard]] TER
692canAddHolding(ReadView const& view, Asset const& asset);
693
699[[nodiscard]] TER
700checkDestinationAndTag(SLE::const_ref toSle, bool hasDestinationTag);
701
714[[nodiscard]] TER
716 AccountID const& from,
717 ReadView const& view,
718 AccountID const& to,
719 SLE::const_ref toSle,
720 bool hasDestinationTag);
721
734[[nodiscard]] TER
736 AccountID const& from,
737 ReadView const& view,
738 AccountID const& to,
739 bool hasDestinationTag);
740
753[[nodiscard]] TER
754canWithdraw(ReadView const& view, STTx const& tx);
755
756[[nodiscard]] TER
758 ApplyView& view,
759 STTx const& tx,
760 AccountID const& senderAcct,
761 AccountID const& dstAcct,
762 AccountID const& sourceAcct,
763 XRPAmount priorBalance,
764 STAmount const& amount,
766
769[[nodiscard]] TER
771 ApplyView& view,
772 AccountID const& accountID,
773 XRPAmount priorBalance,
774 Issue const& issue,
775 beast::Journal journal);
776
777[[nodiscard]] TER
779 ApplyView& view,
780 AccountID const& accountID,
781 XRPAmount priorBalance,
782 MPTIssue const& mptIssue,
783 beast::Journal journal);
784
785[[nodiscard]] inline TER
787 ApplyView& view,
788 AccountID const& accountID,
789 XRPAmount priorBalance,
790 Asset const& asset,
791 beast::Journal journal)
792{
793 return std::visit(
794 [&]<ValidIssueType TIss>(TIss const& issue) -> TER {
795 return addEmptyHolding(
796 view, accountID, priorBalance, issue, journal);
797 },
798 asset.value());
799}
800
801[[nodiscard]] TER
803 ApplyView& view,
804 XRPAmount const& priorBalance,
805 MPTID const& mptIssuanceID,
806 AccountID const& account,
807 beast::Journal journal,
808 std::uint32_t flags = 0,
810
811// VFALCO NOTE Both STAmount parameters should just
812// be "Amount", a unit-less number.
813//
818[[nodiscard]] TER
820 ApplyView& view,
821 bool const bSrcHigh,
822 AccountID const& uSrcAccountID,
823 AccountID const& uDstAccountID,
824 uint256 const& uIndex, // --> ripple state entry
825 SLE::ref sleAccount, // --> the account being set.
826 bool const bAuth, // --> authorize account.
827 bool const bNoRipple, // --> others cannot ripple through
828 bool const bFreeze, // --> funds cannot leave
829 bool bDeepFreeze, // --> can neither receive nor send funds
830 STAmount const& saBalance, // --> balance of account being set.
831 // Issuer should be noAccount()
832 STAmount const& saLimit, // --> limit for account being set.
833 // Issuer should be the account being set.
834 std::uint32_t uSrcQualityIn,
835 std::uint32_t uSrcQualityOut,
837
838[[nodiscard]] TER
840 ApplyView& view,
841 AccountID const& accountID,
842 Issue const& issue,
843 beast::Journal journal);
844
845[[nodiscard]] TER
847 ApplyView& view,
848 AccountID const& accountID,
849 MPTIssue const& mptIssue,
850 beast::Journal journal);
851
852[[nodiscard]] inline TER
854 ApplyView& view,
855 AccountID const& accountID,
856 Asset const& asset,
857 beast::Journal journal)
858{
859 return std::visit(
860 [&]<ValidIssueType TIss>(TIss const& issue) -> TER {
861 return removeEmptyHolding(view, accountID, issue, journal);
862 },
863 asset.value());
864}
865
866[[nodiscard]] TER
868 ApplyView& view,
869 std::shared_ptr<SLE> const& sleRippleState,
870 AccountID const& uLowAccountID,
871 AccountID const& uHighAccountID,
873
880// [[nodiscard]] // nodiscard commented out so Flow, BookTip and others compile.
881TER
882offerDelete(ApplyView& view, std::shared_ptr<SLE> const& sle, beast::Journal j);
883
884//------------------------------------------------------------------------------
885
886//
887// Money Transfers
888//
889
890// Direct send w/o fees:
891// - Redeeming IOUs and/or sending sender's own IOUs.
892// - Create trust line of needed.
893// --> bCheckIssuer : normally require issuer to be involved.
894// [[nodiscard]] // nodiscard commented out so DirectStep.cpp compiles.
895
899TER
901 ApplyView& view,
902 AccountID const& uSenderID,
903 AccountID const& uReceiverID,
904 STAmount const& saAmount,
905 bool bCheckIssuer,
907
908TER
910 ApplyView& view,
911 AccountID const& uGrantorID,
912 STAmount const& saAmount,
914
915TER
917 ApplyView& view,
918 AccountID const& uGrantorID,
919 AccountID const& uGranteeID,
920 STAmount const& netAmount,
921 STAmount const& grossAmount,
923
927[[nodiscard]] TER
929 ApplyView& view,
930 AccountID const& from,
931 AccountID const& to,
932 STAmount const& saAmount,
935
943[[nodiscard]] TER
945 ApplyView& view,
946 AccountID const& senderID,
947 Asset const& asset,
948 MultiplePaymentDestinations const& receivers,
951
952[[nodiscard]] TER
954 ApplyView& view,
955 AccountID const& account,
956 STAmount const& amount,
957 Issue const& issue,
959
960[[nodiscard]] TER
962 ApplyView& view,
963 AccountID const& account,
964 STAmount const& amount,
965 Issue const& issue,
967
968[[nodiscard]] TER
970 ApplyView& view,
971 AccountID const& from,
972 AccountID const& to,
973 STAmount const& amount,
975
976/* Check if MPToken (for MPT) or trust line (for IOU) exists:
977 * - StrongAuth - before checking if authorization is required
978 * - WeakAuth
979 * for MPT - after checking lsfMPTRequireAuth flag
980 * for IOU - do not check if trust line exists
981 * - Legacy
982 * for MPT - before checking lsfMPTRequireAuth flag i.e. same as StrongAuth
983 * for IOU - do not check if trust line exists i.e. same as WeakAuth
984 */
986
1004[[nodiscard]] TER
1006 ReadView const& view,
1007 Issue const& issue,
1008 AccountID const& account,
1009 AuthType authType = AuthType::Legacy);
1010
1034[[nodiscard]] TER
1036 ReadView const& view,
1037 MPTIssue const& mptIssue,
1038 AccountID const& account,
1039 AuthType authType = AuthType::Legacy,
1040 int depth = 0);
1041
1042[[nodiscard]] TER inline requireAuth(
1043 ReadView const& view,
1044 Asset const& asset,
1045 AccountID const& account,
1046 AuthType authType = AuthType::Legacy)
1047{
1048 return std::visit(
1049 [&]<ValidIssueType TIss>(TIss const& issue_) {
1050 return requireAuth(view, issue_, account, authType);
1051 },
1052 asset.value());
1053}
1054
1078[[nodiscard]] TER
1080 ApplyView& view,
1081 MPTID const& mptIssuanceID,
1082 AccountID const& account,
1083 XRPAmount const& priorBalance,
1084 beast::Journal j);
1085
1090[[nodiscard]] TER
1092 ReadView const& view,
1093 MPTIssue const& mptIssue,
1094 AccountID const& from,
1095 AccountID const& to);
1096
1097[[nodiscard]] TER
1099 ReadView const& view,
1100 Issue const& issue,
1101 AccountID const& from,
1102 AccountID const& to);
1103
1104[[nodiscard]] TER inline canTransfer(
1105 ReadView const& view,
1106 Asset const& asset,
1107 AccountID const& from,
1108 AccountID const& to)
1109{
1110 return std::visit(
1111 [&]<ValidIssueType TIss>(TIss const& issue) -> TER {
1112 return canTransfer(view, issue, from, to);
1113 },
1114 asset.value());
1115}
1116
1123 uint256 const&,
1132[[nodiscard]] TER
1134 ApplyView& view,
1135 Keylet const& ownerDirKeylet,
1136 EntryDeleter const& deleter,
1138 std::optional<std::uint16_t> maxNodesToDelete = std::nullopt);
1139
1144[[nodiscard]] TER
1146 ApplyView& view,
1147 std::shared_ptr<SLE> sleState,
1148 std::optional<AccountID> const& ammAccountID,
1149 beast::Journal j);
1150
1151// From the perspective of a vault, return the number of shares to give the
1152// depositor when they deposit a fixed amount of assets. Since shares are MPT
1153// this number is integral and always truncated in this calculation.
1154[[nodiscard]] std::optional<STAmount>
1156 std::shared_ptr<SLE const> const& vault,
1157 std::shared_ptr<SLE const> const& issuance,
1158 STAmount const& assets);
1159
1160// From the perspective of a vault, return the number of assets to take from
1161// depositor when they receive a fixed amount of shares. Note, since shares are
1162// MPT, they are always an integral number.
1163[[nodiscard]] std::optional<STAmount>
1165 std::shared_ptr<SLE const> const& vault,
1166 std::shared_ptr<SLE const> const& issuance,
1167 STAmount const& shares);
1168
1169enum class TruncateShares : bool { no = false, yes = true };
1170
1171// From the perspective of a vault, return the number of shares to demand from
1172// the depositor when they ask to withdraw a fixed amount of assets. Since
1173// shares are MPT this number is integral, and it will be rounded to nearest
1174// unless explicitly requested to be truncated instead.
1175[[nodiscard]] std::optional<STAmount>
1177 std::shared_ptr<SLE const> const& vault,
1178 std::shared_ptr<SLE const> const& issuance,
1179 STAmount const& assets,
1181
1182// From the perspective of a vault, return the number of assets to give the
1183// depositor when they redeem a fixed amount of shares. Note, since shares are
1184// MPT, they are always an integral number.
1185[[nodiscard]] std::optional<STAmount>
1187 std::shared_ptr<SLE const> const& vault,
1188 std::shared_ptr<SLE const> const& issuance,
1189 STAmount const& shares);
1190
1197bool
1199
1200} // namespace xrpl
1201
1202#endif
Provide a light-weight way to check active() before string formatting.
Definition Journal.h:186
A generic endpoint for log messages.
Definition Journal.h:41
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:124
constexpr value_type const & value() const
Definition Asset.h:157
A currency issued by an account.
Definition Issue.h:14
Currency currency
Definition Issue.h:16
AccountID account
Definition Issue.h:17
std::chrono::time_point< NetClock > time_point
Definition chrono.h:50
A view into a ledger.
Definition ReadView.h:32
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry const > const & const_ref
T is_same_v
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:356
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:166
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
TypedField< STInteger< std::uint64_t > > SF_UINT64
Definition SField.h:333
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 uSrcQualityIn, std::uint32_t uSrcQualityOut, beast::Journal j)
Create a trust line.
Definition View.cpp:1635
std::optional< STAmount > sharesToAssetsDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
Definition View.cpp:3568
TER checkDeepFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
Definition View.h:269
base_uint< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition UintTypes.h:37
std::vector< SField const * > const & getPseudoAccountFields()
Definition View.cpp:1199
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
Definition View.cpp:721
TER addEmptyHolding(ApplyView &view, AccountID const &accountID, XRPAmount priorBalance, Issue const &issue, beast::Journal journal)
Any transactors that call addEmptyHolding() in doApply must call canAddHolding() in preflight with th...
Definition View.cpp:1439
FreezeHandling
Controls the treatment of frozen account balances.
Definition View.h:59
@ fhZERO_IF_FROZEN
Definition View.h:59
@ fhIGNORE_FREEZE
Definition View.h:59
bool dirFirst(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
Definition View.cpp:104
AccountID pseudoAccountAddress(ReadView const &view, uint256 const &pseudoOwnerKey)
Definition View.cpp:1175
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
Definition View.cpp:1009
TER canAddHolding(ReadView const &view, Asset const &asset)
Definition View.cpp:1322
std::set< uint256 > getEnabledAmendments(ReadView const &view)
Definition View.cpp:1023
TER issueIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
Definition View.cpp:2876
TER removeEmptyHolding(ApplyView &view, AccountID const &accountID, Issue const &issue, beast::Journal journal)
Definition View.cpp:1762
bool isVaultPseudoAccountFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptShare, int depth)
Definition View.cpp:288
TER rippleUnlockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, AccountID const &uGranteeID, STAmount const &netAmount, STAmount const &grossAmount, beast::Journal j)
Definition View.cpp:3748
TER doWithdraw(ApplyView &view, STTx const &tx, AccountID const &senderAcct, AccountID const &dstAcct, AccountID const &sourceAcct, XRPAmount priorBalance, STAmount const &amount, beast::Journal j)
Definition View.cpp:1390
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
Definition View.cpp:154
TER checkFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
Definition View.h:160
SkipEntry
Definition View.h:26
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items in the given directory.
Definition View.cpp:759
bool isAnyFrozen(ReadView const &view, std::initializer_list< AccountID > const &accounts, MPTIssue const &mptIssue, int depth=0)
Definition View.cpp:263
WaiveTransferFee
Definition View.h:25
Number root(Number f, unsigned d)
Definition Number.cpp:644
bool cdirNext(ReadView const &view, uint256 const &root, std::shared_ptr< SLE const > &page, unsigned int &index, uint256 &entry)
Returns the next entry in the directory, advancing the index.
Definition View.cpp:137
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:29
TER authorizeMPToken(ApplyView &view, XRPAmount const &priorBalance, MPTID const &mptIssuanceID, AccountID const &account, beast::Journal journal, std::uint32_t flags=0, std::optional< AccountID > holderID=std::nullopt)
Definition View.cpp:1515
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
Definition View.cpp:3463
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
Definition View.cpp:331
bool cdirFirst(ReadView const &view, uint256 const &root, std::shared_ptr< SLE const > &page, unsigned int &index, uint256 &entry)
Returns the first entry in the directory, advancing the index.
Definition View.cpp:126
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
Definition View.cpp:461
bool areCompatible(ReadView const &validLedger, ReadView const &testLedger, beast::Journal::Stream &s, char const *reason)
Return false if the test ledger is provably incompatible with the valid ledger, that is,...
Definition View.cpp:901
base_uint< 256 > uint256
Definition base_uint.h:539
LedgerIndex getCandidateLedger(LedgerIndex requested)
Find a ledger index from which we could easily get the requested ledger.
Definition View.h:528
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
Definition View.cpp:1226
TruncateShares
Definition View.h:1169
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Calls static accountSendIOU if saAmount represents Issue.
Definition View.cpp:2777
std::optional< STAmount > assetsToSharesDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets)
Definition View.cpp:3540
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
Definition View.cpp:657
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
Definition View.cpp:163
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
Definition View.cpp:1063
std::optional< STAmount > assetsToSharesWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets, TruncateShares truncate=TruncateShares::no)
Definition View.cpp:3597
TERSubset< CanCvtToTER > TER
Definition TER.h:630
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
Definition View.cpp:1134
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:255
base_uint< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
Definition UintTypes.h:45
AuthHandling
Controls the treatment of unauthorized MPT balances.
Definition View.h:62
@ ahIGNORE_AUTH
Definition View.h:62
@ ahZERO_IF_UNAUTHORIZED
Definition View.h:62
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
Definition View.cpp:864
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition View.cpp:1040
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:3922
AuthType
Definition View.h:985
TER requireAuth(ReadView const &view, Issue const &issue, AccountID const &account, AuthType authType=AuthType::Legacy)
Check if the account lacks required authorization.
Definition View.cpp:3096
TER canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to)
Check if the destination account is allowed to receive MPT.
Definition View.cpp:3325
bool isFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
Definition View.cpp:228
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
Definition View.cpp:3051
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Definition View.cpp:1152
TER canWithdraw(AccountID const &from, ReadView const &view, AccountID const &to, SLE::const_ref toSle, bool hasDestinationTag)
Checks that can withdraw funds from an object to itself or a destination.
Definition View.cpp:1346
TER dirLink(ApplyView &view, AccountID const &owner, std::shared_ptr< SLE > &object, SF_UINT64 const &node=sfOwnerNode)
Definition View.cpp:1160
bool isIndividualFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
Definition View.cpp:194
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
Definition View.cpp:1903
STAmount accountSpendable(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
Definition View.cpp:567
TER redeemIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
Definition View.cpp:2976
std::optional< STAmount > sharesToAssetsWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
Definition View.cpp:3626
TER rippleLockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, STAmount const &saAmount, beast::Journal j)
Definition View.cpp:3651
LedgerEntryType
Identifiers for on-ledger objects.
@ tecLOCKED
Definition TER.h:340
@ tecFROZEN
Definition TER.h:285
bool forEachItemAfter(ReadView const &view, Keylet const &root, uint256 const &after, std::uint64_t const hint, unsigned int limit, std::function< bool(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items after an item in the given directory.
Definition View.cpp:786
TER enforceMPTokenAuthorization(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, XRPAmount const &priorBalance, beast::Journal j)
Enforce account has MPToken to match its authorization.
Definition View.cpp:3224
Expected< std::shared_ptr< SLE >, TER > createPseudoAccount(ApplyView &view, uint256 const &pseudoOwnerKey, SField const &ownerField)
Create pseudo-account, storing pseudoOwnerKey into ownerField.
Definition View.cpp:1246
TER checkDestinationAndTag(SLE::const_ref toSle, bool hasDestinationTag)
Validates that the destination SLE and tag are valid.
Definition View.cpp:1332
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!...
Definition View.cpp:2798
@ no
Definition Steps.h:26
@ yes
Definition Steps.h:26
TER trustDelete(ApplyView &view, std::shared_ptr< SLE > const &sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
Definition View.cpp:1863
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
Definition View.cpp:357
@ tesSUCCESS
Definition TER.h:226
bool dirNext(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
Definition View.cpp:115
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.
TER rippleCredit(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
Calls static rippleCreditIOU if saAmount represents Issue.
Definition View.cpp:3513
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20
T visit(T... args)