1#include <xrpl/tx/transactors/payment_channel/PaymentChannelCreate.h>
3#include <xrpl/basics/chrono.h>
4#include <xrpl/beast/utility/Zero.h>
5#include <xrpl/core/ServiceRegistry.h>
6#include <xrpl/ledger/ApplyView.h>
7#include <xrpl/ledger/View.h>
8#include <xrpl/ledger/helpers/AccountRootHelpers.h>
9#include <xrpl/ledger/helpers/DirectoryHelpers.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/PublicKey.h>
15#include <xrpl/protocol/SField.h>
16#include <xrpl/protocol/STAmount.h>
17#include <xrpl/protocol/STLedgerEntry.h>
18#include <xrpl/protocol/STTx.h>
19#include <xrpl/protocol/TER.h>
20#include <xrpl/protocol/XRPAmount.h>
21#include <xrpl/tx/Transactor.h>
22#include <xrpl/tx/applySteps.h>
59 if (!
isXRP(ctx.
tx[sfAmount]) || (ctx.
tx[sfAmount] <= beast::kZero))
62 if (ctx.
tx[sfAccount] == ctx.
tx[sfDestination])
74 auto const account = ctx.
tx[sfAccount];
81 auto const balance = (*sle)[sfBalance];
84 if (balance < reserve)
87 if (balance < reserve + ctx.
tx[sfAmount])
91 auto const dst = ctx.
tx[sfDestination];
100 if (sled->isFlag(lsfDisallowIncomingPayChan))
103 if (sled->isFlag(lsfRequireDestTag) && !ctx.
tx[~sfDestinationTag])
122 auto const account =
ctx_.tx[sfAccount];
127 if (
ctx_.view().rules().enabled(fixPayChanCancelAfter))
129 auto const closeTime =
ctx_.view().header().parentCloseTime;
130 if (
ctx_.tx[~sfCancelAfter] &&
after(closeTime,
ctx_.tx[sfCancelAfter]))
134 auto const dst =
ctx_.tx[sfDestination];
144 (*slep)[sfAmount] =
ctx_.tx[sfAmount];
146 (*slep)[sfBalance] =
ctx_.tx[sfAmount].zeroed();
147 (*slep)[sfAccount] = account;
148 (*slep)[sfDestination] = dst;
149 (*slep)[sfSettleDelay] =
ctx_.tx[sfSettleDelay];
150 (*slep)[sfPublicKey] =
ctx_.tx[sfPublicKey];
151 (*slep)[~sfCancelAfter] =
ctx_.tx[~sfCancelAfter];
152 (*slep)[~sfSourceTag] =
ctx_.tx[~sfSourceTag];
153 (*slep)[~sfDestinationTag] =
ctx_.tx[~sfDestinationTag];
154 if (
ctx_.view().rules().enabled(fixIncludeKeyletFields))
156 (*slep)[sfSequence] =
ctx_.tx.getSeqValue();
159 ctx_.view().insert(slep);
163 auto const page =
ctx_.view().dirInsert(
167 (*slep)[sfOwnerNode] = *page;
176 (*slep)[sfDestinationNode] = *page;
180 (*sle)[sfBalance] = (*sle)[sfBalance] -
ctx_.tx[sfAmount];
182 ctx_.view().update(sle);
A generic endpoint for log messages.
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
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.
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.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
std::shared_ptr< STLedgerEntry const > const & const_ref
Class describing the consequences to the account of applying a transaction if the transaction consume...
Keylet payChannel(AccountID const &src, AccountID const &dst, std::uint32_t seq) noexcept
A PaymentChannel.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isXRP(AccountID const &c)
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
TERSubset< CanCvtToNotTEC > NotTEC
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
void adjustOwnerCount(ApplyView &view, SLE::ref sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Returns a function that sets the owner on a directory SLE.
TERSubset< CanCvtToTER > TER
@ tecINSUFFICIENT_RESERVE
bool isPseudoAccount(SLE::const_pointer sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
Returns true if and only if sleAcct is a pseudo-account or specific pseudo-accounts in pseudoFieldFil...
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.