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 <vector>
19
20namespace xrpl {
21
27[[nodiscard]] bool
28isGlobalFrozen(ReadView const& view, AccountID const& issuer);
29
46[[nodiscard]] XRPAmount
47xrpLiquid(ReadView const& view, AccountID const& id, std::int32_t ownerCountAdj, beast::Journal j);
48
54
71[[nodiscard]] XRPAmount
73
84[[nodiscard]] inline XRPAmount
85accountReserve(ReadView const& view, AccountID const& id, beast::Journal j, Adjustment adj = {})
86{
87 return accountReserve(view, view.read(keylet::account(id)), j, adj);
88}
89
105[[nodiscard]] TER
108 SLE::ConstRef accSle,
109 XRPAmount accBalance,
110 SLE::ConstRef sponsorSle,
111 Adjustment adj,
112 beast::Journal j,
113 TER insufReserveCode = tecINSUFFICIENT_RESERVE);
114
132[[nodiscard]] TER
135 SLE::ConstRef accSle,
136 XRPAmount accBalance,
137 Adjustment adj,
138 beast::Journal j = beast::Journal{beast::Journal::getNullSink()});
139
149std::uint32_t
150ownerCount(SLE::ConstRef sle, beast::Journal j, std::int32_t ownerCountAdj = 0);
151
166void
168 ApplyView& view,
169 SLE::Ref accountSle,
170 SLE::Ref sponsorSle,
171 std::uint32_t count,
172 beast::Journal j);
173
188void
191 SLE::Ref accountSle,
192 std::uint32_t count,
193 beast::Journal j);
194
204inline void
206 ApplyView& view,
207 AccountID const& account,
208 std::optional<AccountID> const& sponsor,
209 std::uint32_t count,
211{
213 view,
214 view.peek(keylet::account(account)),
215 sponsor ? view.peek(keylet::account(*sponsor)) : SLE::pointer(),
216 count,
217 j);
218}
219
234void
236 ApplyView& view,
237 SLE::Ref accountSle,
238 SLE::Ref sponsorSle,
239 std::uint32_t count,
241
251inline void
253 ApplyView& view,
254 AccountID const& account,
255 std::optional<AccountID> const& sponsor,
256 std::uint32_t count,
258{
260 view,
261 view.peek(keylet::account(account)),
262 sponsor ? view.peek(keylet::account(*sponsor)) : SLE::pointer(),
263 count,
264 j);
265}
266
281void
283 ApplyView& view,
284 SLE::Ref accountSle,
285 SLE::Ref objectSle,
286 std::uint32_t count,
288
298inline void
300 ApplyView& view,
301 AccountID const& account,
302 SLE::Ref objectSle,
303 std::uint32_t count,
305{
306 SLE::Ref accountSle = view.peek(keylet::account(account));
307 decreaseOwnerCountForObject(view, accountSle, objectSle, count, j);
308}
309
325void
327 ApplyView& view,
328 SLE::Ref brokerSle,
329 std::int32_t delta,
331
338[[nodiscard]] Rate
339transferRate(ReadView const& view, AccountID const& issuer);
340
347pseudoAccountAddress(ReadView const& view, UInt256 const& pseudoOwnerKey);
348
357[[nodiscard]] std::vector<SField const*> const&
359
369[[nodiscard]] bool
371
375[[nodiscard]] inline bool
376isPseudoAccount(ReadView const& view, AccountID const& accountId)
377{
378 return isPseudoAccount(view.read(keylet::account(accountId)));
379}
380
389[[nodiscard]] std::expected<SLE::pointer, TER>
390createPseudoAccount(ApplyView& view, UInt256 const& pseudoOwnerKey, SField const& ownerField);
391
398[[nodiscard]] TER
399checkDestinationAndTag(SLE::ConstRef toSle, bool hasDestinationTag);
400
401} // 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:141
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.
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & ConstRef
std::shared_ptr< STLedgerEntry > const & Ref
std::shared_ptr< STLedgerEntry const > const_pointer
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:220
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.
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
Calculate liquid XRP balance for an account.
std::uint32_t ownerCount(SLE::ConstRef 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").
TER checkDestinationAndTag(SLE::ConstRef toSle, bool hasDestinationTag)
Checks the destination and tag.
std::expected< SLE::pointer, TER > createPseudoAccount(ApplyView &view, UInt256 const &pseudoOwnerKey, SField const &ownerField)
Create pseudo-account, storing pseudoOwnerKey into ownerField.
TER checkReserve(ApplyViewContext ctx, SLE::ConstRef accSle, XRPAmount accBalance, SLE::ConstRef sponsorSle, Adjustment adj, beast::Journal j, TER insufReserveCode=tecINSUFFICIENT_RESERVE)
Check if an account has sufficient reserve.
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.
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
Check if the issuer has the global freeze flag set.
BaseUInt< 256 > UInt256
Definition base_uint.h:580
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.
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.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
void adjustLoanBrokerOwnerCount(ApplyView &view, SLE::Ref brokerSle, std::int32_t delta, beast::Journal j)
Adjust a LoanBroker's owner count.
AccountID pseudoAccountAddress(ReadView const &view, UInt256 const &pseudoOwnerKey)
Generate a pseudo-account address from a pseudo owner key.
bool isPseudoAccount(SLE::const_pointer sleAcct)
Returns true if and only if sleAcct is a pseudo-account of any kind (i.e.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
TERSubset< CanCvtToTER > TER
Definition TER.h:654
XRPAmount accountReserve(ReadView const &view, SLE::ConstRef sle, beast::Journal j, Adjustment adj={})
Returns the account reserve, in drops.
@ tecINSUFFICIENT_RESERVE
Definition TER.h:315
std::int32_t accountCountDelta
std::int32_t ownerCountDelta
Bundles the mutable ledger view and the transaction being applied.
Definition ApplyView.h:451