1#include <xrpl/ledger/helpers/AccountRootHelpers.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/basics/contract.h>
6#include <xrpl/beast/utility/Journal.h>
7#include <xrpl/beast/utility/Zero.h>
8#include <xrpl/beast/utility/instrumentation.h>
9#include <xrpl/ledger/ApplyView.h>
10#include <xrpl/ledger/ReadView.h>
11#include <xrpl/protocol/AccountID.h>
12#include <xrpl/protocol/Feature.h>
13#include <xrpl/protocol/Indexes.h>
14#include <xrpl/protocol/LedgerFormats.h>
15#include <xrpl/protocol/Rate.h>
16#include <xrpl/protocol/SField.h>
17#include <xrpl/protocol/STLedgerEntry.h>
18#include <xrpl/protocol/TER.h>
19#include <xrpl/protocol/XRPAmount.h>
20#include <xrpl/protocol/digest.h>
40 return sle->isFlag(lsfGlobalFreeze);
61 if (adjusted < current)
65 JLOG(j.fatal()) <<
"Account " << *
id <<
" owner count exceeds max!";
73 if (adjusted > current)
77 JLOG(j.fatal()) <<
"Account " << *
id <<
" owner count set below 0!";
80 XRPL_ASSERT(!
id,
"xrpl::confineOwnerCount : id is not set");
101 auto const fullBalance = sle->getFieldAmount(sfBalance);
105 STAmount const amount = (balance < reserve) ?
STAmount{0} : balance - reserve;
107 JLOG(j.
trace()) <<
"accountHolds:" <<
" account=" <<
to_string(
id)
109 <<
" fullBalance=" << fullBalance.getFullText()
110 <<
" balance=" << balance.getFullText() <<
" reserve=" << reserve
111 <<
" ownerCount=" << ownerCount <<
" ownerCountAdj=" << ownerCountAdj;
121 if (sle && sle->isFieldPresent(sfTransferRate))
122 return Rate{sle->getFieldU32(sfTransferRate)};
132 XRPL_ASSERT(amount,
"xrpl::adjustOwnerCount : nonzero amount input");
137 sle->at(sfOwnerCount) = adjusted;
150 rsh(hash.data(), hash.size());
173 "xrpl::getPseudoAccountFields : unable to find account root "
177 auto const& soTemplate = ar->getSOTemplate();
180 for (
auto const& field : soTemplate)
187 return kPseudoFields;
197 return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT &&
199 fields.begin(), fields.end(), [&sleAcct, &pseudoFieldFilter](
SField const* sf) ->
bool {
200 return sleAcct->isFieldPresent(*sf) &&
201 (pseudoFieldFilter.empty() || pseudoFieldFilter.contains(sf));
205std::expected<SLE::pointer, TER>
214 [&ownerField](
SField const* sf) ->
bool { return *sf == ownerField; }) == 1,
215 "xrpl::createPseudoAccount : valid owner field");
218 if (accountId == beast::kZero)
223 account->setAccountID(sfAccount, accountId);
224 account->setFieldAmount(sfBalance,
STAmount{});
234 account->setFieldU32(sfSequence, seqno);
238 account->setFieldU32(sfFlags, lsfDisableMaster | lsfDefaultRipple | lsfDepositAuth);
240 account->setFieldH256(ownerField, pseudoOwnerKey);
250 if (toSle ==
nullptr)
255 if (toSle->isFlag(lsfRequireDestTag) && !hasDestinationTag)
A generic endpoint for log messages.
static Sink & getNullSink()
Returns a Sink which does nothing.
Stream trace() const
Severity stream access functions.
Writeable view to a ledger, for applying a transaction.
virtual void insert(SLE::ref sle)=0
Insert a new state SLE.
virtual void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next)
virtual void update(SLE::ref sle)=0
Indicate changes to a peeked SLE.
static BaseUInt fromRaw(Container const &c)
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
virtual std::uint32_t ownerCountHook(AccountID const &account, std::uint32_t count) const
virtual STAmount balanceHookIOU(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
static constexpr auto kSmdPseudoAccount
std::string getFullText() const override
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry const > const & const_ref
std::shared_ptr< STLedgerEntry const > const_pointer
T emplace_back(T... args)
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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)
AccountID pseudoAccountAddress(ReadView const &view, uint256 const &pseudoOwnerKey)
Generate a pseudo-account address from a pseudo owner key.
bool isXRP(AccountID const &c)
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
std::expected< SLE::pointer, TER > createPseudoAccount(ApplyView &view, uint256 const &pseudoOwnerKey, SField const &ownerField)
Create pseudo-account, storing pseudoOwnerKey into ownerField.
std::string to_string(BaseUInt< Bits, Tag > const &a)
static std::uint32_t confineOwnerCount(std::uint32_t current, std::int32_t adjustment, std::optional< AccountID > const &id=std::nullopt, beast::Journal j=beast::Journal{beast::Journal::getNullSink()})
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.
Rate const kParityRate
A transfer rate signifying a 1:1 exchange.
void adjustOwnerCount(ApplyView &view, SLE::ref sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
TERSubset< CanCvtToTER > TER
AccountID const & xrpAccount()
Compute AccountID from public key.
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.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
Represents a transfer rate.
Returns the RIPEMD-160 digest of the SHA256 hash of the message.
std::array< std::uint8_t, 20 > result_type