1#include <xrpld/app/tx/detail/CreateCheck.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/ledger/View.h>
5#include <xrpl/protocol/Feature.h>
6#include <xrpl/protocol/Indexes.h>
7#include <xrpl/protocol/TER.h>
8#include <xrpl/protocol/TxFlags.h>
15 if (ctx.
tx[sfAccount] == ctx.
tx[sfDestination])
18 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: Check to self.";
24 if (!
isLegalNet(sendMax) || sendMax.signum() <= 0)
26 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: bad sendMax amount: "
27 << sendMax.getFullText();
33 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: Bad currency.";
38 if (
auto const optExpiry = ctx.
tx[~sfExpiration])
42 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: bad expiration";
57 JLOG(ctx.
j.
warn()) <<
"Destination account does not exist.";
61 auto const flags = sleDst->getFlags();
79 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: DestinationTag required.";
85 if (!sendMax.native())
88 AccountID const& issuerId{sendMax.getIssuer()};
91 JLOG(ctx.
j.
warn()) <<
"Creating a check for frozen asset";
100 if (issuerId != srcId)
103 auto const sleTrust = ctx.
view.
read(
110 <<
"Creating a check for frozen trustline.";
114 if (issuerId != dstId)
117 auto const sleTrust = ctx.
view.
read(
124 <<
"Creating a check for destination frozen trustline.";
132 JLOG(ctx.
j.
warn()) <<
"Creating a check that has already expired.";
162 sleCheck->setAccountID(sfAccount,
account_);
165 sleCheck->setFieldU32(sfSequence, seq);
166 sleCheck->setFieldAmount(sfSendMax,
ctx_.
tx[sfSendMax]);
167 if (
auto const srcTag =
ctx_.
tx[~sfSourceTag])
168 sleCheck->setFieldU32(sfSourceTag, *srcTag);
169 if (
auto const dstTag =
ctx_.
tx[~sfDestinationTag])
170 sleCheck->setFieldU32(sfDestinationTag, *dstTag);
171 if (
auto const invoiceId =
ctx_.
tx[~sfInvoiceID])
172 sleCheck->setFieldH256(sfInvoiceID, *invoiceId);
173 if (
auto const expiry =
ctx_.
tx[~sfExpiration])
174 sleCheck->setFieldU32(sfExpiration, *expiry);
188 JLOG(
j_.
trace()) <<
"Adding Check to destination directory "
190 << (page ?
"success" :
"failure");
195 sleCheck->setFieldU64(sfDestinationNode, *page);
204 JLOG(
j_.
trace()) <<
"Adding Check to owner directory "
206 << (page ?
"success" :
"failure");
211 sleCheck->setFieldU64(sfOwnerNode, *page);
Stream trace() const
Severity stream access functions.
virtual beast::Journal journal(std::string const &name)=0
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
std::optional< std::uint64_t > dirInsert(Keylet const &directory, uint256 const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Insert an entry to a directory.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual Rules const & rules() const =0
Returns the tx processing rules.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
AccountID getAccountID(SField const &field) const
STAmount const & getFieldAmount(SField const &field) const
bool isFieldPresent(SField const &field) const
void setAccountID(SField const &field, AccountID const &)
std::uint32_t getSeqValue() const
Returns the first non-zero value of (Sequence, TicketSequence).
Keylet line(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet check(AccountID const &id, std::uint32_t seq) noexcept
A Check.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
bool isLegalNet(STAmount const &value)
@ lsfDisallowIncomingCheck
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::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
@ tecINSUFFICIENT_RESERVE
std::string to_string(base_uint< Bits, Tag > const &a)
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct)
TERSubset< CanCvtToNotTEC > NotTEC
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
A pair of SHAMap key and LedgerEntryType.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.