1#include <xrpl/ledger/helpers/PaymentChannelHelpers.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/beast/utility/instrumentation.h>
7#include <xrpl/ledger/ApplyView.h>
8#include <xrpl/ledger/View.h>
9#include <xrpl/ledger/helpers/AccountRootHelpers.h>
10#include <xrpl/protocol/AccountID.h>
11#include <xrpl/protocol/Feature.h>
12#include <xrpl/protocol/Indexes.h>
13#include <xrpl/protocol/SField.h>
14#include <xrpl/protocol/STLedgerEntry.h>
15#include <xrpl/protocol/TER.h>
30 auto const page = (*slep)[sfOwnerNode];
34 JLOG(j.
fatal()) <<
"Could not remove paychan from src owner directory";
41 if (
auto const page = (*slep)[~sfDestinationNode])
43 auto const dst = (*slep)[sfDestination];
47 JLOG(j.
fatal()) <<
"Could not remove paychan from dst owner directory";
59 (*slep)[sfAmount] >= (*slep)[sfBalance],
"xrpl::closeChannel : minimum channel amount");
60 (*sle)[sfBalance] = (*sle)[sfBalance] + (*slep)[sfAmount] - (*slep)[sfBalance];
72 if (rules.
enabled(fixCleanup3_2_0))
74 static constexpr auto kUint32Max =
76 uint64_t
const saturatedResult =
std::min(uint64_t{lhs} + rhs, kUint32Max);
77 return static_cast<uint32_t
>(saturatedResult);
A generic endpoint for log messages.
Writeable view to a ledger, for applying a transaction.
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void erase(SLE::ref sle)=0
Remove a peeked SLE.
virtual void update(SLE::ref sle)=0
Indicate changes to a peeked SLE.
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
Rules controlling protocol behavior.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
std::shared_ptr< STLedgerEntry > const & ref
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 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 after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
uint32_t saturatingAdd(Rules const &rules, uint32_t const lhs, uint32_t const rhs)
Add two uint32_t values with saturation at UINT32_MAX.
void adjustOwnerCount(ApplyView &view, SLE::ref sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
TERSubset< CanCvtToTER > TER
T time_since_epoch(T... args)