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: " << sendMax.getFullText();
32 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: Bad currency.";
37 if (
auto const optExpiry = ctx.
tx[~sfExpiration])
41 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: bad expiration";
56 JLOG(ctx.
j.
warn()) <<
"Destination account does not exist.";
60 auto const flags = sleDst->getFlags();
77 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: DestinationTag required.";
83 if (!sendMax.native())
86 AccountID const& issuerId{sendMax.getIssuer()};
89 JLOG(ctx.
j.
warn()) <<
"Creating a check for frozen asset";
98 if (issuerId != srcId)
104 JLOG(ctx.
j.
warn()) <<
"Creating a check for frozen trustline.";
108 if (issuerId != dstId)
114 JLOG(ctx.
j.
warn()) <<
"Creating a check for destination frozen trustline.";
122 JLOG(ctx.
j.
warn()) <<
"Creating a check that has already expired.";
151 sleCheck->setAccountID(sfAccount,
account_);
154 sleCheck->setFieldU32(sfSequence, seq);
155 sleCheck->setFieldAmount(sfSendMax,
ctx_.
tx[sfSendMax]);
156 if (
auto const srcTag =
ctx_.
tx[~sfSourceTag])
157 sleCheck->setFieldU32(sfSourceTag, *srcTag);
158 if (
auto const dstTag =
ctx_.
tx[~sfDestinationTag])
159 sleCheck->setFieldU32(sfDestinationTag, *dstTag);
160 if (
auto const invoiceId =
ctx_.
tx[~sfInvoiceID])
161 sleCheck->setFieldH256(sfInvoiceID, *invoiceId);
162 if (
auto const expiry =
ctx_.
tx[~sfExpiration])
163 sleCheck->setFieldU32(sfExpiration, *expiry);
174 JLOG(
j_.
trace()) <<
"Adding Check to destination directory " <<
to_string(checkKeylet.
key) <<
": "
175 << (page ?
"success" :
"failure");
180 sleCheck->setFieldU64(sfDestinationNode, *page);
186 JLOG(
j_.
trace()) <<
"Adding Check to owner directory " <<
to_string(checkKeylet.
key) <<
": "
187 << (page ?
"success" :
"failure");
192 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 Fees const & fees() const =0
Returns the fees for the base ledger.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
bool isFieldPresent(SField const &field) const
void setAccountID(SField const &field, AccountID const &)
AccountID getAccountID(SField const &field) const
STAmount const & getFieldAmount(SField const &field) const
std::uint32_t getSeqValue() const
Returns the first non-zero value of (Sequence, TicketSequence).
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.
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.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string to_string(base_uint< Bits, Tag > const &a)
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
bool isLegalNet(STAmount const &value)
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
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)
@ tecINSUFFICIENT_RESERVE
@ lsfDisallowIncomingCheck
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
TERSubset< CanCvtToNotTEC > NotTEC
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.