1#include <xrpl/ledger/helpers/AccountRootHelpers.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/instrumentation.h>
5#include <xrpl/protocol/Feature.h>
6#include <xrpl/protocol/LedgerFormats.h>
7#include <xrpl/protocol/digest.h>
20 return sle->isFlag(lsfGlobalFreeze);
45 JLOG(j.fatal()) <<
"Account " << *
id <<
" owner count exceeds max!";
57 JLOG(j.fatal()) <<
"Account " << *
id <<
" owner count set below 0!";
60 XRPL_ASSERT(!
id,
"xrpl::confineOwnerCount : id is not set");
81 auto const fullBalance = sle->getFieldAmount(sfBalance);
85 STAmount const amount = (balance < reserve) ?
STAmount{0} : balance - reserve;
88 <<
" amount=" << amount.getFullText()
89 <<
" fullBalance=" << fullBalance.getFullText()
90 <<
" balance=" << balance.getFullText() <<
" reserve=" << reserve
91 <<
" ownerCount=" << ownerCount <<
" ownerCountAdj=" << ownerCountAdj;
101 if (sle && sle->isFieldPresent(sfTransferRate))
102 return Rate{sle->getFieldU32(sfTransferRate)};
116 XRPL_ASSERT(amount,
"xrpl::adjustOwnerCount : nonzero amount input");
121 sle->at(sfOwnerCount) = adjusted;
134 rsh(hash.data(), hash.size());
157 "xrpl::getPseudoAccountFields : unable to find account root "
161 auto const& soTemplate = ar->getSOTemplate();
164 for (
auto const& field : soTemplate)
183 return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT &&
185 fields.begin(), fields.end(), [&sleAcct, &pseudoFieldFilter](
SField const* sf) ->
bool {
186 return sleAcct->isFieldPresent(*sf) &&
187 (pseudoFieldFilter.empty() || pseudoFieldFilter.contains(sf));
191Expected<std::shared_ptr<SLE>,
TER>
200 [&ownerField](
SField const* sf) ->
bool { return *sf == ownerField; }) == 1,
201 "xrpl::createPseudoAccount : valid owner field");
204 if (accountId == beast::zero)
209 account->setAccountID(sfAccount, accountId);
210 account->setFieldAmount(sfBalance,
STAmount{});
220 account->setFieldU32(sfSequence, seqno);
224 account->setFieldU32(sfFlags, lsfDisableMaster | lsfDefaultRipple | lsfDepositAuth);
226 account->setFieldH256(ownerField, pseudoOwnerKey);
236 if (toSle ==
nullptr)
241 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 update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
virtual void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next)
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 LedgerHeader const & header() const =0
Returns information about the ledger.
virtual STAmount balanceHook(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
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 std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
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)
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
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::string to_string(base_uint< Bits, Tag > const &a)
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
@ current
This was a new validation and was added.
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
Returns true if and only if sleAcct is a pseudo-account or specific pseudo-accounts in pseudoFieldFil...
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.
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.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
AccountID const & xrpAccount()
Compute AccountID from public key.
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)
Checks the destination and tag.
Rate const parityRate
A transfer rate signifying a 1:1 exchange.
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.