xrpld
Loading...
Searching...
No Matches
AccountRootHelpers.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/ledger/ApplyView.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/Rate.h>
10#include <xrpl/protocol/SField.h>
11#include <xrpl/protocol/STLedgerEntry.h>
12#include <xrpl/protocol/TER.h>
13#include <xrpl/protocol/XRPAmount.h>
14
15#include <cstdint>
16#include <expected>
17#include <optional>
18#include <set>
19#include <vector>
20
21namespace xrpl {
22
28[[nodiscard]] bool
29isGlobalFrozen(ReadView const& view, AccountID const& issuer);
30
47[[nodiscard]] XRPAmount
48xrpLiquid(ReadView const& view, AccountID const& id, std::int32_t ownerCountAdj, beast::Journal j);
49
55
72[[nodiscard]] XRPAmount
74
85[[nodiscard]] inline XRPAmount
86accountReserve(ReadView const& view, AccountID const& id, beast::Journal j, Adjustment adj = {})
87{
88 return accountReserve(view, view.read(keylet::account(id)), j, adj);
89}
90
106[[nodiscard]] TER
109 SLE::const_ref accSle,
110 XRPAmount accBalance,
111 SLE::const_ref sponsorSle,
112 Adjustment adj,
113 beast::Journal j,
114 TER insufReserveCode = tecINSUFFICIENT_RESERVE);
115
133[[nodiscard]] TER
136 SLE::const_ref accSle,
137 XRPAmount accBalance,
138 Adjustment adj,
139 beast::Journal j = beast::Journal{beast::Journal::getNullSink()});
140
150std::uint32_t
151ownerCount(SLE::const_ref sle, beast::Journal j, std::int32_t ownerCountAdj = 0);
152
167void
169 ApplyView& view,
170 SLE::ref accountSle,
171 SLE::ref sponsorSle,
172 std::uint32_t count,
173 beast::Journal j);
174
189void
192 SLE::ref accountSle,
193 std::uint32_t count,
194 beast::Journal j);
195
205inline void
207 ApplyView& view,
208 AccountID const& account,
209 std::optional<AccountID> const& sponsor,
210 std::uint32_t count,
212{
214 view,
215 view.peek(keylet::account(account)),
216 sponsor ? view.peek(keylet::account(*sponsor)) : SLE::pointer(),
217 count,
218 j);
219}
220
235void
237 ApplyView& view,
238 SLE::ref accountSle,
239 SLE::ref sponsorSle,
240 std::uint32_t count,
242
252inline void
254 ApplyView& view,
255 AccountID const& account,
256 std::optional<AccountID> const& sponsor,
257 std::uint32_t count,
259{
261 view,
262 view.peek(keylet::account(account)),
263 sponsor ? view.peek(keylet::account(*sponsor)) : SLE::pointer(),
264 count,
265 j);
266}
267
282void
284 ApplyView& view,
285 SLE::ref accountSle,
286 SLE::ref objectSle,
287 std::uint32_t count,
289
299inline void
301 ApplyView& view,
302 AccountID const& account,
303 SLE::ref objectSle,
304 std::uint32_t count,
306{
307 SLE::ref accountSle = view.peek(keylet::account(account));
308 decreaseOwnerCountForObject(view, accountSle, objectSle, count, j);
309}
310
326void
328 ApplyView& view,
329 SLE::ref brokerSle,
330 std::int32_t delta,
332
339[[nodiscard]] Rate
340transferRate(ReadView const& view, AccountID const& issuer);
341
348pseudoAccountAddress(ReadView const& view, uint256 const& pseudoOwnerKey);
349
358[[nodiscard]] std::vector<SField const*> const&
360
370[[nodiscard]] bool
371isPseudoAccount(SLE::const_pointer sleAcct, std::set<SField const*> const& pseudoFieldFilter = {});
372
376[[nodiscard]] inline bool
378 ReadView const& view,
379 AccountID const& accountId,
380 std::set<SField const*> const& pseudoFieldFilter = {})
381{
382 return isPseudoAccount(view.read(keylet::account(accountId)), pseudoFieldFilter);
383}
384
393[[nodiscard]] std::expected<SLE::pointer, TER>
394createPseudoAccount(ApplyView& view, uint256 const& pseudoOwnerKey, SField const& ownerField);
395
402[[nodiscard]] TER
403checkDestinationAndTag(SLE::const_ref toSle, bool hasDestinationTag);
404
405} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
static Sink & getNullSink()
Returns a Sink which does nothing.
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:134
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
A view into a ledger.
Definition ReadView.h:41
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
Identifies fields.
Definition SField.h:132
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & const_ref
std::shared_ptr< STLedgerEntry const > const_pointer
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:198
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::vector< SField const * > const & getPseudoAccountFields()
Returns the list of fields that define an ACCOUNT_ROOT as a pseudo-account if set.
void decreaseOwnerCountForObject(ApplyView &view, SLE::ref accountSle, SLE::ref objectSle, std::uint32_t count, beast::Journal j)
Decrease owner-count fields for an existing ledger object.
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
Calculate liquid XRP balance for an account.
AccountID pseudoAccountAddress(ReadView const &view, uint256 const &pseudoOwnerKey)
Generate a pseudo-account address from a pseudo owner key.
void increaseOwnerCount(ApplyView &view, SLE::ref accountSle, SLE::ref sponsorSle, std::uint32_t count, beast::Journal j)
Increase owner-count fields when the caller supplies the sponsor.
void adjustLoanBrokerOwnerCount(ApplyView &view, SLE::ref brokerSle, std::int32_t delta, beast::Journal j)
Adjust a LoanBroker's owner count.
std::expected< SLE::pointer, TER > createPseudoAccount(ApplyView &view, uint256 const &pseudoOwnerKey, SField const &ownerField)
Create pseudo-account, storing pseudoOwnerKey into ownerField.
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
Check if the issuer has the global freeze flag set.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
void decreaseOwnerCount(ApplyView &view, SLE::ref accountSle, SLE::ref sponsorSle, std::uint32_t count, beast::Journal j)
Decrease owner-count fields when the caller supplies the sponsor.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
TER checkReserve(ApplyViewContext ctx, SLE::const_ref accSle, XRPAmount accBalance, SLE::const_ref sponsorSle, Adjustment adj, beast::Journal j, TER insufReserveCode=tecINSUFFICIENT_RESERVE)
Check if an account has sufficient reserve.
TERSubset< CanCvtToTER > TER
Definition TER.h:647
@ tecINSUFFICIENT_RESERVE
Definition TER.h:310
bool isPseudoAccount(SLE::const_pointer sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
Returns true if and only if sleAcct is a pseudo-account or specific pseudo-accounts in pseudoFieldFil...
TER checkDestinationAndTag(SLE::const_ref toSle, bool hasDestinationTag)
Checks the destination and tag.
std::uint32_t ownerCount(SLE::const_ref sle, beast::Journal j, std::int32_t ownerCountAdj=0)
Return number of the objects which reserve is covered by the account(sle) (so called "ownercount").
BaseUInt< 256 > uint256
Definition base_uint.h:580
XRPAmount accountReserve(ReadView const &view, SLE::const_ref sle, beast::Journal j, Adjustment adj={})
Returns the account reserve, in drops.
std::int32_t accountCountDelta
std::int32_t ownerCountDelta
Bundles the mutable ledger view and the transaction being applied.
Definition ApplyView.h:444