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
27#include <xrpl/beast/utility/Journal.h>
28#include <xrpl/protocol/MPTIssue.h>
29#include <xrpl/protocol/Protocol.h>
30#include <xrpl/protocol/Rate.h>
31#include <xrpl/protocol/STLedgerEntry.h>
32#include <xrpl/protocol/STObject.h>
33#include <xrpl/protocol/Serializer.h>
34#include <xrpl/protocol/TER.h>
35
36#include <functional>
37#include <map>
38#include <utility>
39
40namespace ripple {
41
42enum class WaiveTransferFee : bool { No = false, Yes };
43enum class SkipEntry : bool { No = false, Yes };
44
45//------------------------------------------------------------------------------
46//
47// Observers
48//
49//------------------------------------------------------------------------------
50
72[[nodiscard]] bool
73hasExpired(ReadView const& view, std::optional<std::uint32_t> const& exp);
74
77
80
81[[nodiscard]] bool
82isGlobalFrozen(ReadView const& view, AccountID const& issuer);
83
84[[nodiscard]] bool
85isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue);
86
87[[nodiscard]] bool
88isGlobalFrozen(ReadView const& view, Asset const& asset);
89
90[[nodiscard]] bool
92 ReadView const& view,
93 AccountID const& account,
94 Currency const& currency,
95 AccountID const& issuer);
96
97[[nodiscard]] inline bool
99 ReadView const& view,
100 AccountID const& account,
101 Issue const& issue)
102{
103 return isIndividualFrozen(view, account, issue.currency, issue.account);
104}
105
106[[nodiscard]] bool
108 ReadView const& view,
109 AccountID const& account,
110 MPTIssue const& mptIssue);
111
112[[nodiscard]] inline bool
114 ReadView const& view,
115 AccountID const& account,
116 Asset const& asset)
117{
118 return std::visit(
119 [&](auto const& issue) {
120 return isIndividualFrozen(view, account, issue);
121 },
122 asset.value());
123}
124
125[[nodiscard]] bool
127 ReadView const& view,
128 AccountID const& account,
129 Currency const& currency,
130 AccountID const& issuer);
131
132[[nodiscard]] inline bool
133isFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
134{
135 return isFrozen(view, account, issue.currency, issue.account);
136}
137
138[[nodiscard]] bool
140 ReadView const& view,
141 AccountID const& account,
142 MPTIssue const& mptIssue);
143
144[[nodiscard]] inline bool
145isFrozen(ReadView const& view, AccountID const& account, Asset const& asset)
146{
147 return std::visit(
148 [&](auto const& issue) { return isFrozen(view, account, issue); },
149 asset.value());
150}
151
152[[nodiscard]] bool
154 ReadView const& view,
155 AccountID const& account,
156 Currency const& currency,
157 AccountID const& issuer);
158
159[[nodiscard]] bool
161 ReadView const& view,
162 AccountID const& account,
163 Issue const& asset,
164 Issue const& asset2);
165
166// Returns the amount an account can spend without going into debt.
167//
168// <-- saAmount: amount of currency held by account. May be negative.
169[[nodiscard]] STAmount
171 ReadView const& view,
172 AccountID const& account,
173 Currency const& currency,
174 AccountID const& issuer,
175 FreezeHandling zeroIfFrozen,
177
178[[nodiscard]] STAmount
180 ReadView const& view,
181 AccountID const& account,
182 Issue const& issue,
183 FreezeHandling zeroIfFrozen,
185
186[[nodiscard]] STAmount
188 ReadView const& view,
189 AccountID const& account,
190 MPTIssue const& mptIssue,
191 FreezeHandling zeroIfFrozen,
192 AuthHandling zeroIfUnauthorized,
194
195// Returns the amount an account can spend of the currency type saDefault, or
196// returns saDefault if this account is the issuer of the currency in
197// question. Should be used in favor of accountHolds when questioning how much
198// an account can spend while also allowing currency issuers to spend
199// unlimited amounts of their own currency (since they can always issue more).
200[[nodiscard]] STAmount
202 ReadView const& view,
203 AccountID const& id,
204 STAmount const& saDefault,
205 FreezeHandling freezeHandling,
207
208// Return the account's liquid (not reserved) XRP. Generally prefer
209// calling accountHolds() over this interface. However, this interface
210// allows the caller to temporarily adjust the owner count should that be
211// necessary.
212//
213// @param ownerCountAdj positive to add to count, negative to reduce count.
214[[nodiscard]] XRPAmount
216 ReadView const& view,
217 AccountID const& id,
218 std::int32_t ownerCountAdj,
220
222void
224 ReadView const& view,
225 Keylet const& root,
226 std::function<void(std::shared_ptr<SLE const> const&)> const& f);
227
234bool
236 ReadView const& view,
237 Keylet const& root,
238 uint256 const& after,
239 std::uint64_t const hint,
240 unsigned int limit,
241 std::function<bool(std::shared_ptr<SLE const> const&)> const& f);
242
244inline void
246 ReadView const& view,
247 AccountID const& id,
248 std::function<void(std::shared_ptr<SLE const> const&)> const& f)
249{
250 return forEachItem(view, keylet::ownerDir(id), f);
251}
252
259inline bool
261 ReadView const& view,
262 AccountID const& id,
263 uint256 const& after,
264 std::uint64_t const hint,
265 unsigned int limit,
266 std::function<bool(std::shared_ptr<SLE const> const&)> const& f)
267{
268 return forEachItemAfter(view, keylet::ownerDir(id), after, hint, limit, f);
269}
270
276[[nodiscard]] Rate
277transferRate(ReadView const& view, AccountID const& issuer);
278
284[[nodiscard]] Rate
285transferRate(ReadView const& view, MPTID const& issuanceID);
286
290[[nodiscard]] bool
291dirIsEmpty(ReadView const& view, Keylet const& k);
292
293// Return the list of enabled amendments
294[[nodiscard]] std::set<uint256>
295getEnabledAmendments(ReadView const& view);
296
297// Return a map of amendments that have achieved majority
299[[nodiscard]] majorityAmendments_t
301
311[[nodiscard]] std::optional<uint256>
312hashOfSeq(ReadView const& ledger, LedgerIndex seq, beast::Journal journal);
313
326inline LedgerIndex
328{
329 return (requested + 255) & (~255);
330}
331
337[[nodiscard]] bool
339 ReadView const& validLedger,
340 ReadView const& testLedger,
342 const char* reason);
343
344[[nodiscard]] bool
346 uint256 const& validHash,
347 LedgerIndex validIndex,
348 ReadView const& testLedger,
350 const char* reason);
351
352//------------------------------------------------------------------------------
353//
354// Modifiers
355//
356//------------------------------------------------------------------------------
357
359void
361 ApplyView& view,
362 std::shared_ptr<SLE> const& sle,
363 std::int32_t amount,
365
381bool
383 ReadView const& view,
384 uint256 const& root,
386 unsigned int& index,
387 uint256& entry);
388
389bool
391 ApplyView& view,
392 uint256 const& root,
394 unsigned int& index,
395 uint256& entry);
413bool
415 ReadView const& view,
416 uint256 const& root,
418 unsigned int& index,
419 uint256& entry);
420
421bool
422dirNext(
423 ApplyView& view,
424 uint256 const& root,
426 unsigned int& index,
427 uint256& entry);
430[[nodiscard]] std::function<void(SLE::ref)>
431describeOwnerDir(AccountID const& account);
432
433// VFALCO NOTE Both STAmount parameters should just
434// be "Amount", a unit-less number.
435//
440[[nodiscard]] TER
442 ApplyView& view,
443 const bool bSrcHigh,
444 AccountID const& uSrcAccountID,
445 AccountID const& uDstAccountID,
446 uint256 const& uIndex, // --> ripple state entry
447 SLE::ref sleAccount, // --> the account being set.
448 const bool bAuth, // --> authorize account.
449 const bool bNoRipple, // --> others cannot ripple through
450 const bool bFreeze, // --> funds cannot leave
451 bool bDeepFreeze, // --> can neither receive nor send funds
452 STAmount const& saBalance, // --> balance of account being set.
453 // Issuer should be noAccount()
454 STAmount const& saLimit, // --> limit for account being set.
455 // Issuer should be the account being set.
456 std::uint32_t uSrcQualityIn,
457 std::uint32_t uSrcQualityOut,
459
460[[nodiscard]] TER
462 ApplyView& view,
463 std::shared_ptr<SLE> const& sleRippleState,
464 AccountID const& uLowAccountID,
465 AccountID const& uHighAccountID,
467
474// [[nodiscard]] // nodiscard commented out so Flow, BookTip and others compile.
475TER
476offerDelete(ApplyView& view, std::shared_ptr<SLE> const& sle, beast::Journal j);
477
478//------------------------------------------------------------------------------
479
480//
481// Money Transfers
482//
483
484// Direct send w/o fees:
485// - Redeeming IOUs and/or sending sender's own IOUs.
486// - Create trust line of needed.
487// --> bCheckIssuer : normally require issuer to be involved.
488// [[nodiscard]] // nodiscard commented out so DirectStep.cpp compiles.
489
493TER
495 ApplyView& view,
496 AccountID const& uSenderID,
497 AccountID const& uReceiverID,
498 STAmount const& saAmount,
499 bool bCheckIssuer,
501
505[[nodiscard]] TER
507 ApplyView& view,
508 AccountID const& from,
509 AccountID const& to,
510 STAmount const& saAmount,
513
514[[nodiscard]] TER
516 ApplyView& view,
517 AccountID const& account,
518 STAmount const& amount,
519 Issue const& issue,
521
522[[nodiscard]] TER
524 ApplyView& view,
525 AccountID const& account,
526 STAmount const& amount,
527 Issue const& issue,
529
530[[nodiscard]] TER
532 ApplyView& view,
533 AccountID const& from,
534 AccountID const& to,
535 STAmount const& amount,
537
542[[nodiscard]] TER
543requireAuth(ReadView const& view, Issue const& issue, AccountID const& account);
544[[nodiscard]] TER
546 ReadView const& view,
547 MPTIssue const& mptIssue,
548 AccountID const& account);
549
554[[nodiscard]] TER
556 ReadView const& view,
557 MPTIssue const& mptIssue,
558 AccountID const& from,
559 AccountID const& to);
560
567 uint256 const&,
576[[nodiscard]] TER
578 ApplyView& view,
579 Keylet const& ownerDirKeylet,
580 EntryDeleter const& deleter,
582 std::optional<std::uint16_t> maxNodesToDelete = std::nullopt);
583
588[[nodiscard]] TER
590 ApplyView& view,
591 std::shared_ptr<SLE> sleState,
594
595} // namespace ripple
596
597#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:141
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:52
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:443
FreezeHandling
Controls the treatment of frozen account balances.
Definition: View.h:76
@ fhZERO_IF_FROZEN
Definition: View.h:76
@ fhIGNORE_FREEZE
Definition: View.h:76
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:137
LedgerIndex getCandidateLedger(LedgerIndex requested)
Find a ledger index from which we could easily get the requested ledger.
Definition: View.h:327
bool isIndividualFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
Definition: View.cpp:205
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:115
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:126
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:272
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:79
@ ahZERO_IF_UNAUTHORIZED
Definition: View.h:79
@ ahIGNORE_AUTH
Definition: View.h:79
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Definition: View.cpp:925
SkipEntry
Definition: View.h:43
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:239
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:43
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:148
WaiveTransferFee
Definition: View.h:42
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:309
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
Definition: View.cpp:298
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:635
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
Definition: View.cpp:165
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:86
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:507
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
Definition: View.cpp:174
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:39
T visit(T... args)