xrpld
Loading...
Searching...
No Matches
RippleStateHelpers.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/ledger/ApplyView.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/ledger/helpers/TokenHelpers.h>
8#include <xrpl/protocol/AccountID.h>
9#include <xrpl/protocol/IOUAmount.h>
10#include <xrpl/protocol/Issue.h>
11#include <xrpl/protocol/STAmount.h>
12#include <xrpl/protocol/STLedgerEntry.h>
13#include <xrpl/protocol/TER.h>
14#include <xrpl/protocol/UintTypes.h>
15#include <xrpl/protocol/XRPAmount.h>
16
17#include <cstdint>
18#include <optional>
19
20//------------------------------------------------------------------------------
21//
22// RippleState (Trustline) helpers
23//
24//------------------------------------------------------------------------------
25
26namespace xrpl {
27
28//------------------------------------------------------------------------------
29//
30// Credit functions (from Credit.h)
31//
32//------------------------------------------------------------------------------
33
45 ReadView const& view,
46 AccountID const& account,
47 AccountID const& issuer,
48 Currency const& currency);
49
51creditLimit2(ReadView const& v, AccountID const& acc, AccountID const& iss, Currency const& cur);
53
64 ReadView const& view,
65 AccountID const& account,
66 AccountID const& issuer,
67 Currency const& currency);
69
70//------------------------------------------------------------------------------
71//
72// Freeze checking (IOU-specific)
73//
74//------------------------------------------------------------------------------
75
76[[nodiscard]] bool
78 ReadView const& view,
79 AccountID const& account,
80 Currency const& currency,
81 AccountID const& issuer);
82
83[[nodiscard]] inline bool
84isIndividualFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
85{
86 return isIndividualFrozen(view, account, issue.currency, issue.account);
87}
88
89[[nodiscard]] bool
91 ReadView const& view,
92 AccountID const& account,
93 Currency const& currency,
94 AccountID const& issuer);
95
96[[nodiscard]] inline bool
97isFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
98{
99 return isFrozen(view, account, issue.currency, issue.account);
100}
101
102// Overload with depth parameter for uniformity with MPTIssue version.
103// The depth parameter is ignored for IOUs since they don't have vault recursion.
104[[nodiscard]] inline bool
105isFrozen(ReadView const& view, AccountID const& account, Issue const& issue, std::uint8_t /*depth*/)
106{
107 return isFrozen(view, account, issue);
108}
109
110[[nodiscard]] bool
112 ReadView const& view,
113 AccountID const& account,
114 Currency const& currency,
115 AccountID const& issuer);
116
117[[nodiscard]] inline bool
119 ReadView const& view,
120 AccountID const& account,
121 Issue const& issue,
122 std::uint8_t = 0 /*ignored*/)
123{
124 return isDeepFrozen(view, account, issue.currency, issue.account);
125}
126
127[[nodiscard]] inline TER
128checkDeepFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
129{
130 return isDeepFrozen(view, account, issue) ? (TER)tecFROZEN : (TER)tesSUCCESS;
131}
132
133//------------------------------------------------------------------------------
134//
135// Trust line operations
136//
137//------------------------------------------------------------------------------
138
144[[nodiscard]] TER
146 ApplyView& view,
147 bool const bSrcHigh,
148 AccountID const& uSrcAccountID,
149 AccountID const& uDstAccountID,
150 uint256 const& uIndex, // --> ripple state entry
151 SLE::ref sleAccount, // --> the account being set.
152 bool const bAuth, // --> authorize account.
153 bool const bNoRipple, // --> others cannot ripple through
154 bool const bFreeze, // --> funds cannot leave
155 bool bDeepFreeze, // --> can neither receive nor send funds
156 STAmount const& saBalance, // --> balance of account being set.
157 // Issuer should be noAccount()
158 STAmount const& saLimit, // --> limit for account being set.
159 // Issuer should be the account being set.
160 std::uint32_t uQualityIn,
161 std::uint32_t uQualityOut,
162 SLE::ref sponsorSle,
164
165[[nodiscard]] TER
167 ApplyView& view,
168 SLE::ref sleRippleState,
169 AccountID const& uLowAccountID,
170 AccountID const& uHighAccountID,
172
173//------------------------------------------------------------------------------
174//
175// IOU issuance/redemption
176//
177//------------------------------------------------------------------------------
178
179[[nodiscard]] TER
181 ApplyView& view,
182 AccountID const& account,
183 STAmount const& amount,
184 Issue const& issue,
185 SLE::ref sponsorSle,
187
188[[nodiscard]] TER
190 ApplyView& view,
191 AccountID const& account,
192 STAmount const& amount,
193 Issue const& issue,
195
196//------------------------------------------------------------------------------
197//
198// Authorization and transfer checks (IOU-specific)
199//
200//------------------------------------------------------------------------------
201
220[[nodiscard]] TER
222 ReadView const& view,
223 Issue const& issue,
224 AccountID const& account,
225 AuthType authType = AuthType::Legacy);
226
232[[nodiscard]] TER
233canTransfer(ReadView const& view, Issue const& issue, AccountID const& from, AccountID const& to);
234
235//------------------------------------------------------------------------------
236//
237// Empty holding operations (IOU-specific)
238//
239//------------------------------------------------------------------------------
240
245[[nodiscard]] TER
247 ApplyViewContext ctx,
248 AccountID const& accountID,
249 XRPAmount priorBalance,
250 Issue const& issue,
251 beast::Journal journal);
252
253[[nodiscard]] TER
255 ApplyViewContext ctx,
256 AccountID const& accountID,
257 Issue const& issue,
258 beast::Journal journal);
259
265[[nodiscard]] TER
267 ApplyView& view,
268 SLE::pointer sleState,
269 std::optional<AccountID> const& ammAccountID,
271
276[[nodiscard]] TER
278 ApplyView& view,
279 SLE::pointer sleMPT,
280 AccountID const& ammAccountID,
282
283} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Floating point representation of amounts with high dynamic range.
Definition IOUAmount.h:26
A currency issued by an account.
Definition Issue.h:18
Currency currency
Definition Issue.h:20
AccountID account
Definition Issue.h:21
A view into a ledger.
Definition ReadView.h:41
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry > pointer
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)
bool isIndividualFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue)
Returns true if account's MPToken for mptIssue carries the individual-lock flag (lsfMPTLocked).
TER deleteAMMTrustLine(ApplyView &view, SLE::pointer sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
TER removeEmptyHolding(ApplyViewContext ctx, AccountID const &accountID, MPTIssue const &mptIssue, beast::Journal journal)
TER deleteAMMMPToken(ApplyView &view, SLE::pointer sleMPT, AccountID const &ammAccountID, beast::Journal j)
Delete AMMs MPToken.
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition UintTypes.h:42
TER addEmptyHolding(ApplyViewContext ctx, AccountID const &accountID, XRPAmount priorBalance, MPTIssue const &mptIssue, beast::Journal journal)
TER trustDelete(ApplyView &view, SLE::ref sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
TER canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to, WaiveMPTCanTransfer waive=WaiveMPTCanTransfer::No, std::uint8_t depth=0)
Check whether to may receive the given MPT from from.
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.
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, SLE::ref sponsorSle, beast::Journal j)
Create a trust line.
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
IOUAmount creditLimit2(ReadView const &v, AccountID const &acc, AccountID const &iss, Currency const &cur)
TER issueIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, SLE::ref sponsorSle, beast::Journal j)
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.
bool isFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue, std::uint8_t depth=0)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
TER redeemIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
TERSubset< CanCvtToTER > TER
Definition TER.h:647
TER requireAuth(ReadView const &view, MPTIssue const &mptIssue, AccountID const &account, AuthType authType=AuthType::Legacy, std::uint8_t depth=0)
Check if the account lacks required authorization for MPT.
@ tecFROZEN
Definition TER.h:306
BaseUInt< 256 > uint256
Definition base_uint.h:580
@ tesSUCCESS
Definition TER.h:245