20#include <xrpld/app/tx/detail/CreateCheck.h>
21#include <xrpld/ledger/View.h>
23#include <xrpl/basics/Log.h>
24#include <xrpl/protocol/Feature.h>
25#include <xrpl/protocol/Indexes.h>
26#include <xrpl/protocol/TER.h>
27#include <xrpl/protocol/TxFlags.h>
44 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: Invalid flags set.";
47 if (ctx.
tx[sfAccount] == ctx.
tx[sfDestination])
50 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: Check to self.";
56 if (!
isLegalNet(sendMax) || sendMax.signum() <= 0)
58 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: bad sendMax amount: "
59 << sendMax.getFullText();
65 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: Bad currency.";
70 if (
auto const optExpiry = ctx.
tx[~sfExpiration])
74 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: bad expiration";
89 JLOG(ctx.
j.
warn()) <<
"Destination account does not exist.";
93 auto const flags = sleDst->getFlags();
111 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: DestinationTag required.";
117 if (!sendMax.native())
120 AccountID const& issuerId{sendMax.getIssuer()};
123 JLOG(ctx.
j.
warn()) <<
"Creating a check for frozen asset";
132 if (issuerId != srcId)
135 auto const sleTrust = ctx.
view.
read(
142 <<
"Creating a check for frozen trustline.";
146 if (issuerId != dstId)
149 auto const sleTrust = ctx.
view.
read(
156 <<
"Creating a check for destination frozen trustline.";
164 JLOG(ctx.
j.
warn()) <<
"Creating a check that has already expired.";
192 auto sleCheck = std::make_shared<SLE>(checkKeylet);
194 sleCheck->setAccountID(sfAccount,
account_);
197 sleCheck->setFieldU32(sfSequence,
seq);
198 sleCheck->setFieldAmount(sfSendMax,
ctx_.
tx[sfSendMax]);
199 if (
auto const srcTag =
ctx_.
tx[~sfSourceTag])
200 sleCheck->setFieldU32(sfSourceTag, *srcTag);
201 if (
auto const dstTag =
ctx_.
tx[~sfDestinationTag])
202 sleCheck->setFieldU32(sfDestinationTag, *dstTag);
203 if (
auto const invoiceId =
ctx_.
tx[~sfInvoiceID])
204 sleCheck->setFieldH256(sfInvoiceID, *invoiceId);
205 if (
auto const expiry =
ctx_.
tx[~sfExpiration])
206 sleCheck->setFieldU32(sfExpiration, *expiry);
220 JLOG(
j_.
trace()) <<
"Adding Check to destination directory "
222 << (page ?
"success" :
"failure");
227 sleCheck->setFieldU64(sfDestinationNode, *page);
236 JLOG(
j_.
trace()) <<
"Adding Check to owner directory "
238 << (page ?
"success" :
"failure");
243 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 getFlags() 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
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
static bool adjustOwnerCount(ApplyContext &ctx, int count)
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
@ tecINSUFFICIENT_RESERVE
bool isTesSuccess(TER x) noexcept
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr std::uint32_t tfUniversalMask
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
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.
Set the sequence number on a JTx.