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) : debits(d), credits(c), origBalance(b)
22 {
23 }
27 };
28
29 // Get the adjustments for the balance between main and other.
30 // Returns the debits, credits and the original balance
32 adjustments(AccountID const& main, AccountID const& other, Currency const& currency) const;
33
34 void
35 credit(
36 AccountID const& sender,
37 AccountID const& receiver,
38 STAmount const& amount,
39 STAmount const& preCreditSenderBalance);
40
41 void
42 ownerCount(AccountID const& id, std::uint32_t cur, std::uint32_t next);
43
44 // Get the adjusted owner count. Since DeferredCredits is meant to be used
45 // in payments, and payments only decrease owner counts, return the max
46 // remembered owner count.
48 ownerCount(AccountID const& id) const;
49
50 void
52
53private:
54 // lowAccount, highAccount
64
65 static Key
66 makeKey(AccountID const& a1, AccountID const& a2, Currency const& c);
67
70};
71
72} // namespace detail
73
74//------------------------------------------------------------------------------
75
89{
90public:
91 PaymentSandbox() = delete;
96 operator=(PaymentSandbox const&) = delete;
97
99
101 {
102 }
103
104 PaymentSandbox(ApplyView const* base) : ApplyViewBase(base, base->flags())
105 {
106 }
107
118 // VFALCO If we are constructing on top of a PaymentSandbox,
119 // or a PaymentSandbox-derived class, we MUST go through
120 // one of these constructors or invariants will be broken.
122 explicit PaymentSandbox(PaymentSandbox const* base) : ApplyViewBase(base, base->flags()), ps_(base)
123 {
124 }
125
126 explicit PaymentSandbox(PaymentSandbox* base) : ApplyViewBase(base, base->flags()), ps_(base)
127 {
128 }
132 balanceHook(AccountID const& account, AccountID const& issuer, STAmount const& amount) const override;
133
134 void
135 creditHook(AccountID const& from, AccountID const& to, STAmount const& amount, STAmount const& preCreditBalance)
136 override;
137
138 void
139 adjustOwnerCountHook(AccountID const& account, std::uint32_t cur, std::uint32_t next) override;
140
142 ownerCountHook(AccountID const& account, std::uint32_t count) const override;
143
151 void
152 apply(RawView& to);
153
154 void
158 // Return a map of balance changes on trust lines. The low account is the
159 // first account in the key. If the two accounts are equal, the map contains
160 // the total changes in currency regardless of issuer. This is useful to get
161 // the total change in XRP balances.
163 balanceChanges(ReadView const& view) const;
164
166 xrpDestroyed() const;
167
168private:
170 PaymentSandbox const* ps_ = nullptr;
171};
172
173} // namespace xrpl
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:114
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)