1#include <xrpl/tx/transactors/payment_channel/PaymentChannelFund.h>
3#include <xrpl/beast/utility/Journal.h>
4#include <xrpl/beast/utility/Zero.h>
5#include <xrpl/ledger/ApplyView.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/ledger/helpers/PaymentChannelHelpers.h>
8#include <xrpl/protocol/AccountID.h>
9#include <xrpl/protocol/Feature.h>
10#include <xrpl/protocol/Indexes.h>
11#include <xrpl/protocol/Keylet.h>
12#include <xrpl/protocol/LedgerFormats.h>
13#include <xrpl/protocol/SField.h>
14#include <xrpl/protocol/STAmount.h>
15#include <xrpl/protocol/STLedgerEntry.h>
16#include <xrpl/protocol/STTx.h>
17#include <xrpl/protocol/TER.h>
18#include <xrpl/protocol/XRPAmount.h>
19#include <xrpl/tx/Transactor.h>
20#include <xrpl/tx/applySteps.h>
33 if (ctx.
rules.
enabled(fixCleanup3_2_0) && ctx.
tx[sfChannel] == beast::kZero)
36 if (!
isXRP(ctx.
tx[sfAmount]) || (ctx.
tx[sfAmount] <= beast::kZero))
46 auto const slep =
ctx_.view().peek(k);
51 auto const txAccount =
ctx_.tx[sfAccount];
52 auto const curExpiration = (*slep)[~sfExpiration];
66 if (
auto newExpiration =
ctx_.tx[~sfExpiration])
70 ctx_.view().header().parentCloseTime.time_since_epoch().count(),
71 (*slep)[sfSettleDelay]);
72 if (curExpiration && *curExpiration < minExpiration)
73 minExpiration = *curExpiration;
75 if (*newExpiration < minExpiration)
80 (*slep)[~sfExpiration] = *newExpiration;
81 ctx_.view().update(slep);
90 auto const balance = (*sle)[sfBalance];
91 auto const reserve =
ctx_.view().fees().accountReserve((*sle)[sfOwnerCount]);
93 if (balance < reserve)
96 if (balance < reserve +
ctx_.tx[sfAmount])
106 (*slep)[sfAmount] = (*slep)[sfAmount] +
ctx_.tx[sfAmount];
107 ctx_.view().update(slep);
109 (*sle)[sfBalance] = (*sle)[sfBalance] -
ctx_.tx[sfAmount];
110 ctx_.view().update(sle);
A generic endpoint for log messages.
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
static NotTEC preflight(PreflightContext const &ctx)
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
std::shared_ptr< STLedgerEntry const > const & const_ref
Class describing the consequences to the account of applying a transaction if the transaction consume...
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isChannelExpired(ApplyView const &view, std::optional< std::uint32_t > timeField)
Determine whether a payment channel time field represents an expired time.
TER closeChannel(SLE::ref slep, ApplyView &view, uint256 const &key, beast::Journal j)
Close a payment channel and return its remaining funds to the channel owner.
bool isXRP(AccountID const &c)
TERSubset< CanCvtToNotTEC > NotTEC
uint32_t saturatingAdd(Rules const &rules, uint32_t const lhs, uint32_t const rhs)
Add two uint32_t values with saturation at UINT32_MAX.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
TERSubset< CanCvtToTER > TER
@ tecINSUFFICIENT_RESERVE
A pair of SHAMap key and LedgerEntryType.
State information when preflighting a tx.