1#ifndef XRPL_LEDGER_VIEW_H_INCLUDED
2#define XRPL_LEDGER_VIEW_H_INCLUDED
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/Indexes.h>
9#include <xrpl/protocol/MPTIssue.h>
10#include <xrpl/protocol/Protocol.h>
11#include <xrpl/protocol/Rate.h>
12#include <xrpl/protocol/STLedgerEntry.h>
13#include <xrpl/protocol/STObject.h>
14#include <xrpl/protocol/Serializer.h>
15#include <xrpl/protocol/TER.h>
77 MPTIssue
const& mptShare,
87[[nodiscard]]
inline bool
100 MPTIssue
const& mptIssue);
102[[nodiscard]]
inline bool
109 [&](
auto const& issue) {
117 ReadView
const& view,
122[[nodiscard]]
inline bool
134 ReadView
const& view,
136 MPTIssue
const& mptIssue,
144[[nodiscard]]
inline bool
152 [&](
auto const& issue) {
153 return isFrozen(view, account, issue, depth);
158[[nodiscard]]
inline TER
164[[nodiscard]]
inline TER
173[[nodiscard]]
inline TER
177 [&](
auto const& issue) {
return checkFrozen(view, account, issue); },
183 ReadView
const& view,
185 MPTIssue
const& mptIssue,
188[[nodiscard]]
inline bool
194 for (
auto const& account : accounts)
202[[nodiscard]]
inline bool
221 ReadView
const& view,
228 ReadView
const& view,
231 Issue
const& asset2);
236[[nodiscard]] STAmount
238 ReadView
const& view,
245[[nodiscard]] STAmount
247 ReadView
const& view,
253[[nodiscard]] STAmount
255 ReadView
const& view,
257 MPTIssue
const& mptIssue,
262[[nodiscard]] STAmount
264 ReadView
const& view,
276[[nodiscard]] STAmount
278 ReadView
const& view,
280 STAmount
const& saDefault,
290[[nodiscard]] XRPAmount
292 ReadView
const& view,
300 ReadView
const& view,
312 ReadView
const& view,
368transferRate(ReadView
const& view, STAmount
const& amount);
374dirIsEmpty(ReadView
const& view, Keylet
const& k);
412 return (requested + 255) & (~255);
422 ReadView
const& validLedger,
423 ReadView
const& testLedger,
431 ReadView
const& testLedger,
466 ReadView
const& view,
498 ReadView
const& view,
530[[nodiscard]] Expected<std::shared_ptr<SLE>,
TER>
534 SField
const& ownerField);
556[[nodiscard]]
inline bool
571 XRPAmount priorBalance,
579 XRPAmount priorBalance,
580 MPTIssue
const& mptIssue,
583[[nodiscard]]
inline TER
594 view, accountID, priorBalance, issue, journal);
602 XRPAmount
const& priorBalance,
603 MPTID const& mptIssuanceID,
625 bool const bNoRipple,
628 STAmount
const& saBalance,
630 STAmount
const& saLimit,
647 MPTIssue
const& mptIssue,
650[[nodiscard]]
inline TER
702 STAmount
const& saAmount,
710 STAmount
const& saAmount,
718 STAmount
const& netAmount,
719 STAmount
const& grossAmount,
730 STAmount
const& saAmount,
738 STAmount
const& amount,
746 STAmount
const& amount,
755 STAmount
const& amount,
788 ReadView
const& view,
817 ReadView
const& view,
818 MPTIssue
const& mptIssue,
831 return requireAuth(view, issue_, account, authType);
862 MPTID const& mptIssuanceID,
864 XRPAmount
const& priorBalance,
873 ReadView
const& view,
874 MPTIssue
const& mptIssue,
896 Keylet const& ownerDirKeylet,
940 STAmount
const& assets,
950 STAmount
const& shares);
Provide a light-weight way to check active() before string formatting.
A generic endpoint for log messages.
Writeable view to a ledger, for applying a transaction.
constexpr value_type const & value() const
A currency issued by an account.
std::chrono::time_point< NetClock > time_point
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
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
std::uint32_t LedgerIndex
A ledger index.
TER checkFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
FreezeHandling
Controls the treatment of frozen account balances.
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,...
TER rippleLockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, STAmount const &saAmount, beast::Journal j)
LedgerIndex getCandidateLedger(LedgerIndex requested)
Find a ledger index from which we could easily get the requested ledger.
std::optional< STAmount > sharesToAssetsDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
bool isIndividualFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
bool dirFirst(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
bool dirNext(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
TER redeemIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
base_uint< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
std::optional< STAmount > assetsToSharesDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets)
AuthHandling
Controls the treatment of unauthorized MPT balances.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
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)
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
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.
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
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.
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
std::set< uint256 > getEnabledAmendments(ReadView const &view)
TER rippleUnlockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, AccountID const &uGranteeID, STAmount const &netAmount, STAmount const &grossAmount, beast::Journal j)
TER requireAuth(ReadView const &view, Issue const &issue, AccountID const &account, AuthType authType=AuthType::Legacy)
Check if the account lacks required authorization.
std::optional< STAmount > sharesToAssetsWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
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.
base_uint< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
TER canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to)
Check if the destination account is allowed to receive MPT.
Expected< std::shared_ptr< SLE >, TER > createPseudoAccount(ApplyView &view, uint256 const &pseudoOwnerKey, SField const &ownerField)
Create pseudo-account, storing pseudoOwnerKey into ownerField.
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
bool isVaultPseudoAccountFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptShare, int depth)
TER issueIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
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.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
TER trustDelete(ApplyView &view, std::shared_ptr< SLE > const &sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
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.
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...
AccountID pseudoAccountAddress(ReadView const &view, uint256 const &pseudoOwnerKey)
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
majorityAmendments_t getMajorityAmendments(ReadView const &view)
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.
LedgerEntryType
Identifiers for on-ledger objects.
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
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.
Number root(Number f, unsigned d)
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
TER enforceMPTokenAuthorization(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, XRPAmount const &priorBalance, beast::Journal j)
Enforce account has MPToken to match its authorization.
TER canAddHolding(ReadView const &view, Asset const &asset)
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.
bool isAnyFrozen(ReadView const &view, std::initializer_list< AccountID > const &accounts, MPTIssue const &mptIssue, int depth=0)
std::vector< SField const * > const & getPseudoAccountFields()
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)
TERSubset< CanCvtToTER > TER
TER removeEmptyHolding(ApplyView &view, AccountID const &accountID, Issue const &issue, beast::Journal journal)
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct)
TER dirLink(ApplyView &view, AccountID const &owner, std::shared_ptr< SLE > &object)
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
A pair of SHAMap key and LedgerEntryType.