rippled
Loading...
Searching...
No Matches
TokenHelpers.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/protocol/Asset.h>
7#include <xrpl/protocol/MPTIssue.h>
8#include <xrpl/protocol/Rate.h>
9#include <xrpl/protocol/STAmount.h>
10#include <xrpl/protocol/TER.h>
11
12#include <initializer_list>
13#include <vector>
14
15namespace xrpl {
16
17//------------------------------------------------------------------------------
18//
19// Enums for token handling
20//
21//------------------------------------------------------------------------------
22
25
28
31
32enum class WaiveTransferFee : bool { No = false, Yes };
33
34/* Check if MPToken (for MPT) or trust line (for IOU) exists:
35 * - StrongAuth - before checking if authorization is required
36 * - WeakAuth
37 * for MPT - after checking lsfMPTRequireAuth flag
38 * for IOU - do not check if trust line exists
39 * - Legacy
40 * for MPT - before checking lsfMPTRequireAuth flag i.e. same as StrongAuth
41 * for IOU - do not check if trust line exists i.e. same as WeakAuth
42 */
44
45//------------------------------------------------------------------------------
46//
47// Freeze checking (Asset-based dispatchers)
48//
49//------------------------------------------------------------------------------
50
51[[nodiscard]] bool
52isGlobalFrozen(ReadView const& view, Asset const& asset);
53
54[[nodiscard]] bool
55isIndividualFrozen(ReadView const& view, AccountID const& account, Asset const& asset);
56
62[[nodiscard]] bool
63isFrozen(ReadView const& view, AccountID const& account, Asset const& asset, int depth = 0);
64
65[[nodiscard]] TER
66checkFrozen(ReadView const& view, AccountID const& account, Issue const& issue);
67
68[[nodiscard]] TER
69checkFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue);
70
71[[nodiscard]] TER
72checkFrozen(ReadView const& view, AccountID const& account, Asset const& asset);
73
74[[nodiscard]] bool
76 ReadView const& view,
78 Issue const& issue);
79
80[[nodiscard]] bool
82 ReadView const& view,
84 Asset const& asset,
85 int depth = 0);
86
87[[nodiscard]] bool
89 ReadView const& view,
90 AccountID const& account,
91 MPTIssue const& mptIssue,
92 int depth = 0);
93
99[[nodiscard]] bool
100isDeepFrozen(ReadView const& view, AccountID const& account, Asset const& asset, int depth = 0);
101
102[[nodiscard]] TER
103checkDeepFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue);
104
105[[nodiscard]] TER
106checkDeepFrozen(ReadView const& view, AccountID const& account, Asset const& asset);
107
108//------------------------------------------------------------------------------
109//
110// Account balance functions (Asset-based dispatchers)
111//
112//------------------------------------------------------------------------------
113
114// Returns the amount an account can spend.
115//
116// If shSIMPLE_BALANCE is specified, this is the amount the account can spend
117// without going into debt.
118//
119// If shFULL_BALANCE is specified, this is the amount the account can spend
120// total. Specifically:
121// * The account can go into debt if using a trust line, and the other side has
122// a non-zero limit.
123// * If the account is the asset issuer the limit is defined by the asset /
124// issuance.
125//
126// <-- saAmount: amount of currency held by account. May be negative.
127[[nodiscard]] STAmount
129 ReadView const& view,
130 AccountID const& account,
131 Currency const& currency,
132 AccountID const& issuer,
133 FreezeHandling zeroIfFrozen,
135 SpendableHandling includeFullBalance = shSIMPLE_BALANCE);
136
137[[nodiscard]] STAmount
139 ReadView const& view,
140 AccountID const& account,
141 Issue const& issue,
142 FreezeHandling zeroIfFrozen,
144 SpendableHandling includeFullBalance = shSIMPLE_BALANCE);
145
146[[nodiscard]] STAmount
148 ReadView const& view,
149 AccountID const& account,
150 MPTIssue const& mptIssue,
151 FreezeHandling zeroIfFrozen,
152 AuthHandling zeroIfUnauthorized,
154 SpendableHandling includeFullBalance = shSIMPLE_BALANCE);
155
156[[nodiscard]] STAmount
158 ReadView const& view,
159 AccountID const& account,
160 Asset const& asset,
161 FreezeHandling zeroIfFrozen,
162 AuthHandling zeroIfUnauthorized,
164 SpendableHandling includeFullBalance = shSIMPLE_BALANCE);
165
166// Returns the amount an account can spend of the currency type saDefault, or
167// returns saDefault if this account is the issuer of the currency in
168// question. Should be used in favor of accountHolds when questioning how much
169// an account can spend while also allowing currency issuers to spend
170// unlimited amounts of their own currency (since they can always issue more).
171[[nodiscard]] STAmount
173 ReadView const& view,
174 AccountID const& id,
175 STAmount const& saDefault,
176 FreezeHandling freezeHandling,
178
183[[nodiscard]] Rate
184transferRate(ReadView const& view, STAmount const& amount);
185
186//------------------------------------------------------------------------------
187//
188// Holding operations (Asset-based dispatchers)
189//
190//------------------------------------------------------------------------------
191
192[[nodiscard]] TER
193canAddHolding(ReadView const& view, Asset const& asset);
194
195[[nodiscard]] TER
197 ApplyView& view,
198 AccountID const& accountID,
199 XRPAmount priorBalance,
200 Asset const& asset,
201 beast::Journal journal);
202
203[[nodiscard]] TER
205 ApplyView& view,
206 AccountID const& accountID,
207 Asset const& asset,
208 beast::Journal journal);
209
210//------------------------------------------------------------------------------
211//
212// Authorization and transfer checks (Asset-based dispatchers)
213//
214//------------------------------------------------------------------------------
215
216[[nodiscard]] TER
218 ReadView const& view,
219 Asset const& asset,
220 AccountID const& account,
221 AuthType authType = AuthType::Legacy);
222
223[[nodiscard]] TER
224canTransfer(ReadView const& view, Asset const& asset, AccountID const& from, AccountID const& to);
225
226//------------------------------------------------------------------------------
227//
228// Money Transfers (Asset-based dispatchers)
229//
230//------------------------------------------------------------------------------
231
232// Direct send w/o fees:
233// - Redeeming IOUs and/or sending sender's own IOUs.
234// - Create trust line of needed.
235// --> bCheckIssuer : normally require issuer to be involved.
236// [[nodiscard]] // nodiscard commented out so DirectStep.cpp compiles.
237
241TER
243 ApplyView& view,
244 AccountID const& uSenderID,
245 AccountID const& uReceiverID,
246 STAmount const& saAmount,
247 bool bCheckIssuer,
249
253[[nodiscard]] TER
255 ApplyView& view,
256 AccountID const& from,
257 AccountID const& to,
258 STAmount const& saAmount,
261
269[[nodiscard]] TER
271 ApplyView& view,
272 AccountID const& senderID,
273 Asset const& asset,
274 MultiplePaymentDestinations const& receivers,
277
278[[nodiscard]] TER
280 ApplyView& view,
281 AccountID const& from,
282 AccountID const& to,
283 STAmount const& amount,
285
286} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:116
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
FreezeHandling
Controls the treatment of frozen account balances.
@ fhZERO_IF_FROZEN
@ fhIGNORE_FREEZE
SpendableHandling
Controls whether to include the account's full spendable balance.
@ shSIMPLE_BALANCE
@ shFULL_BALANCE
bool isIndividualFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue)
TER addEmptyHolding(ApplyView &view, AccountID const &accountID, XRPAmount priorBalance, MPTIssue const &mptIssue, beast::Journal journal)
TER checkFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
bool isAnyFrozen(ReadView const &view, std::initializer_list< AccountID > const &accounts, MPTIssue const &mptIssue, int depth=0)
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j, SpendableHandling includeFullBalance=shSIMPLE_BALANCE)
WaiveTransferFee
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Calls static accountSendIOU if saAmount represents Issue.
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
Check if the issuer has the global freeze flag set.
bool isFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue, int depth=0)
TERSubset< CanCvtToTER > TER
Definition TER.h:622
TER canAddHolding(ReadView const &view, MPTIssue const &mptIssue)
AuthHandling
Controls the treatment of unauthorized MPT balances.
@ ahIGNORE_AUTH
@ ahZERO_IF_UNAUTHORIZED
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
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 transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
TER accountSendMulti(ApplyView &view, AccountID const &senderID, Asset const &asset, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Like accountSend, except one account is sending multiple payments (with the same asset!...
TER removeEmptyHolding(ApplyView &view, AccountID const &accountID, MPTIssue const &mptIssue, beast::Journal journal)
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.
TER rippleCredit(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
Calls static rippleCreditIOU if saAmount represents Issue.