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/Asset.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/MPTIssue.h>
11#include <xrpl/protocol/Protocol.h>
12#include <xrpl/protocol/Rate.h>
13#include <xrpl/protocol/STLedgerEntry.h>
14#include <xrpl/protocol/STObject.h>
15#include <xrpl/protocol/Serializer.h>
16#include <xrpl/protocol/TER.h>
78 MPTIssue
const& mptShare,
88[[nodiscard]]
inline bool
101 MPTIssue
const& mptIssue);
103[[nodiscard]]
inline bool
110 [&](
auto const& issue) {
118 ReadView
const& view,
123[[nodiscard]]
inline bool
135 ReadView
const& view,
137 MPTIssue
const& mptIssue,
145[[nodiscard]]
inline bool
153 [&](
auto const& issue) {
154 return isFrozen(view, account, issue, depth);
159[[nodiscard]]
inline TER
165[[nodiscard]]
inline TER
174[[nodiscard]]
inline TER
178 [&](
auto const& issue) {
return checkFrozen(view, account, issue); },
184 ReadView
const& view,
186 MPTIssue
const& mptIssue,
189[[nodiscard]]
inline bool
195 for (
auto const& account : accounts)
203[[nodiscard]]
inline bool
222 ReadView
const& view,
227[[nodiscard]]
inline bool
237[[nodiscard]]
inline bool
246 return isFrozen(view, account, mptIssue, depth);
254[[nodiscard]]
inline bool
262 [&](
auto const& issue) {
268[[nodiscard]]
inline TER
278[[nodiscard]]
inline TER
288[[nodiscard]]
inline TER
295 [&](
auto const& issue) {
303 ReadView
const& view,
306 Issue
const& asset2);
311[[nodiscard]] STAmount
313 ReadView
const& view,
320[[nodiscard]] STAmount
322 ReadView
const& view,
328[[nodiscard]] STAmount
330 ReadView
const& view,
332 MPTIssue
const& mptIssue,
337[[nodiscard]] STAmount
339 ReadView
const& view,
354[[nodiscard]] STAmount
356 ReadView
const& view,
363[[nodiscard]] STAmount
365 ReadView
const& view,
371[[nodiscard]] STAmount
373 ReadView
const& view,
375 MPTIssue
const& mptIssue,
380[[nodiscard]] STAmount
382 ReadView
const& view,
394[[nodiscard]] STAmount
396 ReadView
const& view,
398 STAmount
const& saDefault,
408[[nodiscard]] XRPAmount
410 ReadView
const& view,
418 ReadView
const& view,
430 ReadView
const& view,
486transferRate(ReadView
const& view, STAmount
const& amount);
492dirIsEmpty(ReadView
const& view, Keylet
const& k);
530 return (requested + 255) & (~255);
540 ReadView
const& validLedger,
541 ReadView
const& testLedger,
549 ReadView
const& testLedger,
584 ReadView
const& view,
616 ReadView
const& view,
652[[nodiscard]] Expected<std::shared_ptr<SLE>,
TER>
656 SField
const& ownerField);
681[[nodiscard]]
inline bool
717 ReadView
const& view,
720 bool hasDestinationTag);
737 ReadView
const& view,
739 bool hasDestinationTag);
763 XRPAmount priorBalance,
764 STAmount
const& amount,
773 XRPAmount priorBalance,
781 XRPAmount priorBalance,
782 MPTIssue
const& mptIssue,
785[[nodiscard]]
inline TER
796 view, accountID, priorBalance, issue, journal);
804 XRPAmount
const& priorBalance,
805 MPTID const& mptIssuanceID,
827 bool const bNoRipple,
830 STAmount
const& saBalance,
832 STAmount
const& saLimit,
849 MPTIssue
const& mptIssue,
852[[nodiscard]]
inline TER
904 STAmount
const& saAmount,
912 STAmount
const& saAmount,
920 STAmount
const& netAmount,
921 STAmount
const& grossAmount,
932 STAmount
const& saAmount,
1006 ReadView
const& view,
1036 ReadView
const& view,
1037 MPTIssue
const& mptIssue,
1050 return requireAuth(view, issue_, account, authType);
1081 MPTID const& mptIssuanceID,
1083 XRPAmount
const& priorBalance,
1092 ReadView
const& view,
1093 MPTIssue
const& mptIssue,
1099 ReadView
const& view,
1135 Keylet const& ownerDirKeylet,
1179 STAmount
const& assets,
1189 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
std::shared_ptr< STLedgerEntry const > const & const_ref
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
TypedField< STInteger< std::uint64_t > > SF_UINT64
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.
std::optional< STAmount > sharesToAssetsDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
TER checkDeepFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
base_uint< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
std::vector< SField const * > const & getPseudoAccountFields()
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
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...
FreezeHandling
Controls the treatment of frozen account balances.
bool dirFirst(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
AccountID pseudoAccountAddress(ReadView const &view, uint256 const &pseudoOwnerKey)
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
TER canAddHolding(ReadView const &view, Asset const &asset)
std::set< uint256 > getEnabledAmendments(ReadView const &view)
TER issueIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
TER removeEmptyHolding(ApplyView &view, AccountID const &accountID, Issue const &issue, beast::Journal journal)
bool isVaultPseudoAccountFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptShare, int depth)
TER rippleUnlockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, AccountID const &uGranteeID, STAmount const &netAmount, STAmount const &grossAmount, beast::Journal j)
TER doWithdraw(ApplyView &view, STTx const &tx, AccountID const &senderAcct, AccountID const &dstAcct, AccountID const &sourceAcct, XRPAmount priorBalance, STAmount const &amount, beast::Journal j)
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
TER checkFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
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.
bool isAnyFrozen(ReadView const &view, std::initializer_list< AccountID > const &accounts, MPTIssue const &mptIssue, int depth=0)
Number root(Number f, unsigned d)
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.
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
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)
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
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.
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
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,...
LedgerIndex getCandidateLedger(LedgerIndex requested)
Find a ledger index from which we could easily get the requested ledger.
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
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.
std::optional< STAmount > assetsToSharesDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets)
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
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)
TERSubset< CanCvtToTER > TER
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::uint32_t LedgerIndex
A ledger index.
base_uint< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
AuthHandling
Controls the treatment of unauthorized MPT balances.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
majorityAmendments_t getMajorityAmendments(ReadView const &view)
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
TER requireAuth(ReadView const &view, Issue const &issue, AccountID const &account, AuthType authType=AuthType::Legacy)
Check if the account lacks required authorization.
TER canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to)
Check if the destination account is allowed to receive MPT.
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
TER canWithdraw(AccountID const &from, ReadView const &view, AccountID const &to, SLE::const_ref toSle, bool hasDestinationTag)
Checks that can withdraw funds from an object to itself or a destination.
TER dirLink(ApplyView &view, AccountID const &owner, std::shared_ptr< SLE > &object, SF_UINT64 const &node=sfOwnerNode)
bool isIndividualFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
STAmount accountSpendable(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
TER redeemIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
std::optional< STAmount > sharesToAssetsWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
TER rippleLockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, STAmount const &saAmount, beast::Journal j)
LedgerEntryType
Identifiers for on-ledger objects.
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.
TER enforceMPTokenAuthorization(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, XRPAmount const &priorBalance, beast::Journal j)
Enforce account has MPToken to match its authorization.
Expected< std::shared_ptr< SLE >, TER > createPseudoAccount(ApplyView &view, uint256 const &pseudoOwnerKey, SField const &ownerField)
Create pseudo-account, storing pseudoOwnerKey into ownerField.
TER checkDestinationAndTag(SLE::const_ref toSle, bool hasDestinationTag)
Validates that the destination SLE and tag are valid.
TER accountSendMulti(ApplyView &view, AccountID const &senderID, Asset const &asset, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Like accountSend, except one account is sending multiple payments (with the same asset!...
TER trustDelete(ApplyView &view, std::shared_ptr< SLE > const &sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
bool dirNext(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
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.
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.
A pair of SHAMap key and LedgerEntryType.