rippled
Loading...
Searching...
No Matches
PaymentSandbox.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_LEDGER_PAYMENTSANDBOX_H_INCLUDED
21#define RIPPLE_LEDGER_PAYMENTSANDBOX_H_INCLUDED
22
23#include <xrpl/ledger/RawView.h>
24#include <xrpl/ledger/Sandbox.h>
25#include <xrpl/ledger/detail/ApplyViewBase.h>
26#include <xrpl/protocol/AccountID.h>
27
28#include <map>
29
30namespace ripple {
31
32namespace detail {
33
34// VFALCO TODO Inline this implementation
35// into the PaymentSandbox class itself
37{
38public:
40 {
41 Adjustment(STAmount const& d, STAmount const& c, STAmount const& b)
42 : debits(d), credits(c), origBalance(b)
43 {
44 }
48 };
49
50 // Get the adjustments for the balance between main and other.
51 // Returns the debits, credits and the original balance
54 AccountID const& main,
55 AccountID const& other,
56 Currency const& currency) const;
57
58 void
59 credit(
60 AccountID const& sender,
61 AccountID const& receiver,
62 STAmount const& amount,
63 STAmount const& preCreditSenderBalance);
64
65 void
66 ownerCount(AccountID const& id, std::uint32_t cur, std::uint32_t next);
67
68 // Get the adjusted owner count. Since DeferredCredits is meant to be used
69 // in payments, and payments only decrease owner counts, return the max
70 // remembered owner count.
72 ownerCount(AccountID const& id) const;
73
74 void
76
77private:
78 // lowAccount, highAccount
88
89 static Key
90 makeKey(AccountID const& a1, AccountID const& a2, Currency const& c);
91
94};
95
96} // namespace detail
97
98//------------------------------------------------------------------------------
99
113{
114public:
115 PaymentSandbox() = delete;
120 operator=(PaymentSandbox const&) = delete;
121
123
125 : ApplyViewBase(base, flags)
126 {
127 }
128
129 PaymentSandbox(ApplyView const* base) : ApplyViewBase(base, base->flags())
130 {
131 }
132
143 // VFALCO If we are constructing on top of a PaymentSandbox,
144 // or a PaymentSandbox-derived class, we MUST go through
145 // one of these constructors or invariants will be broken.
147 explicit PaymentSandbox(PaymentSandbox const* base)
148 : ApplyViewBase(base, base->flags()), ps_(base)
149 {
150 }
151
153 : ApplyViewBase(base, base->flags()), ps_(base)
154 {
155 }
160 AccountID const& account,
161 AccountID const& issuer,
162 STAmount const& amount) const override;
163
164 void
166 AccountID const& from,
167 AccountID const& to,
168 STAmount const& amount,
169 STAmount const& preCreditBalance) override;
170
171 void
173 AccountID const& account,
174 std::uint32_t cur,
175 std::uint32_t next) override;
176
178 ownerCountHook(AccountID const& account, std::uint32_t count)
179 const override;
180
188 void
189 apply(RawView& to);
190
191 void
195 // Return a map of balance changes on trust lines. The low account is the
196 // first account in the key. If the two accounts are equal, the map contains
197 // the total changes in currency regardless of issuer. This is useful to get
198 // the total change in XRP balances.
200 balanceChanges(ReadView const& view) const;
201
203 xrpDestroyed() const;
204
205private:
207 PaymentSandbox const* ps_ = nullptr;
208};
209
210} // namespace ripple
211
212#endif
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:143
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:34
A view into a ledger.
Definition ReadView.h:51
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:25
Adjustment(STAmount const &d, STAmount const &c, STAmount const &b)