rippled
Loading...
Searching...
No Matches
RippleStateHelpers.h
1#pragma once
2
3#include <xrpl/beast/utility/Journal.h>
4#include <xrpl/ledger/ApplyView.h>
5#include <xrpl/ledger/ReadView.h>
6#include <xrpl/ledger/helpers/TokenHelpers.h>
7#include <xrpl/protocol/IOUAmount.h>
8#include <xrpl/protocol/Issue.h>
9#include <xrpl/protocol/STAmount.h>
10#include <xrpl/protocol/STLedgerEntry.h>
11#include <xrpl/protocol/TER.h>
12
13//------------------------------------------------------------------------------
14//
15// RippleState (Trustline) helpers
16//
17//------------------------------------------------------------------------------
18
19namespace xrpl {
20
21//------------------------------------------------------------------------------
22//
23// Credit functions (from Credit.h)
24//
25//------------------------------------------------------------------------------
26
35STAmount
37 ReadView const& view,
38 AccountID const& account,
39 AccountID const& issuer,
40 Currency const& currency);
41
42IOUAmount
43creditLimit2(ReadView const& v, AccountID const& acc, AccountID const& iss, Currency const& cur);
53STAmount
55 ReadView const& view,
56 AccountID const& account,
57 AccountID const& issuer,
58 Currency const& currency);
61//------------------------------------------------------------------------------
62//
63// Freeze checking (IOU-specific)
64//
65//------------------------------------------------------------------------------
66
67[[nodiscard]] bool
69 ReadView const& view,
70 AccountID const& account,
71 Currency const& currency,
72 AccountID const& issuer);
73
74[[nodiscard]] inline bool
75isIndividualFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
76{
77 return isIndividualFrozen(view, account, issue.currency, issue.account);
78}
79
80[[nodiscard]] bool
82 ReadView const& view,
83 AccountID const& account,
84 Currency const& currency,
85 AccountID const& issuer);
86
87[[nodiscard]] inline bool
88isFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
89{
90 return isFrozen(view, account, issue.currency, issue.account);
91}
92
93// Overload with depth parameter for uniformity with MPTIssue version.
94// The depth parameter is ignored for IOUs since they don't have vault recursion.
95[[nodiscard]] inline bool
96isFrozen(ReadView const& view, AccountID const& account, Issue const& issue, int /*depth*/)
97{
98 return isFrozen(view, account, issue);
99}
100
101[[nodiscard]] bool
103 ReadView const& view,
104 AccountID const& account,
105 Currency const& currency,
106 AccountID const& issuer);
107
108[[nodiscard]] inline bool
110 ReadView const& view,
111 AccountID const& account,
112 Issue const& issue,
113 int = 0 /*ignored*/)
114{
115 return isDeepFrozen(view, account, issue.currency, issue.account);
116}
117
118[[nodiscard]] inline TER
119checkDeepFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
120{
121 return isDeepFrozen(view, account, issue) ? (TER)tecFROZEN : (TER)tesSUCCESS;
122}
123
124//------------------------------------------------------------------------------
125//
126// Trust line operations
127//
128//------------------------------------------------------------------------------
129
134[[nodiscard]] TER
136 ApplyView& view,
137 bool const bSrcHigh,
138 AccountID const& uSrcAccountID,
139 AccountID const& uDstAccountID,
140 uint256 const& uIndex, // --> ripple state entry
141 SLE::ref sleAccount, // --> the account being set.
142 bool const bAuth, // --> authorize account.
143 bool const bNoRipple, // --> others cannot ripple through
144 bool const bFreeze, // --> funds cannot leave
145 bool bDeepFreeze, // --> can neither receive nor send funds
146 STAmount const& saBalance, // --> balance of account being set.
147 // Issuer should be noAccount()
148 STAmount const& saLimit, // --> limit for account being set.
149 // Issuer should be the account being set.
150 std::uint32_t uQualityIn,
151 std::uint32_t uQualityOut,
153
154[[nodiscard]] TER
156 ApplyView& view,
157 std::shared_ptr<SLE> const& sleRippleState,
158 AccountID const& uLowAccountID,
159 AccountID const& uHighAccountID,
161
162//------------------------------------------------------------------------------
163//
164// IOU issuance/redemption
165//
166//------------------------------------------------------------------------------
167
168[[nodiscard]] TER
170 ApplyView& view,
171 AccountID const& account,
172 STAmount const& amount,
173 Issue const& issue,
175
176[[nodiscard]] TER
178 ApplyView& view,
179 AccountID const& account,
180 STAmount const& amount,
181 Issue const& issue,
183
184//------------------------------------------------------------------------------
185//
186// Authorization and transfer checks (IOU-specific)
187//
188//------------------------------------------------------------------------------
189
207[[nodiscard]] TER
209 ReadView const& view,
210 Issue const& issue,
211 AccountID const& account,
212 AuthType authType = AuthType::Legacy);
213
218[[nodiscard]] TER
219canTransfer(ReadView const& view, Issue const& issue, AccountID const& from, AccountID const& to);
220
221//------------------------------------------------------------------------------
222//
223// Empty holding operations (IOU-specific)
224//
225//------------------------------------------------------------------------------
226
229[[nodiscard]] TER
231 ApplyView& view,
232 AccountID const& accountID,
233 XRPAmount priorBalance,
234 Issue const& issue,
235 beast::Journal journal);
236
237[[nodiscard]] TER
239 ApplyView& view,
240 AccountID const& accountID,
241 Issue const& issue,
242 beast::Journal journal);
243
248[[nodiscard]] TER
250 ApplyView& view,
251 std::shared_ptr<SLE> sleState,
252 std::optional<AccountID> const& ammAccountID,
254
255} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
A currency issued by an account.
Definition Issue.h:13
Currency currency
Definition Issue.h:15
AccountID account
Definition Issue.h:16
A view into a ledger.
Definition ReadView.h:31
std::shared_ptr< STLedgerEntry > const & ref
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
TER checkDeepFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
base_uint< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition UintTypes.h:36
TER issueIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
bool isIndividualFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue)
TER trustCreate(ApplyView &view, bool const bSrcHigh, AccountID const &uSrcAccountID, AccountID const &uDstAccountID, uint256 const &uIndex, SLE::ref sleAccount, bool const bAuth, bool const bNoRipple, bool const bFreeze, bool bDeepFreeze, STAmount const &saBalance, STAmount const &saLimit, std::uint32_t uQualityIn, std::uint32_t uQualityOut, beast::Journal j)
Create a trust line.
TER addEmptyHolding(ApplyView &view, AccountID const &accountID, XRPAmount priorBalance, MPTIssue const &mptIssue, beast::Journal journal)
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
STAmount creditLimit(ReadView const &view, AccountID const &account, AccountID const &issuer, Currency const &currency)
Calculate the maximum amount of IOUs that an account can hold.
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
base_uint< 256 > uint256
Definition base_uint.h:531
IOUAmount creditLimit2(ReadView const &v, AccountID const &acc, AccountID const &iss, Currency const &cur)
bool isFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue, int depth=0)
TERSubset< CanCvtToTER > TER
Definition TER.h:622
STAmount creditBalance(ReadView const &view, AccountID const &account, AccountID const &issuer, Currency const &currency)
Returns the amount of IOUs issued by issuer that are held by an account.
TER canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to)
Check if the destination account is allowed to receive MPT.
TER redeemIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
@ tecFROZEN
Definition TER.h:284
TER trustDelete(ApplyView &view, std::shared_ptr< SLE > const &sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
TER removeEmptyHolding(ApplyView &view, AccountID const &accountID, MPTIssue const &mptIssue, beast::Journal journal)
@ tesSUCCESS
Definition TER.h:225
TER requireAuth(ReadView const &view, MPTIssue const &mptIssue, AccountID const &account, AuthType authType=AuthType::Legacy, int depth=0)
Check if the account lacks required authorization for MPT.