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/core/Config.h>
24#include <xrpld/ledger/ApplyView.h>
25#include <xrpld/ledger/OpenView.h>
26#include <xrpld/ledger/RawView.h>
27#include <xrpld/ledger/ReadView.h>
28#include <xrpl/beast/utility/Journal.h>
29#include <xrpl/protocol/MPTIssue.h>
30#include <xrpl/protocol/Protocol.h>
31#include <xrpl/protocol/Rate.h>
32#include <xrpl/protocol/STLedgerEntry.h>
33#include <xrpl/protocol/STObject.h>
34#include <xrpl/protocol/STTx.h>
35#include <xrpl/protocol/Serializer.h>
36#include <xrpl/protocol/TER.h>
37#include <functional>
38#include <map>
39#include <memory>
40#include <utility>
41
42#include <vector>
43
44namespace ripple {
45
46enum class WaiveTransferFee : bool { No = false, Yes };
47enum class SkipEntry : bool { No = false, Yes };
48
49//------------------------------------------------------------------------------
50//
51// Observers
52//
53//------------------------------------------------------------------------------
54
76[[nodiscard]] bool
77hasExpired(ReadView const& view, std::optional<std::uint32_t> const& exp);
78
81
84
85[[nodiscard]] bool
86isGlobalFrozen(ReadView const& view, AccountID const& issuer);
87
88[[nodiscard]] bool
89isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue);
90
91[[nodiscard]] bool
92isGlobalFrozen(ReadView const& view, Asset const& asset);
93
94[[nodiscard]] bool
96 ReadView const& view,
97 AccountID const& account,
98 Currency const& currency,
99 AccountID const& issuer);
100
101[[nodiscard]] inline bool
103 ReadView const& view,
104 AccountID const& account,
105 Issue const& issue)
106{
107 return isIndividualFrozen(view, account, issue.currency, issue.account);
108}
109
110[[nodiscard]] bool
112 ReadView const& view,
113 AccountID const& account,
114 MPTIssue const& mptIssue);
115
116[[nodiscard]] inline bool
118 ReadView const& view,
119 AccountID const& account,
120 Asset const& asset)
121{
122 return std::visit(
123 [&](auto const& issue) {
124 return isIndividualFrozen(view, account, issue);
125 },
126 asset.value());
127}
128
129[[nodiscard]] bool
131 ReadView const& view,
132 AccountID const& account,
133 Currency const& currency,
134 AccountID const& issuer);
135
136[[nodiscard]] inline bool
137isFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
138{
139 return isFrozen(view, account, issue.currency, issue.account);
140}
141
142[[nodiscard]] bool
144 ReadView const& view,
145 AccountID const& account,
146 MPTIssue const& mptIssue);
147
148[[nodiscard]] inline bool
149isFrozen(ReadView const& view, AccountID const& account, Asset const& asset)
150{
151 return std::visit(
152 [&](auto const& issue) { return isFrozen(view, account, issue); },
153 asset.value());
154}
155
156[[nodiscard]] bool
158 ReadView const& view,
159 AccountID const& account,
160 Currency const& currency,
161 AccountID const& issuer);
162
163[[nodiscard]] bool
165 ReadView const& view,
166 AccountID const& account,
167 Issue const& asset,
168 Issue const& asset2);
169
170// Returns the amount an account can spend without going into debt.
171//
172// <-- saAmount: amount of currency held by account. May be negative.
173[[nodiscard]] STAmount
175 ReadView const& view,
176 AccountID const& account,
177 Currency const& currency,
178 AccountID const& issuer,
179 FreezeHandling zeroIfFrozen,
181
182[[nodiscard]] STAmount
184 ReadView const& view,
185 AccountID const& account,
186 Issue const& issue,
187 FreezeHandling zeroIfFrozen,
189
190[[nodiscard]] STAmount
192 ReadView const& view,
193 AccountID const& account,
194 MPTIssue const& mptIssue,
195 FreezeHandling zeroIfFrozen,
196 AuthHandling zeroIfUnauthorized,
198
199// Returns the amount an account can spend of the currency type saDefault, or
200// returns saDefault if this account is the issuer of the currency in
201// question. Should be used in favor of accountHolds when questioning how much
202// an account can spend while also allowing currency issuers to spend
203// unlimited amounts of their own currency (since they can always issue more).
204[[nodiscard]] STAmount
206 ReadView const& view,
207 AccountID const& id,
208 STAmount const& saDefault,
209 FreezeHandling freezeHandling,
211
212// Return the account's liquid (not reserved) XRP. Generally prefer
213// calling accountHolds() over this interface. However, this interface
214// allows the caller to temporarily adjust the owner count should that be
215// necessary.
216//
217// @param ownerCountAdj positive to add to count, negative to reduce count.
218[[nodiscard]] XRPAmount
220 ReadView const& view,
221 AccountID const& id,
222 std::int32_t ownerCountAdj,
224
226void
228 ReadView const& view,
229 Keylet const& root,
230 std::function<void(std::shared_ptr<SLE const> const&)> const& f);
231
238bool
240 ReadView const& view,
241 Keylet const& root,
242 uint256 const& after,
243 std::uint64_t const hint,
244 unsigned int limit,
245 std::function<bool(std::shared_ptr<SLE const> const&)> const& f);
246
248inline void
250 ReadView const& view,
251 AccountID const& id,
252 std::function<void(std::shared_ptr<SLE const> const&)> const& f)
253{
254 return forEachItem(view, keylet::ownerDir(id), f);
255}
256
263inline bool
265 ReadView const& view,
266 AccountID const& id,
267 uint256 const& after,
268 std::uint64_t const hint,
269 unsigned int limit,
270 std::function<bool(std::shared_ptr<SLE const> const&)> const& f)
271{
272 return forEachItemAfter(view, keylet::ownerDir(id), after, hint, limit, f);
273}
274
280[[nodiscard]] Rate
281transferRate(ReadView const& view, AccountID const& issuer);
282
288[[nodiscard]] Rate
289transferRate(ReadView const& view, MPTID const& issuanceID);
290
294[[nodiscard]] bool
295dirIsEmpty(ReadView const& view, Keylet const& k);
296
297// Return the list of enabled amendments
298[[nodiscard]] std::set<uint256>
299getEnabledAmendments(ReadView const& view);
300
301// Return a map of amendments that have achieved majority
303[[nodiscard]] majorityAmendments_t
305
315[[nodiscard]] std::optional<uint256>
316hashOfSeq(ReadView const& ledger, LedgerIndex seq, beast::Journal journal);
317
330inline LedgerIndex
332{
333 return (requested + 255) & (~255);
334}
335
341[[nodiscard]] bool
343 ReadView const& validLedger,
344 ReadView const& testLedger,
346 const char* reason);
347
348[[nodiscard]] bool
350 uint256 const& validHash,
351 LedgerIndex validIndex,
352 ReadView const& testLedger,
354 const char* reason);
355
356//------------------------------------------------------------------------------
357//
358// Modifiers
359//
360//------------------------------------------------------------------------------
361
363void
365 ApplyView& view,
366 std::shared_ptr<SLE> const& sle,
367 std::int32_t amount,
369
385bool
387 ReadView const& view,
388 uint256 const& root,
390 unsigned int& index,
391 uint256& entry);
392
393bool
395 ApplyView& view,
396 uint256 const& root,
398 unsigned int& index,
399 uint256& entry);
417bool
419 ReadView const& view,
420 uint256 const& root,
422 unsigned int& index,
423 uint256& entry);
424
425bool
426dirNext(
427 ApplyView& view,
428 uint256 const& root,
430 unsigned int& index,
431 uint256& entry);
434[[nodiscard]] std::function<void(SLE::ref)>
435describeOwnerDir(AccountID const& account);
436
437// VFALCO NOTE Both STAmount parameters should just
438// be "Amount", a unit-less number.
439//
444[[nodiscard]] TER
446 ApplyView& view,
447 const bool bSrcHigh,
448 AccountID const& uSrcAccountID,
449 AccountID const& uDstAccountID,
450 uint256 const& uIndex, // --> ripple state entry
451 SLE::ref sleAccount, // --> the account being set.
452 const bool bAuth, // --> authorize account.
453 const bool bNoRipple, // --> others cannot ripple through
454 const bool bFreeze, // --> funds cannot leave
455 bool bDeepFreeze, // --> can neither receive nor send funds
456 STAmount const& saBalance, // --> balance of account being set.
457 // Issuer should be noAccount()
458 STAmount const& saLimit, // --> limit for account being set.
459 // Issuer should be the account being set.
460 std::uint32_t uSrcQualityIn,
461 std::uint32_t uSrcQualityOut,
463
464[[nodiscard]] TER
466 ApplyView& view,
467 std::shared_ptr<SLE> const& sleRippleState,
468 AccountID const& uLowAccountID,
469 AccountID const& uHighAccountID,
471
478// [[nodiscard]] // nodiscard commented out so Flow, BookTip and others compile.
479TER
480offerDelete(ApplyView& view, std::shared_ptr<SLE> const& sle, beast::Journal j);
481
482//------------------------------------------------------------------------------
483
484//
485// Money Transfers
486//
487
488// Direct send w/o fees:
489// - Redeeming IOUs and/or sending sender's own IOUs.
490// - Create trust line of needed.
491// --> bCheckIssuer : normally require issuer to be involved.
492// [[nodiscard]] // nodiscard commented out so DirectStep.cpp compiles.
493
497TER
499 ApplyView& view,
500 AccountID const& uSenderID,
501 AccountID const& uReceiverID,
502 STAmount const& saAmount,
503 bool bCheckIssuer,
505
509[[nodiscard]] TER
511 ApplyView& view,
512 AccountID const& from,
513 AccountID const& to,
514 STAmount const& saAmount,
517
518[[nodiscard]] TER
520 ApplyView& view,
521 AccountID const& account,
522 STAmount const& amount,
523 Issue const& issue,
525
526[[nodiscard]] TER
528 ApplyView& view,
529 AccountID const& account,
530 STAmount const& amount,
531 Issue const& issue,
533
534[[nodiscard]] TER
536 ApplyView& view,
537 AccountID const& from,
538 AccountID const& to,
539 STAmount const& amount,
541
546[[nodiscard]] TER
547requireAuth(ReadView const& view, Issue const& issue, AccountID const& account);
548[[nodiscard]] TER
550 ReadView const& view,
551 MPTIssue const& mptIssue,
552 AccountID const& account);
553
558[[nodiscard]] TER
560 ReadView const& view,
561 MPTIssue const& mptIssue,
562 AccountID const& from,
563 AccountID const& to);
564
571 uint256 const&,
580[[nodiscard]] TER
582 ApplyView& view,
583 Keylet const& ownerDirKeylet,
584 EntryDeleter const& deleter,
586 std::optional<std::uint16_t> maxNodesToDelete = std::nullopt);
587
592[[nodiscard]] TER
594 ApplyView& view,
595 std::shared_ptr<SLE> sleState,
598
599} // namespace ripple
600
601#endif
Provide a light-weight way to check active() before string formatting.
Definition: Journal.h:194
A generic endpoint for log messages.
Definition: Journal.h:59
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:55
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:350
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:119
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:80
@ fhZERO_IF_FROZEN
Definition: View.h:80
@ fhIGNORE_FREEZE
Definition: View.h:80
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:331
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:2050
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:557
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:1899
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:836
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
Definition: View.cpp:650
TER redeemIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
Definition: View.cpp:1783
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:83
@ ahZERO_IF_UNAUTHORIZED
Definition: View.h:83
@ ahIGNORE_AUTH
Definition: View.h:83
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Definition: View.cpp:925
SkipEntry
Definition: View.h:47
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
Definition: View.cpp:1856
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
Definition: View.cpp:1092
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:796
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:1952
AccountID ammAccountID(std::uint16_t prefix, uint256 const &parentHash, uint256 const &ammID)
Calculate AMM account ID.
Definition: AMMCore.cpp:30
static bool adjustOwnerCount(ApplyContext &ctx, int count)
Definition: SetOracle.cpp:186
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:1683
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:933
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:46
TER trustDelete(ApplyView &view, std::shared_ptr< SLE > const &sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
Definition: View.cpp:1052
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:813
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:572
TER cleanupOnAccountDelete(ApplyView &view, Keylet const &ownerDirKeylet, EntryDeleter const &deleter, beast::Journal j, std::optional< uint16_t > maxNodesToDelete)
Definition: View.cpp:1972
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:544
Number root(Number f, unsigned d)
Definition: Number.cpp:630
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:2099
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:674
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition: Escrow.cpp:89
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
Definition: View.cpp:782
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:1609
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)