rippled
Loading...
Searching...
No Matches
PaymentSandbox.h
1#ifndef XRPL_LEDGER_PAYMENTSANDBOX_H_INCLUDED
2#define XRPL_LEDGER_PAYMENTSANDBOX_H_INCLUDED
3
4#include <xrpl/ledger/RawView.h>
5#include <xrpl/ledger/Sandbox.h>
6#include <xrpl/ledger/detail/ApplyViewBase.h>
7#include <xrpl/protocol/AccountID.h>
8
9#include <map>
10
11namespace ripple {
12
13namespace detail {
14
15// VFALCO TODO Inline this implementation
16// into the PaymentSandbox class itself
18{
19public:
21 {
22 Adjustment(STAmount const& d, STAmount const& c, STAmount const& b)
23 : debits(d), credits(c), origBalance(b)
24 {
25 }
29 };
30
31 // Get the adjustments for the balance between main and other.
32 // Returns the debits, credits and the original balance
35 AccountID const& main,
36 AccountID const& other,
37 Currency const& currency) const;
38
39 void
40 credit(
41 AccountID const& sender,
42 AccountID const& receiver,
43 STAmount const& amount,
44 STAmount const& preCreditSenderBalance);
45
46 void
47 ownerCount(AccountID const& id, std::uint32_t cur, std::uint32_t next);
48
49 // Get the adjusted owner count. Since DeferredCredits is meant to be used
50 // in payments, and payments only decrease owner counts, return the max
51 // remembered owner count.
53 ownerCount(AccountID const& id) const;
54
55 void
57
58private:
59 // lowAccount, highAccount
69
70 static Key
71 makeKey(AccountID const& a1, AccountID const& a2, Currency const& c);
72
75};
76
77} // namespace detail
78
79//------------------------------------------------------------------------------
80
94{
95public:
96 PaymentSandbox() = delete;
101 operator=(PaymentSandbox const&) = delete;
102
104
106 : ApplyViewBase(base, flags)
107 {
108 }
109
110 PaymentSandbox(ApplyView const* base) : ApplyViewBase(base, base->flags())
111 {
112 }
113
124 // VFALCO If we are constructing on top of a PaymentSandbox,
125 // or a PaymentSandbox-derived class, we MUST go through
126 // one of these constructors or invariants will be broken.
128 explicit PaymentSandbox(PaymentSandbox const* base)
129 : ApplyViewBase(base, base->flags()), ps_(base)
130 {
131 }
132
134 : ApplyViewBase(base, base->flags()), ps_(base)
135 {
136 }
141 AccountID const& account,
142 AccountID const& issuer,
143 STAmount const& amount) const override;
144
145 void
147 AccountID const& from,
148 AccountID const& to,
149 STAmount const& amount,
150 STAmount const& preCreditBalance) override;
151
152 void
154 AccountID const& account,
155 std::uint32_t cur,
156 std::uint32_t next) override;
157
159 ownerCountHook(AccountID const& account, std::uint32_t count)
160 const override;
161
169 void
170 apply(RawView& to);
171
172 void
176 // Return a map of balance changes on trust lines. The low account is the
177 // first account in the key. If the two accounts are equal, the map contains
178 // the total changes in currency regardless of issuer. This is useful to get
179 // the total change in XRP balances.
181 balanceChanges(ReadView const& view) const;
182
184 xrpDestroyed() const;
185
186private:
188 PaymentSandbox const* ps_ = nullptr;
189};
190
191} // namespace ripple
192
193#endif
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:124
A wrapper which makes credits unavailable to balances.
XRPAmount xrpDestroyed() const
std::uint32_t ownerCountHook(AccountID const &account, std::uint32_t count) const override
std::map< std::tuple< AccountID, AccountID, Currency >, STAmount > balanceChanges(ReadView const &view) const
void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance) override
PaymentSandbox(ApplyView const *base)
void apply(RawView &to)
Apply changes to base view.
detail::DeferredCredits tab_
PaymentSandbox & operator=(PaymentSandbox &&)=delete
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(PaymentSandbox const &)=delete
PaymentSandbox(PaymentSandbox const *base)
Construct on top of existing PaymentSandbox.
PaymentSandbox const * ps_
PaymentSandbox & operator=(PaymentSandbox const &)=delete
PaymentSandbox(PaymentSandbox &&)=default
Interface for ledger entry changes.
Definition RawView.h:15
A view into a ledger.
Definition ReadView.h:32
ApplyFlags flags() const override
Returns the tx apply flags.
std::optional< Adjustment > adjustments(AccountID const &main, AccountID const &other, Currency const &currency) const
void credit(AccountID const &sender, AccountID const &receiver, STAmount const &amount, STAmount const &preCreditSenderBalance)
void apply(DeferredCredits &to)
std::map< AccountID, std::uint32_t > ownerCounts_
void ownerCount(AccountID const &id, std::uint32_t cur, std::uint32_t next)
std::map< Key, Value > credits_
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:6
Adjustment(STAmount const &d, STAmount const &c, STAmount const &b)