20#include <xrpld/app/tx/detail/PayChan.h>
22#include <xrpl/basics/Log.h>
23#include <xrpl/basics/chrono.h>
24#include <xrpl/ledger/ApplyView.h>
25#include <xrpl/ledger/CredentialHelpers.h>
26#include <xrpl/ledger/View.h>
27#include <xrpl/protocol/Feature.h>
28#include <xrpl/protocol/Indexes.h>
29#include <xrpl/protocol/PayChan.h>
30#include <xrpl/protocol/PublicKey.h>
31#include <xrpl/protocol/TxFlags.h>
32#include <xrpl/protocol/XRPAmount.h>
33#include <xrpl/protocol/digest.h>
123 AccountID const src = (*slep)[sfAccount];
126 auto const page = (*slep)[sfOwnerNode];
131 <<
"Could not remove paychan from src owner directory";
138 if (
auto const page = (*slep)[~sfDestinationNode];
139 page && view.
rules().enabled(fixPayChanRecipientOwnerDir))
141 auto const dst = (*slep)[sfDestination];
146 <<
"Could not remove paychan from dst owner directory";
158 (*slep)[sfAmount] >= (*slep)[sfBalance],
159 "ripple::closeChannel : minimum channel amount");
161 (*sle)[sfBalance] + (*slep)[sfAmount] - (*slep)[sfBalance];
181 if (!
isXRP(ctx.
tx[sfAmount]) || (ctx.
tx[sfAmount] <= beast::zero))
184 if (ctx.
tx[sfAccount] == ctx.
tx[sfDestination])
196 auto const account = ctx.
tx[sfAccount];
203 auto const balance = (*sle)[sfBalance];
207 if (balance < reserve)
210 if (balance < reserve + ctx.
tx[sfAmount])
214 auto const dst = ctx.
tx[sfDestination];
222 auto const flags = sled->getFlags();
254 auto const account =
ctx_.
tx[sfAccount];
266 auto const dst =
ctx_.
tx[sfDestination];
272 Keylet const payChanKeylet =
277 (*slep)[sfAmount] =
ctx_.
tx[sfAmount];
279 (*slep)[sfBalance] =
ctx_.
tx[sfAmount].zeroed();
280 (*slep)[sfAccount] = account;
281 (*slep)[sfDestination] = dst;
282 (*slep)[sfSettleDelay] =
ctx_.
tx[sfSettleDelay];
283 (*slep)[sfPublicKey] =
ctx_.
tx[sfPublicKey];
284 (*slep)[~sfCancelAfter] =
ctx_.
tx[~sfCancelAfter];
285 (*slep)[~sfSourceTag] =
ctx_.
tx[~sfSourceTag];
286 (*slep)[~sfDestinationTag] =
ctx_.
tx[~sfDestinationTag];
302 (*slep)[sfOwnerNode] = *page;
312 (*slep)[sfDestinationNode] = *page;
316 (*sle)[sfBalance] = (*sle)[sfBalance] -
ctx_.
tx[sfAmount];
334 if (!
isXRP(ctx.
tx[sfAmount]) || (ctx.
tx[sfAmount] <= beast::zero))
348 AccountID const src = (*slep)[sfAccount];
349 auto const txAccount =
ctx_.
tx[sfAccount];
350 auto const expiration = (*slep)[~sfExpiration];
353 auto const cancelAfter = (*slep)[~sfCancelAfter];
354 auto const closeTime =
356 if ((cancelAfter && closeTime >= *cancelAfter) ||
357 (expiration && closeTime >= *expiration))
362 if (src != txAccount)
366 if (
auto extend =
ctx_.
tx[~sfExpiration])
370 (*slep)[sfSettleDelay];
371 if (expiration && *expiration < minExpiration)
372 minExpiration = *expiration;
374 if (*extend < minExpiration)
376 (*slep)[~sfExpiration] = *extend;
386 auto const balance = (*sle)[sfBalance];
390 if (balance < reserve)
393 if (balance < reserve +
ctx_.
tx[sfAmount])
398 if (
AccountID const dst = (*slep)[sfDestination];
404 (*slep)[sfAmount] = (*slep)[sfAmount] +
ctx_.
tx[sfAmount];
407 (*sle)[sfBalance] = (*sle)[sfBalance] -
ctx_.
tx[sfAmount];
431 auto const bal = ctx.
tx[~sfBalance];
432 if (bal && (!
isXRP(*bal) || *bal <= beast::zero))
435 auto const amt = ctx.
tx[~sfAmount];
436 if (amt && (!
isXRP(*amt) || *amt <= beast::zero))
439 if (bal && amt && *bal > *amt)
449 if (
auto const sig = ctx.
tx[~sfSignature])
451 if (!(ctx.
tx[~sfPublicKey] && bal))
458 auto const reqBalance = bal->xrp();
459 auto const authAmt = amt ? amt->xrp() : reqBalance;
461 if (reqBalance > authAmt)
464 Keylet const k(ltPAYCHAN, ctx.
tx[sfChannel]);
504 AccountID const src = (*slep)[sfAccount];
505 AccountID const dst = (*slep)[sfDestination];
508 auto const curExpiration = (*slep)[~sfExpiration];
510 auto const cancelAfter = (*slep)[~sfCancelAfter];
511 auto const closeTime =
513 if ((cancelAfter && closeTime >= *cancelAfter) ||
514 (curExpiration && closeTime >= *curExpiration))
519 if (txAccount != src && txAccount != dst)
524 auto const chanBalance = slep->getFieldAmount(sfBalance).xrp();
525 auto const chanFunds = slep->getFieldAmount(sfAmount).xrp();
526 auto const reqBalance =
ctx_.
tx[sfBalance].xrp();
528 if (txAccount == dst && !
ctx_.
tx[~sfSignature])
531 if (
ctx_.
tx[~sfSignature])
533 PublicKey const pk((*slep)[sfPublicKey]);
534 if (
ctx_.
tx[sfPublicKey] != pk)
538 if (reqBalance > chanFunds)
541 if (reqBalance <= chanBalance)
564 (*slep)[sfBalance] =
ctx_.
tx[sfBalance];
565 XRPAmount const reqDelta = reqBalance - chanBalance;
567 reqDelta >= beast::zero,
568 "ripple::PayChanClaim::doApply : minimum balance delta");
569 (*sled)[sfBalance] = (*sled)[sfBalance] + reqDelta;
576 if (src != txAccount)
585 if (dst == txAccount || (*slep)[sfBalance] == (*slep)[sfAmount])
589 auto const settleExpiration =
591 (*slep)[sfSettleDelay];
593 if (!curExpiration || *curExpiration > settleExpiration)
595 (*slep)[~sfExpiration] = settleExpiration;
A generic endpoint for log messages.
virtual beast::Journal journal(std::string const &name)=0
beast::Journal const journal
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.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
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.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static bool checkExtraFeatures(PreflightContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TxConsequences makeTxConsequences(PreflightContext 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 LedgerInfo const & info() const =0
Returns information about the 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.
bool isFieldPresent(SField const &field) const
std::uint32_t getFlags() const
std::uint32_t getSeqValue() const
Returns the first non-zero value of (Sequence, TicketSequence).
Slice slice() const noexcept
static TER preclaim(PreclaimContext const &ctx)
Class describing the consequences to the account of applying a transaction if the transaction consume...
NotTEC checkFields(STTx const &tx, beast::Journal j)
TER valid(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet payChan(AccountID const &src, AccountID const &dst, std::uint32_t seq) noexcept
A PaymentChannel.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static TER closeChannel(std::shared_ptr< SLE > const &slep, ApplyView &view, uint256 const &key, beast::Journal j)
bool isXRP(AccountID const &c)
constexpr std::uint32_t tfRenew
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical=true) noexcept
Verify a signature on a message.
@ lsfDisallowIncomingPayChan
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)
TER verifyDepositPreauth(STTx const &tx, ApplyView &view, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE > const &sleDst, beast::Journal j)
void serializePayChanAuthorization(Serializer &msg, uint256 const &key, XRPAmount const &amt)
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
@ tecINSUFFICIENT_RESERVE
bool isTesSuccess(TER x) noexcept
constexpr std::uint32_t tfClose
constexpr std::uint32_t tfPayChanClaimMask
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
TERSubset< CanCvtToTER > TER
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct)
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.
T time_since_epoch(T... args)