rippled
Loading...
Searching...
No Matches
View.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_LEDGER_VIEW_H_INCLUDED
21#define RIPPLE_LEDGER_VIEW_H_INCLUDED
22
23#include <xrpld/ledger/ApplyView.h>
24#include <xrpld/ledger/OpenView.h>
25#include <xrpld/ledger/ReadView.h>
26#include <xrpl/beast/utility/Journal.h>
27#include <xrpl/protocol/MPTIssue.h>
28#include <xrpl/protocol/Protocol.h>
29#include <xrpl/protocol/Rate.h>
30#include <xrpl/protocol/STLedgerEntry.h>
31#include <xrpl/protocol/STObject.h>
32#include <xrpl/protocol/Serializer.h>
33#include <xrpl/protocol/TER.h>
34
35#include <functional>
36#include <map>
37#include <utility>
38
39namespace ripple {
40
41enum class WaiveTransferFee : bool { No = false, Yes };
42enum class SkipEntry : bool { No = false, Yes };
43
44//------------------------------------------------------------------------------
45//
46// Observers
47//
48//------------------------------------------------------------------------------
49
71[[nodiscard]] bool
72hasExpired(ReadView const& view, std::optional<std::uint32_t> const& exp);
73
76
79
80[[nodiscard]] bool
81isGlobalFrozen(ReadView const& view, AccountID const& issuer);
82
83[[nodiscard]] bool
84isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue);
85
86[[nodiscard]] bool
87isGlobalFrozen(ReadView const& view, Asset const& asset);
88
89[[nodiscard]] bool
91 ReadView const& view,
92 AccountID const& account,
93 Currency const& currency,
94 AccountID const& issuer);
95
96[[nodiscard]] inline bool
98 ReadView const& view,
99 AccountID const& account,
100 Issue const& issue)
101{
102 return isIndividualFrozen(view, account, issue.currency, issue.account);
103}
104
105[[nodiscard]] bool
107 ReadView const& view,
108 AccountID const& account,
109 MPTIssue const& mptIssue);
110
111[[nodiscard]] inline bool
113 ReadView const& view,
114 AccountID const& account,
115 Asset const& asset)
116{
117 return std::visit(
118 [&](auto const& issue) {
119 return isIndividualFrozen(view, account, issue);
120 },
121 asset.value());
122}
123
124[[nodiscard]] bool
126 ReadView const& view,
127 AccountID const& account,
128 Currency const& currency,
129 AccountID const& issuer);
130
131[[nodiscard]] inline bool
132isFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
133{
134 return isFrozen(view, account, issue.currency, issue.account);
135}
136
137[[nodiscard]] bool
139 ReadView const& view,
140 AccountID const& account,
141 MPTIssue const& mptIssue);
142
143[[nodiscard]] inline bool
144isFrozen(ReadView const& view, AccountID const& account, Asset const& asset)
145{
146 return std::visit(
147 [&](auto const& issue) { return isFrozen(view, account, issue); },
148 asset.value());
149}
150
151[[nodiscard]] bool
153 ReadView const& view,
154 AccountID const& account,
155 Currency const& currency,
156 AccountID const& issuer);
157
158[[nodiscard]] bool
160 ReadView const& view,
161 AccountID const& account,
162 Issue const& asset,
163 Issue const& asset2);
164
165// Returns the amount an account can spend without going into debt.
166//
167// <-- saAmount: amount of currency held by account. May be negative.
168[[nodiscard]] STAmount
170 ReadView const& view,
171 AccountID const& account,
172 Currency const& currency,
173 AccountID const& issuer,
174 FreezeHandling zeroIfFrozen,
176
177[[nodiscard]] STAmount
179 ReadView const& view,
180 AccountID const& account,
181 Issue const& issue,
182 FreezeHandling zeroIfFrozen,
184
185[[nodiscard]] STAmount
187 ReadView const& view,
188 AccountID const& account,
189 MPTIssue const& mptIssue,
190 FreezeHandling zeroIfFrozen,
191 AuthHandling zeroIfUnauthorized,
193
194// Returns the amount an account can spend of the currency type saDefault, or
195// returns saDefault if this account is the issuer of the currency in
196// question. Should be used in favor of accountHolds when questioning how much
197// an account can spend while also allowing currency issuers to spend
198// unlimited amounts of their own currency (since they can always issue more).
199[[nodiscard]] STAmount
201 ReadView const& view,
202 AccountID const& id,
203 STAmount const& saDefault,
204 FreezeHandling freezeHandling,
206
207// Return the account's liquid (not reserved) XRP. Generally prefer
208// calling accountHolds() over this interface. However, this interface
209// allows the caller to temporarily adjust the owner count should that be
210// necessary.
211//
212// @param ownerCountAdj positive to add to count, negative to reduce count.
213[[nodiscard]] XRPAmount
215 ReadView const& view,
216 AccountID const& id,
217 std::int32_t ownerCountAdj,
219
221void
223 ReadView const& view,
224 Keylet const& root,
225 std::function<void(std::shared_ptr<SLE const> const&)> const& f);
226
233bool
235 ReadView const& view,
236 Keylet const& root,
237 uint256 const& after,
238 std::uint64_t const hint,
239 unsigned int limit,
240 std::function<bool(std::shared_ptr<SLE const> const&)> const& f);
241
243inline void
245 ReadView const& view,
246 AccountID const& id,
247 std::function<void(std::shared_ptr<SLE const> const&)> const& f)
248{
249 return forEachItem(view, keylet::ownerDir(id), f);
250}
251
258inline bool
260 ReadView const& view,
261 AccountID const& id,
262 uint256 const& after,
263 std::uint64_t const hint,
264 unsigned int limit,
265 std::function<bool(std::shared_ptr<SLE const> const&)> const& f)
266{
267 return forEachItemAfter(view, keylet::ownerDir(id), after, hint, limit, f);
268}
269
275[[nodiscard]] Rate
276transferRate(ReadView const& view, AccountID const& issuer);
277
283[[nodiscard]] Rate
284transferRate(ReadView const& view, MPTID const& issuanceID);
285
289[[nodiscard]] bool
290dirIsEmpty(ReadView const& view, Keylet const& k);
291
292// Return the list of enabled amendments
293[[nodiscard]] std::set<uint256>
294getEnabledAmendments(ReadView const& view);
295
296// Return a map of amendments that have achieved majority
298[[nodiscard]] majorityAmendments_t
300
310[[nodiscard]] std::optional<uint256>
311hashOfSeq(ReadView const& ledger, LedgerIndex seq, beast::Journal journal);
312
325inline LedgerIndex
327{
328 return (requested + 255) & (~255);
329}
330
336[[nodiscard]] bool
338 ReadView const& validLedger,
339 ReadView const& testLedger,
341 const char* reason);
342
343[[nodiscard]] bool
345 uint256 const& validHash,
346 LedgerIndex validIndex,
347 ReadView const& testLedger,
349 const char* reason);
350
351//------------------------------------------------------------------------------
352//
353// Modifiers
354//
355//------------------------------------------------------------------------------
356
358void
360 ApplyView& view,
361 std::shared_ptr<SLE> const& sle,
362 std::int32_t amount,
364
380bool
382 ReadView const& view,
383 uint256 const& root,
385 unsigned int& index,
386 uint256& entry);
387
388bool
390 ApplyView& view,
391 uint256 const& root,
393 unsigned int& index,
394 uint256& entry);
412bool
414 ReadView const& view,
415 uint256 const& root,
417 unsigned int& index,
418 uint256& entry);
419
420bool
421dirNext(
422 ApplyView& view,
423 uint256 const& root,
425 unsigned int& index,
426 uint256& entry);
429[[nodiscard]] std::function<void(SLE::ref)>
430describeOwnerDir(AccountID const& account);
431
432// VFALCO NOTE Both STAmount parameters should just
433// be "Amount", a unit-less number.
434//
439[[nodiscard]] TER
441 ApplyView& view,
442 const bool bSrcHigh,
443 AccountID const& uSrcAccountID,
444 AccountID const& uDstAccountID,
445 uint256 const& uIndex, // --> ripple state entry
446 SLE::ref sleAccount, // --> the account being set.
447 const bool bAuth, // --> authorize account.
448 const bool bNoRipple, // --> others cannot ripple through
449 const bool bFreeze, // --> funds cannot leave
450 bool bDeepFreeze, // --> can neither receive nor send funds
451 STAmount const& saBalance, // --> balance of account being set.
452 // Issuer should be noAccount()
453 STAmount const& saLimit, // --> limit for account being set.
454 // Issuer should be the account being set.
455 std::uint32_t uSrcQualityIn,
456 std::uint32_t uSrcQualityOut,
458
459[[nodiscard]] TER
461 ApplyView& view,
462 std::shared_ptr<SLE> const& sleRippleState,
463 AccountID const& uLowAccountID,
464 AccountID const& uHighAccountID,
466
473// [[nodiscard]] // nodiscard commented out so Flow, BookTip and others compile.
474TER
475offerDelete(ApplyView& view, std::shared_ptr<SLE> const& sle, beast::Journal j);
476
477//------------------------------------------------------------------------------
478
479//
480// Money Transfers
481//
482
483// Direct send w/o fees:
484// - Redeeming IOUs and/or sending sender's own IOUs.
485// - Create trust line of needed.
486// --> bCheckIssuer : normally require issuer to be involved.
487// [[nodiscard]] // nodiscard commented out so DirectStep.cpp compiles.
488
492TER
494 ApplyView& view,
495 AccountID const& uSenderID,
496 AccountID const& uReceiverID,
497 STAmount const& saAmount,
498 bool bCheckIssuer,
500
504[[nodiscard]] TER
506 ApplyView& view,
507 AccountID const& from,
508 AccountID const& to,
509 STAmount const& saAmount,
512
513[[nodiscard]] TER
515 ApplyView& view,
516 AccountID const& account,
517 STAmount const& amount,
518 Issue const& issue,
520
521[[nodiscard]] TER
523 ApplyView& view,
524 AccountID const& account,
525 STAmount const& amount,
526 Issue const& issue,
528
529[[nodiscard]] TER
531 ApplyView& view,
532 AccountID const& from,
533 AccountID const& to,
534 STAmount const& amount,
536
541[[nodiscard]] TER
542requireAuth(ReadView const& view, Issue const& issue, AccountID const& account);
543[[nodiscard]] TER
545 ReadView const& view,
546 MPTIssue const& mptIssue,
547 AccountID const& account);
548
553[[nodiscard]] TER
555 ReadView const& view,
556 MPTIssue const& mptIssue,
557 AccountID const& from,
558 AccountID const& to);
559
566 uint256 const&,
575[[nodiscard]] TER
577 ApplyView& view,
578 Keylet const& ownerDirKeylet,
579 EntryDeleter const& deleter,
581 std::optional<std::uint16_t> maxNodesToDelete = std::nullopt);
582
587[[nodiscard]] TER
589 ApplyView& view,
590 std::shared_ptr<SLE> sleState,
593
594} // namespace ripple
595
596#endif
Provide a light-weight way to check active() before string formatting.
Definition: Journal.h:205
A generic endpoint for log messages.
Definition: Journal.h:60
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:140
constexpr value_type const & value() const
Definition: Asset.h:143
A currency issued by an account.
Definition: Issue.h:36
AccountID account
Definition: Issue.h:39
Currency currency
Definition: Issue.h:38
A view into a ledger.
Definition: ReadView.h:51
const std::shared_ptr< STLedgerEntry > & ref
Definition: STLedgerEntry.h:38
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition: Indexes.cpp:365
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:49
std::uint32_t LedgerIndex
A ledger index.
Definition: Protocol.h:120
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
Definition: View.cpp:442
FreezeHandling
Controls the treatment of frozen account balances.
Definition: View.h:75
@ fhZERO_IF_FROZEN
Definition: View.h:75
@ fhIGNORE_FREEZE
Definition: View.h:75
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:136
LedgerIndex getCandidateLedger(LedgerIndex requested)
Find a ledger index from which we could easily get the requested ledger.
Definition: View.h:326
bool isIndividualFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
Definition: View.cpp:204
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
Definition: View.cpp:2049
bool dirFirst(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
Definition: View.cpp:114
base_uint< 256 > uint256
Definition: base_uint.h:558
bool dirNext(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
Definition: View.cpp:125
TER requireAuth(ReadView const &view, Issue const &issue, AccountID const &account)
Check if the account lacks required authorization.
Definition: View.cpp:1898
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
Definition: View.cpp:271
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
Definition: View.cpp:835
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
Definition: View.cpp:649
TER redeemIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
Definition: View.cpp:1782
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:64
AuthHandling
Controls the treatment of unauthorized MPT balances.
Definition: View.h:78
@ ahZERO_IF_UNAUTHORIZED
Definition: View.h:78
@ ahIGNORE_AUTH
Definition: View.h:78
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Definition: View.cpp:924
SkipEntry
Definition: View.h:42
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
Definition: View.cpp:1855
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
Definition: View.cpp:1091
bool isFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
Definition: View.cpp:238
std::set< uint256 > getEnabledAmendments(ReadView const &view)
Definition: View.cpp:795
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:1951
AccountID ammAccountID(std::uint16_t prefix, uint256 const &parentHash, uint256 const &ammID)
Calculate AMM account ID.
Definition: AMMCore.cpp:43
static bool adjustOwnerCount(ApplyContext &ctx, int count)
Definition: SetOracle.cpp:185
base_uint< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition: UintTypes.h:56
TER issueIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
Definition: View.cpp:1682
TER trustCreate(ApplyView &view, const bool bSrcHigh, AccountID const &uSrcAccountID, AccountID const &uDstAccountID, uint256 const &uIndex, SLE::ref sleAccount, const bool bAuth, const bool bNoRipple, const bool bFreeze, bool bDeepFreeze, STAmount const &saBalance, STAmount const &saLimit, std::uint32_t uQualityIn, std::uint32_t uQualityOut, beast::Journal j)
Create a trust line.
Definition: View.cpp:932
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:147
WaiveTransferFee
Definition: View.h:41
TER trustDelete(ApplyView &view, std::shared_ptr< SLE > const &sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
Definition: View.cpp:1051
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
Definition: View.cpp:308
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
Definition: View.cpp:297
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition: View.cpp:812
LedgerEntryType
Identifiers for on-ledger objects.
Definition: LedgerFormats.h:54
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:571
TER cleanupOnAccountDelete(ApplyView &view, Keylet const &ownerDirKeylet, EntryDeleter const &deleter, beast::Journal j, std::optional< uint16_t > maxNodesToDelete)
Definition: View.cpp:1971
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:543
Number root(Number f, unsigned d)
Definition: Number.cpp:635
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
Definition: View.cpp:164
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:2098
TERSubset< CanCvtToTER > TER
Definition: TER.h:627
bool areCompatible(ReadView const &validLedger, ReadView const &testLedger, beast::Journal::Stream &s, const char *reason)
Return false if the test ledger is provably incompatible with the valid ledger, that is,...
Definition: View.cpp:673
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition: Escrow.cpp:85
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
Definition: View.cpp:781
TER accountSend(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee)
Calls static accountSendIOU if saAmount represents Issue.
Definition: View.cpp:1608
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
Definition: View.cpp:506
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
Definition: View.cpp:173
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:39
T visit(T... args)