rippled
Loading...
Searching...
No Matches
PaymentSandbox.h
1#pragma once
2
3#include <xrpl/ledger/RawView.h>
4#include <xrpl/ledger/Sandbox.h>
5#include <xrpl/ledger/detail/ApplyViewBase.h>
6#include <xrpl/protocol/AccountID.h>
7
8#include <map>
9
10namespace xrpl {
11
12namespace detail {
13
14// VFALCO TODO Inline this implementation
15// into the PaymentSandbox class itself
17{
18public:
20 {
21 Adjustment(STAmount const& d, STAmount const& c, STAmount const& b)
22 : debits(d), credits(c), origBalance(b)
23 {
24 }
28 };
29
30 // Get the adjustments for the balance between main and other.
31 // Returns the debits, credits and the original balance
33 adjustments(AccountID const& main, AccountID const& other, Currency const& currency) const;
34
35 void
36 credit(
37 AccountID const& sender,
38 AccountID const& receiver,
39 STAmount const& amount,
40 STAmount const& preCreditSenderBalance);
41
42 void
43 ownerCount(AccountID const& id, std::uint32_t cur, std::uint32_t next);
44
45 // Get the adjusted owner count. Since DeferredCredits is meant to be used
46 // in payments, and payments only decrease owner counts, return the max
47 // remembered owner count.
49 ownerCount(AccountID const& id) const;
50
51 void
53
54private:
55 // lowAccount, highAccount
65
66 static Key
67 makeKey(AccountID const& a1, AccountID const& a2, Currency const& c);
68
71};
72
73} // namespace detail
74
75//------------------------------------------------------------------------------
76
90{
91public:
92 PaymentSandbox() = delete;
97 operator=(PaymentSandbox const&) = delete;
98
100
102 {
103 }
104
105 PaymentSandbox(ApplyView const* base) : ApplyViewBase(base, base->flags())
106 {
107 }
108
119 // VFALCO If we are constructing on top of a PaymentSandbox,
120 // or a PaymentSandbox-derived class, we MUST go through
121 // one of these constructors or invariants will be broken.
123 explicit PaymentSandbox(PaymentSandbox const* base)
124 : ApplyViewBase(base, base->flags()), ps_(base)
125 {
126 }
127
128 explicit PaymentSandbox(PaymentSandbox* base) : ApplyViewBase(base, base->flags()), ps_(base)
129 {
130 }
134 balanceHook(AccountID const& account, AccountID const& issuer, STAmount const& amount)
135 const override;
136
137 void
139 AccountID const& from,
140 AccountID const& to,
141 STAmount const& amount,
142 STAmount const& preCreditBalance) override;
143
144 void
145 adjustOwnerCountHook(AccountID const& account, std::uint32_t cur, std::uint32_t next) override;
146
148 ownerCountHook(AccountID const& account, std::uint32_t count) const override;
149
157 void
158 apply(RawView& to);
159
160 void
164 // Return a map of balance changes on trust lines. The low account is the
165 // first account in the key. If the two accounts are equal, the map contains
166 // the total changes in currency regardless of issuer. This is useful to get
167 // the total change in XRP balances.
169 balanceChanges(ReadView const& view) const;
170
172 xrpDestroyed() const;
173
174private:
176 PaymentSandbox const* ps_ = nullptr;
177};
178
179} // namespace xrpl
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:116
A wrapper which makes credits unavailable to balances.
STAmount balanceHook(AccountID const &account, AccountID const &issuer, STAmount const &amount) const override
PaymentSandbox(ReadView const *base, ApplyFlags flags)
void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next) override
PaymentSandbox(PaymentSandbox *base)
PaymentSandbox & operator=(PaymentSandbox &&)=delete
PaymentSandbox const * ps_
PaymentSandbox(PaymentSandbox const &)=delete
void apply(RawView &to)
Apply changes to base view.
PaymentSandbox(PaymentSandbox &&)=default
detail::DeferredCredits tab_
PaymentSandbox(ApplyView const *base)
std::uint32_t ownerCountHook(AccountID const &account, std::uint32_t count) const override
void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance) override
PaymentSandbox(PaymentSandbox const *base)
Construct on top of existing PaymentSandbox.
XRPAmount xrpDestroyed() const
PaymentSandbox & operator=(PaymentSandbox const &)=delete
std::map< std::tuple< AccountID, AccountID, Currency >, STAmount > balanceChanges(ReadView const &view) const
Interface for ledger entry changes.
Definition RawView.h:14
A view into a ledger.
Definition ReadView.h:31
ApplyFlags flags() const override
Returns the tx apply flags.
void apply(DeferredCredits &to)
std::optional< Adjustment > adjustments(AccountID const &main, AccountID const &other, Currency const &currency) const
std::map< AccountID, std::uint32_t > ownerCounts_
void credit(AccountID const &sender, AccountID const &receiver, STAmount const &amount, STAmount const &preCreditSenderBalance)
std::map< Key, Value > credits_
void ownerCount(AccountID const &id, std::uint32_t cur, std::uint32_t next)
static Key makeKey(AccountID const &a1, AccountID const &a2, Currency const &c)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
ApplyFlags
Definition ApplyView.h:10
Adjustment(STAmount const &d, STAmount const &c, STAmount const &b)