xrpld
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
35enum class AllowMPTOverflow : bool { No = false, Yes };
36
44enum class WaiveMPTCanTransfer : bool { No = false, Yes };
45
46/* Check if MPToken (for MPT) or trust line (for IOU) exists:
47 * - StrongAuth - before checking if authorization is required
48 * - WeakAuth
49 * for MPT - after checking lsfMPTRequireAuth flag
50 * for IOU - do not check if trust line exists
51 * - Legacy
52 * for MPT - before checking lsfMPTRequireAuth flag i.e. same as StrongAuth
53 * for IOU - do not check if trust line exists i.e. same as WeakAuth
54 */
56
57//------------------------------------------------------------------------------
58//
59// Freeze checking (Asset-based dispatchers)
60//
61//------------------------------------------------------------------------------
62
63[[nodiscard]] bool
64isGlobalFrozen(ReadView const& view, Asset const& asset);
65
66[[nodiscard]] TER
67checkGlobalFrozen(ReadView const& view, Asset const& asset);
68
69[[nodiscard]] bool
70isIndividualFrozen(ReadView const& view, AccountID const& account, Asset const& asset);
71
72[[nodiscard]] TER
73checkIndividualFrozen(ReadView const& view, AccountID const& account, Asset const& asset);
74
80[[nodiscard]] bool
82 ReadView const& view,
83 AccountID const& account,
84 Asset const& asset,
85 std::uint8_t depth = 0);
86
87[[nodiscard]] TER
88checkFrozen(ReadView const& view, AccountID const& account, Issue const& issue);
89
90[[nodiscard]] TER
91checkFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue);
92
93[[nodiscard]] TER
94checkFrozen(ReadView const& view, AccountID const& account, Asset const& asset);
95
96[[nodiscard]] bool
98 ReadView const& view,
100 Issue const& issue);
101
102[[nodiscard]] bool
104 ReadView const& view,
105 std::initializer_list<AccountID> const& accounts,
106 Asset const& asset,
107 std::uint8_t depth = 0);
108
109[[nodiscard]] bool
111 ReadView const& view,
112 AccountID const& account,
113 MPTIssue const& mptIssue,
114 std::uint8_t depth = 0);
115
121[[nodiscard]] bool
123 ReadView const& view,
124 AccountID const& account,
125 Asset const& asset,
126 std::uint8_t depth = 0);
127
128[[nodiscard]] TER
129checkDeepFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue);
130
131[[nodiscard]] TER
132checkDeepFrozen(ReadView const& view, AccountID const& account, Asset const& asset);
133
166[[nodiscard]] TER
168 ReadView const& view,
169 AccountID const& srcAcct,
170 AccountID const& submitterAcct,
171 AccountID const& dstAcct,
172 Asset const& asset);
173
196[[nodiscard]] TER
198 ReadView const& view,
199 AccountID const& srcAcct,
200 AccountID const& dstAcct,
201 Asset const& asset);
202
203//------------------------------------------------------------------------------
204//
205// Account balance functions (Asset-based dispatchers)
206//
207//------------------------------------------------------------------------------
208
209// Returns the amount an account can spend.
210//
211// If shSIMPLE_BALANCE is specified, this is the amount the account can spend
212// without going into debt.
213//
214// If shFULL_BALANCE is specified, this is the amount the account can spend
215// total. Specifically:
216// * The account can go into debt if using a trust line, and the other side has
217// a non-zero limit.
218// * If the account is the asset issuer the limit is defined by the asset /
219// issuance.
220//
221// <-- saAmount: amount of currency held by account. May be negative.
222[[nodiscard]] STAmount
224 ReadView const& view,
225 AccountID const& account,
226 Currency const& currency,
227 AccountID const& issuer,
228 FreezeHandling zeroIfFrozen,
231
232[[nodiscard]] STAmount
234 ReadView const& view,
235 AccountID const& account,
236 Issue const& issue,
237 FreezeHandling zeroIfFrozen,
240
241[[nodiscard]] STAmount
243 ReadView const& view,
244 AccountID const& account,
245 MPTIssue const& mptIssue,
246 FreezeHandling zeroIfFrozen,
247 AuthHandling zeroIfUnauthorized,
250
251[[nodiscard]] STAmount
253 ReadView const& view,
254 AccountID const& account,
255 Asset const& asset,
256 FreezeHandling zeroIfFrozen,
257 AuthHandling zeroIfUnauthorized,
260
261// Returns the amount an account can spend of the currency type saDefault, or
262// returns saDefault if this account is the issuer of the currency in
263// question. Should be used in favor of accountHolds when questioning how much
264// an account can spend while also allowing currency issuers to spend
265// unlimited amounts of their own currency (since they can always issue more).
266[[nodiscard]] STAmount
268 ReadView const& view,
269 AccountID const& id,
270 STAmount const& saDefault,
271 FreezeHandling freezeHandling,
273
274// Overload with AuthHandling to support IOU and MPT.
275[[nodiscard]] STAmount
277 ReadView const& view,
278 AccountID const& id,
279 STAmount const& saDefault,
280 FreezeHandling freezeHandling,
281 AuthHandling authHandling,
283
288[[nodiscard]] Rate
289transferRate(ReadView const& view, STAmount const& amount);
290
291//------------------------------------------------------------------------------
292//
293// Holding operations (Asset-based dispatchers)
294//
295//------------------------------------------------------------------------------
296
297[[nodiscard]] TER
298canAddHolding(ReadView const& view, Asset const& asset);
299
300[[nodiscard]] TER
302 ApplyView& view,
303 AccountID const& accountID,
304 XRPAmount priorBalance,
305 Asset const& asset,
306 beast::Journal journal);
307
308[[nodiscard]] TER
310 ApplyView& view,
311 AccountID const& accountID,
312 Asset const& asset,
313 beast::Journal journal);
314
315//------------------------------------------------------------------------------
316//
317// Authorization and transfer checks (Asset-based dispatchers)
318//
319//------------------------------------------------------------------------------
320
321[[nodiscard]] TER
323 ReadView const& view,
324 Asset const& asset,
325 AccountID const& account,
326 AuthType authType = AuthType::Legacy);
327
328[[nodiscard]] TER
330 ReadView const& view,
331 Asset const& asset,
332 AccountID const& from,
333 AccountID const& to,
335 std::uint8_t depth = 0);
336
337//------------------------------------------------------------------------------
338//
339// Money Transfers (Asset-based dispatchers)
340//
341//------------------------------------------------------------------------------
342
343// Direct send w/o fees:
344// - Redeeming IOUs and/or sending sender's own IOUs.
345// - Create trust line of needed.
346// --> bCheckIssuer : normally require issuer to be involved.
347// [[nodiscard]] // nodiscard commented out so DirectStep.cpp compiles.
348
352TER
354 ApplyView& view,
355 AccountID const& uSenderID,
356 AccountID const& uReceiverID,
357 STAmount const& saAmount,
358 bool bCheckIssuer,
360
364[[nodiscard]] TER
366 ApplyView& view,
367 AccountID const& from,
368 AccountID const& to,
369 STAmount const& saAmount,
372 AllowMPTOverflow allowOverflow = AllowMPTOverflow::No);
373
381[[nodiscard]] TER
383 ApplyView& view,
384 AccountID const& senderID,
385 Asset const& asset,
386 MultiplePaymentDestinations const& receivers,
389
390[[nodiscard]] TER
392 ApplyView& view,
393 AccountID const& from,
394 AccountID const& to,
395 STAmount const& amount,
397
398} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:118
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)
FreezeHandling
Controls the treatment of frozen account balances.
SpendableHandling
Controls whether to include the account's full spendable balance.
TER checkIndividualFrozen(ReadView const &view, AccountID const &account, Asset const &asset)
bool isIndividualFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue)
AllowMPTOverflow
Controls whether accountSend is allowed to overflow OutstandingAmount.
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)
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition UintTypes.h:36
WaiveTransferFee
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.
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
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.
TER canAddHolding(ReadView const &view, MPTIssue const &mptIssue)
AuthHandling
Controls the treatment of unauthorized MPT balances.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
TER checkWithdrawFreeze(ReadView const &view, AccountID const &srcAcct, AccountID const &submitterAcct, AccountID const &dstAcct, Asset const &asset)
Checks freeze compliance for withdrawing an asset from a pseudo-account (e.g.
TER directSendNoFee(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
Calls static directSendNoFeeIOU if saAmount represents Issue.
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
WaiveMPTCanTransfer
Controls whether canTransfer enforces lsfMPTCanTransfer on MPTs.
bool isFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue, std::uint8_t depth=0)
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No, AllowMPTOverflow allowOverflow=AllowMPTOverflow::No)
Calls static accountSendIOU if saAmount represents Issue.
TER checkGlobalFrozen(ReadView const &view, Asset const &asset)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
TER checkDepositFreeze(ReadView const &view, AccountID const &srcAcct, AccountID const &dstAcct, Asset const &asset)
Checks freeze compliance for depositing an asset into a pseudo-account (e.g.
bool isAnyFrozen(ReadView const &view, std::initializer_list< AccountID > const &accounts, MPTIssue const &mptIssue, std::uint8_t depth=0)
TERSubset< CanCvtToTER > TER
Definition TER.h:634
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.
std::vector< std::pair< AccountID, Number > > MultiplePaymentDestinations
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)
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j, SpendableHandling includeFullBalance=SpendableHandling::SimpleBalance)