rippled
Loading...
Searching...
No Matches
PaymentChannelHelpers.cpp
1#include <xrpl/basics/Log.h>
2#include <xrpl/ledger/View.h>
3#include <xrpl/ledger/helpers/AccountRootHelpers.h>
4#include <xrpl/protocol/Indexes.h>
5
6#include <libxrpl/tx/transactors/payment_channel/PaymentChannelHelpers.h>
7
8namespace xrpl {
9
10TER
12 std::shared_ptr<SLE> const& slep,
13 ApplyView& view,
14 uint256 const& key,
16{
17 AccountID const src = (*slep)[sfAccount];
18 // Remove PayChan from owner directory
19 {
20 auto const page = (*slep)[sfOwnerNode];
21 if (!view.dirRemove(keylet::ownerDir(src), page, key, true))
22 {
23 // LCOV_EXCL_START
24 JLOG(j.fatal()) << "Could not remove paychan from src owner directory";
25 return tefBAD_LEDGER;
26 // LCOV_EXCL_STOP
27 }
28 }
29
30 // Remove PayChan from recipient's owner directory, if present.
31 if (auto const page = (*slep)[~sfDestinationNode])
32 {
33 auto const dst = (*slep)[sfDestination];
34 if (!view.dirRemove(keylet::ownerDir(dst), *page, key, true))
35 {
36 // LCOV_EXCL_START
37 JLOG(j.fatal()) << "Could not remove paychan from dst owner directory";
38 return tefBAD_LEDGER;
39 // LCOV_EXCL_STOP
40 }
41 }
42
43 // Transfer amount back to owner, decrement owner count
44 auto const sle = view.peek(keylet::account(src));
45 if (!sle)
46 return tefINTERNAL; // LCOV_EXCL_LINE
47
48 XRPL_ASSERT(
49 (*slep)[sfAmount] >= (*slep)[sfBalance], "xrpl::closeChannel : minimum channel amount");
50 (*sle)[sfBalance] = (*sle)[sfBalance] + (*slep)[sfAmount] - (*slep)[sfBalance];
51 adjustOwnerCount(view, sle, -1, j);
52 view.update(sle);
53
54 // Remove PayChan from ledger
55 view.erase(slep);
56 return tesSUCCESS;
57}
58
59} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
Stream fatal() const
Definition Journal.h:325
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:116
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:336
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:165
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ tefBAD_LEDGER
Definition TER.h:150
@ tefINTERNAL
Definition TER.h:153
TER closeChannel(std::shared_ptr< SLE > const &slep, ApplyView &view, uint256 const &key, beast::Journal j)
TERSubset< CanCvtToTER > TER
Definition TER.h:622
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
@ tesSUCCESS
Definition TER.h:225