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/AccountRootHelpers.h>
8#include <xrpl/ledger/helpers/PaymentChannelHelpers.h>
9#include <xrpl/protocol/AccountID.h>
10#include <xrpl/protocol/Feature.h>
11#include <xrpl/protocol/Indexes.h>
12#include <xrpl/protocol/Keylet.h>
13#include <xrpl/protocol/LedgerFormats.h>
14#include <xrpl/protocol/SField.h>
15#include <xrpl/protocol/STAmount.h>
16#include <xrpl/protocol/STLedgerEntry.h>
17#include <xrpl/protocol/STTx.h>
18#include <xrpl/protocol/TER.h>
19#include <xrpl/protocol/XRPAmount.h>
20#include <xrpl/tx/Transactor.h>
21#include <xrpl/tx/applySteps.h>
47 auto const slep =
ctx_.view().peek(k);
52 auto const txAccount =
ctx_.tx[sfAccount];
53 auto const curExpiration = (*slep)[~sfExpiration];
67 if (
auto newExpiration =
ctx_.tx[~sfExpiration])
71 ctx_.view().header().parentCloseTime.time_since_epoch().count(),
72 (*slep)[sfSettleDelay]);
73 if (curExpiration && *curExpiration < minExpiration)
74 minExpiration = *curExpiration;
76 if (*newExpiration < minExpiration)
81 (*slep)[~sfExpiration] = *newExpiration;
82 ctx_.view().update(slep);
91 STAmount const balance = (*sle)[sfBalance];
112 (*slep)[sfAmount] = (*slep)[sfAmount] +
ctx_.tx[sfAmount];
113 ctx_.view().update(slep);
115 (*sle)[sfBalance] = (*sle)[sfBalance] -
ctx_.tx[sfAmount];
116 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.
TER checkReserve(ApplyViewContext ctx, SLE::const_ref accSle, XRPAmount accBalance, SLE::const_ref sponsorSle, Adjustment adj, beast::Journal j, TER insufReserveCode=tecINSUFFICIENT_RESERVE)
Check if an account has sufficient reserve.
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
XRPAmount accountReserve(ReadView const &view, SLE::const_ref sle, beast::Journal j, Adjustment adj={})
Returns the account reserve, in drops.
A pair of SHAMap key and LedgerEntryType.
State information when preflighting a tx.