xrpld
Loading...
Searching...
No Matches
TokenHelpers.h
1#pragma once
2
3#include <xrpl/basics/Number.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/ledger/ApplyView.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/Asset.h>
9#include <xrpl/protocol/Issue.h>
10#include <xrpl/protocol/MPTIssue.h>
11#include <xrpl/protocol/Rate.h>
12#include <xrpl/protocol/STAmount.h>
13#include <xrpl/protocol/STLedgerEntry.h>
14#include <xrpl/protocol/TER.h>
15#include <xrpl/protocol/UintTypes.h>
16#include <xrpl/protocol/XRPAmount.h>
17
18#include <cstdint>
19#include <initializer_list>
20#include <utility>
21#include <vector>
22
23namespace xrpl {
24
25//------------------------------------------------------------------------------
26//
27// Enums for token handling
28//
29//------------------------------------------------------------------------------
30
35
40
45
46enum class WaiveTransferFee : bool { No = false, Yes };
47
51enum class AllowMPTOverflow : bool { No = false, Yes };
52
61enum class WaiveMPTCanTransfer : bool { No = false, Yes };
62
63/* Check if MPToken (for MPT) or trust line (for IOU) exists:
64 * - StrongAuth - before checking if authorization is required
65 * - WeakAuth
66 * for MPT - after checking lsfMPTRequireAuth flag
67 * for IOU - do not check if trust line exists
68 * - Legacy
69 * for MPT - before checking lsfMPTRequireAuth flag i.e. same as StrongAuth
70 * for IOU - do not check if trust line exists i.e. same as WeakAuth
71 */
73
74//------------------------------------------------------------------------------
75//
76// Freeze checking (Asset-based dispatchers)
77//
78//------------------------------------------------------------------------------
79
80[[nodiscard]] bool
81isGlobalFrozen(ReadView const& view, Asset const& asset);
82
83[[nodiscard]] TER
84checkGlobalFrozen(ReadView const& view, Asset const& asset);
85
86[[nodiscard]] bool
87isIndividualFrozen(ReadView const& view, AccountID const& account, Asset const& asset);
88
89[[nodiscard]] TER
90checkIndividualFrozen(ReadView const& view, AccountID const& account, Asset const& asset);
91
97[[nodiscard]] bool
99 ReadView const& view,
100 AccountID const& account,
101 Asset const& asset,
102 std::uint8_t depth = 0);
103
104[[nodiscard]] TER
105checkFrozen(ReadView const& view, AccountID const& account, Issue const& issue);
106
107[[nodiscard]] TER
108checkFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue);
109
110[[nodiscard]] TER
111checkFrozen(ReadView const& view, AccountID const& account, Asset const& asset);
112
113[[nodiscard]] bool
115 ReadView const& view,
116 std::initializer_list<AccountID> const& accounts,
117 Issue const& issue);
118
119[[nodiscard]] bool
121 ReadView const& view,
122 std::initializer_list<AccountID> const& accounts,
123 Asset const& asset,
124 std::uint8_t depth = 0);
125
126[[nodiscard]] bool
128 ReadView const& view,
129 AccountID const& account,
130 MPTIssue const& mptIssue,
131 std::uint8_t depth = 0);
132
138[[nodiscard]] bool
140 ReadView const& view,
141 AccountID const& account,
142 Asset const& asset,
143 std::uint8_t depth = 0);
144
145[[nodiscard]] TER
146checkDeepFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue);
147
148[[nodiscard]] TER
149checkDeepFrozen(ReadView const& view, AccountID const& account, Asset const& asset);
150
182[[nodiscard]] TER
184 ReadView const& view,
185 AccountID const& pseudoAcct,
186 AccountID const& submitterAcct,
187 AccountID const& dstAcct,
188 Asset const& asset);
189
209[[nodiscard]] TER
211 ReadView const& view,
212 AccountID const& srcAcct,
213 AccountID const& pseudoAcct,
214 Asset const& asset);
215
216//------------------------------------------------------------------------------
217//
218// Account balance functions (Asset-based dispatchers)
219//
220//------------------------------------------------------------------------------
221
222// Returns the amount an account can spend.
223//
224// If shSIMPLE_BALANCE is specified, this is the amount the account can spend
225// without going into debt.
226//
227// If shFULL_BALANCE is specified, this is the amount the account can spend
228// total. Specifically:
229// * The account can go into debt if using a trust line, and the other side has
230// a non-zero limit.
231// * If the account is the asset issuer the limit is defined by the asset /
232// issuance.
233//
234// <-- saAmount: amount of currency held by account. May be negative.
235[[nodiscard]] STAmount
237 ReadView const& view,
238 AccountID const& account,
239 Currency const& currency,
240 AccountID const& issuer,
241 FreezeHandling zeroIfFrozen,
244
245[[nodiscard]] STAmount
247 ReadView const& view,
248 AccountID const& account,
249 Issue const& issue,
250 FreezeHandling zeroIfFrozen,
253
254[[nodiscard]] STAmount
256 ReadView const& view,
257 AccountID const& account,
258 MPTIssue const& mptIssue,
259 FreezeHandling zeroIfFrozen,
260 AuthHandling zeroIfUnauthorized,
263
264[[nodiscard]] STAmount
266 ReadView const& view,
267 AccountID const& account,
268 Asset const& asset,
269 FreezeHandling zeroIfFrozen,
270 AuthHandling zeroIfUnauthorized,
273
274// Returns the amount an account can spend of the currency type saDefault, or
275// returns saDefault if this account is the issuer of the currency in
276// question. Should be used in favor of accountHolds when questioning how much
277// an account can spend while also allowing currency issuers to spend
278// unlimited amounts of their own currency (since they can always issue more).
279[[nodiscard]] STAmount
281 ReadView const& view,
282 AccountID const& id,
283 STAmount const& saDefault,
284 FreezeHandling freezeHandling,
286
287// Overload with AuthHandling to support IOU and MPT.
288[[nodiscard]] STAmount
290 ReadView const& view,
291 AccountID const& id,
292 STAmount const& saDefault,
293 FreezeHandling freezeHandling,
294 AuthHandling authHandling,
296
302[[nodiscard]] Rate
303transferRate(ReadView const& view, STAmount const& amount);
304
305//------------------------------------------------------------------------------
306//
307// Holding operations (Asset-based dispatchers)
308//
309//------------------------------------------------------------------------------
310
311[[nodiscard]] TER
312canAddHolding(ReadView const& view, Asset const& asset);
313
314[[nodiscard]] TER
316 ApplyViewContext ctx,
317 AccountID const& accountID,
318 XRPAmount priorBalance,
319 Asset const& asset,
320 beast::Journal journal);
321
322[[nodiscard]] TER
324 ApplyViewContext ctx,
325 AccountID const& accountID,
326 Asset const& asset,
327 beast::Journal journal);
328
329//------------------------------------------------------------------------------
330//
331// Authorization and transfer checks (Asset-based dispatchers)
332//
333//------------------------------------------------------------------------------
334
335[[nodiscard]] TER
337 ReadView const& view,
338 Asset const& asset,
339 AccountID const& account,
340 AuthType authType = AuthType::Legacy);
341
342[[nodiscard]] TER
344 ReadView const& view,
345 Asset const& asset,
346 AccountID const& from,
347 AccountID const& to,
349 std::uint8_t depth = 0);
350
351//------------------------------------------------------------------------------
352//
353// Money Transfers (Asset-based dispatchers)
354//
355//------------------------------------------------------------------------------
356
357// Direct send w/o fees:
358// - Redeeming IOUs and/or sending sender's own IOUs.
359// - Create trust line of needed.
360// --> bCheckIssuer : normally require issuer to be involved.
361// [[nodiscard]] // nodiscard commented out so DirectStep.cpp compiles.
362
367TER
369 ApplyView& view,
370 AccountID const& uSenderID,
371 AccountID const& uReceiverID,
372 STAmount const& saAmount,
373 bool bCheckIssuer,
375
380[[nodiscard]] TER
382 ApplyView& view,
383 AccountID const& from,
384 AccountID const& to,
385 STAmount const& saAmount,
387 SLE::ref sponsorSle = {},
389 AllowMPTOverflow allowOverflow = AllowMPTOverflow::No);
390
399[[nodiscard]] TER
401 ApplyView& view,
402 AccountID const& senderID,
403 Asset const& asset,
404 MultiplePaymentDestinations const& receivers,
407
408[[nodiscard]] TER
410 ApplyView& view,
411 AccountID const& from,
412 AccountID const& to,
413 STAmount const& amount,
415
416} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:134
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)
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)
Returns true if account's MPToken for mptIssue carries the individual-lock flag (lsfMPTLocked).
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, SLE::ref sponsorSle={}, WaiveTransferFee waiveFee=WaiveTransferFee::No, AllowMPTOverflow allowOverflow=AllowMPTOverflow::No)
Calls static accountSendIOU if saAmount represents Issue.
TER checkDepositFreeze(ReadView const &view, AccountID const &srcAcct, AccountID const &pseudoAcct, Asset const &asset)
Checks freeze compliance for depositing an asset into a pseudo-account (e.g.
AllowMPTOverflow
Controls whether accountSend is allowed to overflow OutstandingAmount *.
TER removeEmptyHolding(ApplyViewContext ctx, AccountID const &accountID, 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:42
TER addEmptyHolding(ApplyViewContext ctx, AccountID const &accountID, XRPAmount priorBalance, MPTIssue const &mptIssue, beast::Journal journal)
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)
@ Yes
We have consensus along with the network.
@ No
We do not have consensus.
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 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 checkGlobalFrozen(ReadView const &view, Asset const &asset)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
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: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.
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 checkWithdrawFreeze(ReadView const &view, AccountID const &pseudoAcct, AccountID const &submitterAcct, AccountID const &dstAcct, Asset const &asset)
Checks freeze compliance for withdrawing an asset from a pseudo-account (e.g.
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j, SpendableHandling includeFullBalance=SpendableHandling::SimpleBalance)