20 #include <ripple/app/ledger/Ledger.h>
21 #include <ripple/app/paths/Flow.h>
22 #include <ripple/app/tx/impl/CashCheck.h>
23 #include <ripple/basics/Log.h>
24 #include <ripple/basics/scope.h>
25 #include <ripple/protocol/Feature.h>
26 #include <ripple/protocol/Indexes.h>
27 #include <ripple/protocol/STAccount.h>
28 #include <ripple/protocol/TER.h>
29 #include <ripple/protocol/TxFlags.h>
48 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: Invalid flags set.";
56 if (
static_cast<bool>(optAmount) ==
static_cast<bool>(optDeliverMin))
59 <<
"Malformed transaction: "
60 "does not specify exactly one of Amount and DeliverMin.";
65 STAmount const value{optAmount ? *optAmount : *optDeliverMin};
68 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: bad amount: "
69 << value.getFullText();
75 JLOG(ctx.
j.
warn()) <<
"Malformed transaction: Bad currency.";
88 JLOG(ctx.
j.
warn()) <<
"Check does not exist.";
96 JLOG(ctx.
j.
warn()) <<
"Cashing a check with wrong Destination.";
104 JLOG(ctx.
j.
error()) <<
"Malformed transaction: Cashing check to self.";
110 if (!sleSrc || !sleDst)
114 <<
"Malformed transaction: source or destination not in ledger";
124 <<
"Malformed transaction: DestinationTag required in check.";
131 JLOG(ctx.
j.
warn()) <<
"Cashing a check that has already expired.";
139 auto const optAmount = tx[~
sfAmount];
144 Currency const currency{value.getCurrency()};
147 JLOG(ctx.
j.
warn()) <<
"Check cash does not match check currency.";
150 AccountID const issuerId{value.getIssuer()};
153 JLOG(ctx.
j.
warn()) <<
"Check cash does not match check issuer.";
158 JLOG(ctx.
j.
warn()) <<
"Check cashed for more than check sendMax.";
179 if (value > availableFunds)
182 <<
"Check cashed for more than owner's balance.";
188 if (!value.native() && (value.getIssuer() != dstId))
190 auto const sleTrustLine =
197 <<
"Cannot cash check for IOU without trustline.";
205 <<
"Can't receive IOUs from non-existent issuer: "
222 bool const canonical_gt(dstId > issuerId);
224 bool const is_authorized(
231 <<
"Can't receive IOUs from issuer without auth.";
244 JLOG(ctx.
j.
warn()) <<
"Cashing a check to a frozen trustline.";
262 JLOG(
j_.
fatal()) <<
"Precheck did not verify check's existence.";
271 <<
"Precheck did not verify source or destination's existence.";
312 if (srcLiquid < xrpDeliver)
316 JLOG(
j_.
trace()) <<
"Cash Check: Insufficient XRP: "
317 << srcLiquid.getFullText() <<
" < "
318 << xrpDeliver.getFullText();
322 if (optDeliverMin && doFix1623)
344 optDeliverMin->issue(),
350 Issue const& trustLineIssue = flowDeliver.issue();
351 AccountID const issuer = flowDeliver.getIssuer();
354 bool const destLow = issuer >
account_;
356 bool const checkCashMakesTrustLine =
359 if (checkCashMakesTrustLine && !psb.
exists(trustLineKey))
374 JLOG(
j_.
trace()) <<
"Trust line does not exist. "
375 "Insufficent reserve to create line.";
380 Currency const currency = flowDeliver.getCurrency();
381 STAmount initialBalance(flowDeliver.issue());
417 auto const sleTrustLine = psb.
peek(trustLineKey);
422 STAmount const savedLimit = sleTrustLine->at(tweakedLimit);
426 [&psb, &trustLineKey, &tweakedLimit, &savedLimit]() {
427 if (
auto const sleTrustLine = psb.
peek(trustLineKey))
428 sleTrustLine->at(tweakedLimit) = savedLimit;
431 if (checkCashMakesTrustLine)
437 sleTrustLine->at(tweakedLimit) = bigAmount;
441 auto const result =
flow(
448 static_cast<bool>(optDeliverMin),
458 return result.result();
464 if (result.actualAmountOut < *optDeliverMin)
467 <<
"flow did not produce DeliverMin.";
470 if (doFix1623 && !checkCashMakesTrustLine)
477 if (checkCashMakesTrustLine)
493 JLOG(
j_.
fatal()) <<
"Unable to delete check from destination.";
504 JLOG(
j_.
fatal()) <<
"Unable to delete check from owner.";
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
const SF_UINT32 sfOwnerCount
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
A pair of SHAMap key and LedgerEntryType.
A currency issued by an account.
const SF_AMOUNT sfSendMax
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
const SF_UINT64 sfOwnerNode
A field with a type known at compile time.
Stream trace() const
Severity stream access functions.
const SF_ACCOUNT sfDestination
A wrapper which makes credits unavailable to balances.
const SF_UINT256 sfCheckID
static NotTEC preflight(PreflightContext const &ctx)
bool exists(Keylet const &k) const override
Determine if a state item exists.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
void update(std::shared_ptr< SLE > const &sle) override
Indicate changes to a peeked SLE.
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
const beast::Journal journal
bool isLegalNet(STAmount const &value)
void setIssuer(AccountID const &uIssuer)
Fees const & fees() const override
Returns the fees for the base ledger.
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
AccountID const & getIssuer() const
const SF_UINT32 sfExpiration
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
const SF_AMOUNT sfDeliverMin
const SF_AMOUNT sfLowLimit
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
path::RippleCalc::Output flow(PaymentSandbox &view, STAmount const &deliver, AccountID const &src, AccountID const &dst, STPathSet const &paths, bool defaultPaths, bool partialPayment, bool ownerPaysTransferFee, bool offerCrossing, std::optional< Quality > const &limitQuality, std::optional< STAmount > const &sendMax, beast::Journal j, path::detail::FlowDebugInfo *flowDebugInfo=nullptr)
Make a payment from the src account to the dst account.
Keylet account(AccountID const &id) noexcept
AccountID root.
static TER preclaim(PreclaimContext const &ctx)
const SF_UINT64 sfDestinationNode
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
std::uint32_t getFlags() const
void deliver(STAmount const &amount)
Sets the DeliveredAmount field in the metadata.
const SF_AMOUNT sfHighLimit
Keylet line(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
const uint256 featureChecks
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
State information when determining if a tx is likely to claim a fee.
void erase(std::shared_ptr< SLE > const &sle) override
Remove a peeked SLE.
bool native() const noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
virtual beast::Journal journal(std::string const &name)=0
TER trustCreate(ApplyView &view, const bool bSrcHigh, AccountID const &uSrcAccountID, AccountID const &uDstAccountID, uint256 const &uIndex, SLE::ref sleAccount, const bool bAuth, const bool bNoRipple, const bool bFreeze, STAmount const &saBalance, STAmount const &saLimit, std::uint32_t uQualityIn, std::uint32_t uQualityOut, beast::Journal j)
Create a trust line.
@ tecNO_LINE_INSUF_RESERVE
void apply(RawView &to)
Apply changes to base view.
virtual Rules const & rules() const =0
Returns the tx processing rules.
const SF_UINT32 sfDestinationTag
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
const SF_ACCOUNT sfAccount
std::shared_ptr< SLE > peek(Keylet const &k) override
Prepare to modify the SLE associated with key.
Rules const & rules() const override
Returns the tx processing rules.
const uint256 featureCheckCashMakesTrustLine
State information when preflighting a tx.
static const int cMaxOffset
Keylet check(AccountID const &id, std::uint32_t seq) noexcept
A Check.
constexpr std::uint32_t tfUniversalMask
Currency const & getCurrency() const
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
STAmount const & getFieldAmount(SField const &field) const
AccountID const & noAccount()
A placeholder for empty accounts.
static const std::uint64_t cMaxValue
TERSubset< CanCvtToNotTEC > NotTEC