rippled
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 <ripple/beast/utility/Journal.h>
24 #include <ripple/core/Config.h>
25 #include <ripple/ledger/ApplyView.h>
26 #include <ripple/ledger/OpenView.h>
27 #include <ripple/ledger/RawView.h>
28 #include <ripple/ledger/ReadView.h>
29 #include <ripple/protocol/Protocol.h>
30 #include <ripple/protocol/Rate.h>
31 #include <ripple/protocol/STLedgerEntry.h>
32 #include <ripple/protocol/STObject.h>
33 #include <ripple/protocol/STTx.h>
34 #include <ripple/protocol/Serializer.h>
35 #include <ripple/protocol/TER.h>
36 #include <functional>
37 #include <map>
38 #include <memory>
39 #include <utility>
40 
41 #include <vector>
42 
43 namespace ripple {
44 
45 //------------------------------------------------------------------------------
46 //
47 // Observers
48 //
49 //------------------------------------------------------------------------------
50 
53 
54 [[nodiscard]] bool
55 isGlobalFrozen(ReadView const& view, AccountID const& issuer);
56 
57 [[nodiscard]] bool
58 isFrozen(
59  ReadView const& view,
60  AccountID const& account,
61  Currency const& currency,
62  AccountID const& issuer);
63 
64 // Returns the amount an account can spend without going into debt.
65 //
66 // <-- saAmount: amount of currency held by account. May be negative.
67 [[nodiscard]] STAmount
69  ReadView const& view,
70  AccountID const& account,
71  Currency const& currency,
72  AccountID const& issuer,
73  FreezeHandling zeroIfFrozen,
74  beast::Journal j);
75 
76 [[nodiscard]] STAmount
78  ReadView const& view,
79  AccountID const& id,
80  STAmount const& saDefault,
81  FreezeHandling freezeHandling,
82  beast::Journal j);
83 
84 // Return the account's liquid (not reserved) XRP. Generally prefer
85 // calling accountHolds() over this interface. However this interface
86 // allows the caller to temporarily adjust the owner count should that be
87 // necessary.
88 //
89 // @param ownerCountAdj positive to add to count, negative to reduce count.
90 [[nodiscard]] XRPAmount
91 xrpLiquid(
92  ReadView const& view,
93  AccountID const& id,
94  std::int32_t ownerCountAdj,
95  beast::Journal j);
96 
98 void
100  ReadView const& view,
101  AccountID const& id,
102  std::function<void(std::shared_ptr<SLE const> const&)> f);
103 
110 bool
112  ReadView const& view,
113  AccountID const& id,
114  uint256 const& after,
115  std::uint64_t const hint,
116  unsigned int limit,
117  std::function<bool(std::shared_ptr<SLE const> const&)> f);
118 
119 [[nodiscard]] Rate
120 transferRate(ReadView const& view, AccountID const& issuer);
121 
125 [[nodiscard]] bool
126 dirIsEmpty(ReadView const& view, Keylet const& k);
127 
128 // Return the list of enabled amendments
129 [[nodiscard]] std::set<uint256>
130 getEnabledAmendments(ReadView const& view);
131 
132 // Return a map of amendments that have achieved majority
134 [[nodiscard]] majorityAmendments_t
135 getMajorityAmendments(ReadView const& view);
136 
146 [[nodiscard]] std::optional<uint256>
147 hashOfSeq(ReadView const& ledger, LedgerIndex seq, beast::Journal journal);
148 
161 inline LedgerIndex
163 {
164  return (requested + 255) & (~255);
165 }
166 
172 [[nodiscard]] bool
174  ReadView const& validLedger,
175  ReadView const& testLedger,
177  const char* reason);
178 
179 [[nodiscard]] bool
181  uint256 const& validHash,
182  LedgerIndex validIndex,
183  ReadView const& testLedger,
185  const char* reason);
186 
187 //------------------------------------------------------------------------------
188 //
189 // Modifiers
190 //
191 //------------------------------------------------------------------------------
192 
194 void
196  ApplyView& view,
197  std::shared_ptr<SLE> const& sle,
198  std::int32_t amount,
199  beast::Journal j);
200 
216 bool
217 cdirFirst(
218  ReadView const& view,
219  uint256 const& root,
221  unsigned int& index,
222  uint256& entry);
223 
224 bool
225 dirFirst(
226  ApplyView& view,
227  uint256 const& root,
228  std::shared_ptr<SLE>& page,
229  unsigned int& index,
230  uint256& entry);
248 bool
249 cdirNext(
250  ReadView const& view,
251  uint256 const& root,
253  unsigned int& index,
254  uint256& entry);
255 
256 bool
257 dirNext(
258  ApplyView& view,
259  uint256 const& root,
260  std::shared_ptr<SLE>& page,
261  unsigned int& index,
262  uint256& entry);
265 [[nodiscard]] std::function<void(SLE::ref)>
266 describeOwnerDir(AccountID const& account);
267 
268 // VFALCO NOTE Both STAmount parameters should just
269 // be "Amount", a unit-less number.
270 //
275 [[nodiscard]] TER
277  ApplyView& view,
278  const bool bSrcHigh,
279  AccountID const& uSrcAccountID,
280  AccountID const& uDstAccountID,
281  uint256 const& uIndex, // --> ripple state entry
282  SLE::ref sleAccount, // --> the account being set.
283  const bool bAuth, // --> authorize account.
284  const bool bNoRipple, // --> others cannot ripple through
285  const bool bFreeze, // --> funds cannot leave
286  STAmount const& saBalance, // --> balance of account being set.
287  // Issuer should be noAccount()
288  STAmount const& saLimit, // --> limit for account being set.
289  // Issuer should be the account being set.
290  std::uint32_t uSrcQualityIn,
291  std::uint32_t uSrcQualityOut,
292  beast::Journal j);
293 
294 [[nodiscard]] TER
296  ApplyView& view,
297  std::shared_ptr<SLE> const& sleRippleState,
298  AccountID const& uLowAccountID,
299  AccountID const& uHighAccountID,
300  beast::Journal j);
301 
308 // [[nodiscard]] // nodiscard commented out so Flow, BookTip and others compile.
309 TER
310 offerDelete(ApplyView& view, std::shared_ptr<SLE> const& sle, beast::Journal j);
311 
312 //------------------------------------------------------------------------------
313 
314 //
315 // Money Transfers
316 //
317 
318 // Direct send w/o fees:
319 // - Redeeming IOUs and/or sending sender's own IOUs.
320 // - Create trust line of needed.
321 // --> bCheckIssuer : normally require issuer to be involved.
322 // [[nodiscard]] // nodiscard commented out so DirectStep.cpp compiles.
323 TER
325  ApplyView& view,
326  AccountID const& uSenderID,
327  AccountID const& uReceiverID,
328  const STAmount& saAmount,
329  bool bCheckIssuer,
330  beast::Journal j);
331 
332 [[nodiscard]] TER
334  ApplyView& view,
335  AccountID const& from,
336  AccountID const& to,
337  const STAmount& saAmount,
338  beast::Journal j);
339 
340 [[nodiscard]] TER
341 issueIOU(
342  ApplyView& view,
343  AccountID const& account,
344  STAmount const& amount,
345  Issue const& issue,
346  beast::Journal j);
347 
348 [[nodiscard]] TER
349 redeemIOU(
350  ApplyView& view,
351  AccountID const& account,
352  STAmount const& amount,
353  Issue const& issue,
354  beast::Journal j);
355 
356 [[nodiscard]] TER
358  ApplyView& view,
359  AccountID const& from,
360  AccountID const& to,
361  STAmount const& amount,
362  beast::Journal j);
363 
364 } // namespace ripple
365 
366 #endif
ripple::rippleCredit
TER rippleCredit(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
Definition: View.cpp:933
ripple::transferRate
Rate transferRate(ReadView const &view, AccountID const &issuer)
Definition: View.cpp:471
ripple::cdirNext
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
ripple::dirNext
bool dirNext(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
Definition: View.cpp:125
ripple::getMajorityAmendments
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition: View.cpp:621
ripple::LedgerIndex
std::uint32_t LedgerIndex
A ledger index.
Definition: Protocol.h:57
ripple::getEnabledAmendments
std::set< uint256 > getEnabledAmendments(ReadView const &view)
Definition: View.cpp:604
std::shared_ptr
STL class.
ripple::fhZERO_IF_FROZEN
@ fhZERO_IF_FROZEN
Definition: View.h:52
utility
ripple::describeOwnerDir
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Definition: View.cpp:731
functional
vector
ripple::accountHolds
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
Definition: View.cpp:216
std::function
ripple::FreezeHandling
FreezeHandling
Controls the treatment of frozen account balances.
Definition: View.h:52
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:529
ripple::forEachItem
void forEachItem(ReadView const &view, AccountID const &id, std::function< void(std::shared_ptr< SLE const > const &)> f)
Iterate all items in an account's owner directory.
Definition: View.cpp:375
ripple::isGlobalFrozen
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
Definition: View.cpp:181
ripple::adjustOwnerCount
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:713
ripple::offerDelete
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
Definition: View.cpp:893
ripple::TER
TERSubset< CanCvtToTER > TER
Definition: TER.h:555
ripple::accountSend
TER accountSend(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j)
Definition: View.cpp:1122
beast::Journal::Stream
Provide a light-weight way to check active() before string formatting.
Definition: Journal.h:194
ripple::xrpLiquid
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
Definition: View.cpp:339
ripple::hashOfSeq
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
Definition: View.cpp:644
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::int32_t
map
ripple::trustDelete
TER trustDelete(ApplyView &view, std::shared_ptr< SLE > const &sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
Definition: View.cpp:853
memory
ripple::areCompatible
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:482
ripple::accountFunds
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
Definition: View.cpp:260
ripple::transferXRP
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
Definition: View.cpp:1447
ripple::issueIOU
TER issueIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
Definition: View.cpp:1281
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:192
ripple::dirIsEmpty
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
Definition: View.cpp:590
ripple::Currency
base_uint< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition: UintTypes.h:56
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::dirFirst
bool dirFirst(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
Definition: View.cpp:114
ripple::trustCreate
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, STAmount const &saBalance, STAmount const &saLimit, std::uint32_t uQualityIn, std::uint32_t uQualityOut, beast::Journal j)
Create a trust line.
Definition: View.cpp:739
ripple::redeemIOU
TER redeemIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
Definition: View.cpp:1377
ripple::fhIGNORE_FREEZE
@ fhIGNORE_FREEZE
Definition: View.h:52
ripple::forEachItemAfter
bool forEachItemAfter(ReadView const &view, AccountID const &id, uint256 const &after, std::uint64_t const hint, unsigned int limit, std::function< bool(std::shared_ptr< SLE const > const &)> f)
Iterate all items after an item in an owner directory.
Definition: View.cpp:398
std::optional
ripple::after
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition: Escrow.cpp:88
ripple::getCandidateLedger
LedgerIndex getCandidateLedger(LedgerIndex requested)
Find a ledger index from which we could easily get the requested ledger.
Definition: View.h:162
ripple::cdirFirst
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
ripple::STLedgerEntry::ref
const std::shared_ptr< STLedgerEntry > & ref
Definition: STLedgerEntry.h:36
std::set
STL class.
ripple::isFrozen
bool isFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
Definition: View.cpp:193
ripple::AccountID
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:47