1#include <xrpl/ledger/ApplyView.h>
2#include <xrpl/ledger/View.h>
3#include <xrpl/ledger/helpers/CredentialHelpers.h>
4#include <xrpl/protocol/Feature.h>
5#include <xrpl/protocol/Indexes.h>
6#include <xrpl/protocol/PayChan.h>
7#include <xrpl/protocol/PublicKey.h>
8#include <xrpl/protocol/TxFlags.h>
9#include <xrpl/tx/transactors/payment_channel/PaymentChannelClaim.h>
11#include <libxrpl/tx/transactors/payment_channel/PaymentChannelHelpers.h>
24 return tfPaymentChannelClaimMask;
30 auto const bal = ctx.
tx[~sfBalance];
31 if (bal && (!
isXRP(*bal) || *bal <= beast::zero))
34 auto const amt = ctx.
tx[~sfAmount];
35 if (amt && (!
isXRP(*amt) || *amt <= beast::zero))
38 if (bal && amt && *bal > *amt)
44 if (((flags & tfClose) != 0u) && ((flags & tfRenew) != 0u))
48 if (
auto const sig = ctx.
tx[~sfSignature])
50 if (!(ctx.
tx[~sfPublicKey] && bal))
57 auto const reqBalance = bal->xrp();
58 auto const authAmt = amt ? amt->xrp() : reqBalance;
60 if (reqBalance > authAmt)
63 Keylet const k(ltPAYCHAN, ctx.
tx[sfChannel]);
101 AccountID const src = (*slep)[sfAccount];
102 AccountID const dst = (*slep)[sfDestination];
105 auto const curExpiration = (*slep)[~sfExpiration];
107 auto const cancelAfter = (*slep)[~sfCancelAfter];
109 if ((cancelAfter && closeTime >= *cancelAfter) ||
110 (curExpiration && closeTime >= *curExpiration))
114 if (txAccount != src && txAccount != dst)
119 auto const chanBalance = slep->getFieldAmount(sfBalance).xrp();
120 auto const chanFunds = slep->getFieldAmount(sfAmount).xrp();
121 auto const reqBalance =
ctx_.
tx[sfBalance].xrp();
123 if (txAccount == dst && !
ctx_.
tx[~sfSignature])
126 if (
ctx_.
tx[~sfSignature])
128 PublicKey const pk((*slep)[sfPublicKey]);
129 if (
ctx_.
tx[sfPublicKey] != pk)
133 if (reqBalance > chanFunds)
136 if (reqBalance <= chanBalance)
151 (*slep)[sfBalance] =
ctx_.
tx[sfBalance];
152 XRPAmount const reqDelta = reqBalance - chanBalance;
154 reqDelta >= beast::zero,
"xrpl::PaymentChannelClaim::doApply : minimum balance delta");
155 (*sled)[sfBalance] = (*sled)[sfBalance] + reqDelta;
162 if (src != txAccount)
171 if (dst == txAccount || (*slep)[sfBalance] == (*slep)[sfAmount])
174 auto const settleExpiration =
176 (*slep)[sfSettleDelay];
178 if (!curExpiration || *curExpiration > settleExpiration)
180 (*slep)[~sfExpiration] = settleExpiration;
std::reference_wrapper< ServiceRegistry > registry
beast::Journal const journal
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static bool checkExtraFeatures(PreflightContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
bool isFieldPresent(SField const &field) const
std::uint32_t getFlags() const
Slice slice() const noexcept
static TER preclaim(PreclaimContext const &ctx)
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.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isXRP(AccountID const &c)
TER verifyDepositPreauth(STTx const &tx, ApplyView &view, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE const > const &sleDst, beast::Journal j)
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig) noexcept
Verify a signature on a message.
void serializePayChanAuthorization(Serializer &msg, uint256 const &key, XRPAmount const &amt)
TER closeChannel(std::shared_ptr< SLE > const &slep, ApplyView &view, uint256 const &key, beast::Journal j)
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
bool isTesSuccess(TER x) noexcept
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)