xrpld
Loading...
Searching...
No Matches
StepChecks.h
1#pragma once
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/ledger/ReadView.h>
6#include <xrpl/ledger/View.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/UintTypes.h>
9
10namespace xrpl {
11
12inline TER
14 ReadView const& view,
15 AccountID const& src,
16 AccountID const& dst,
17 Currency const& currency)
18{
19 XRPL_ASSERT(src != dst, "xrpl::checkFreeze : unequal input accounts");
20
21 // check freeze
22 if (auto sle = view.read(keylet::account(dst)))
23 {
24 if (sle->isFlag(lsfGlobalFreeze))
25 {
26 return terNO_LINE;
27 }
28 }
29
30 if (auto sle = view.read(keylet::trustLine(src, dst, currency)))
31 {
32 if (sle->isFlag((dst > src) ? lsfHighFreeze : lsfLowFreeze))
33 {
34 return terNO_LINE;
35 }
36 // Unlike normal freeze, a deep frozen trust line acts the same
37 // regardless of which side froze it
38 if (sle->isFlag(lsfHighDeepFreeze) || sle->isFlag(lsfLowDeepFreeze))
39 {
40 return terNO_LINE;
41 }
42 }
43
44 if (view.rules().enabled(fixFrozenLPTokenTransfer))
45 {
46 if (auto const sleDst = view.read(keylet::account(dst));
47 sleDst && sleDst->isFieldPresent(sfAMMID))
48 {
49 auto const sleAmm = view.read(keylet::amm((*sleDst)[sfAMMID]));
50 if (!sleAmm)
51 return tecINTERNAL; // LCOV_EXCL_LINE
52
53 if (isLPTokenFrozen(view, src, (*sleAmm)[sfAsset], (*sleAmm)[sfAsset2]))
54 {
55 return terNO_LINE;
56 }
57 }
58 }
59
60 return tesSUCCESS;
61}
62
63inline TER
65 ReadView const& view,
66 AccountID const& prev,
67 AccountID const& cur,
68 // This is the account whose constraints we are checking
69 AccountID const& next,
70 Currency const& currency,
72{
73 // fetch the ripple lines into and out of this node
74 auto sleIn = view.read(keylet::trustLine(prev, cur, currency));
75 auto sleOut = view.read(keylet::trustLine(cur, next, currency));
76
77 if (!sleIn || !sleOut)
78 return terNO_LINE;
79
80 if (sleIn->isFlag((cur > prev) ? lsfHighNoRipple : lsfLowNoRipple) &&
81 sleOut->isFlag((cur > next) ? lsfHighNoRipple : lsfLowNoRipple))
82 {
83 JLOG(j.info()) << "Path violates noRipple constraint between " << prev << ", " << cur
84 << " and " << next;
85
86 return terNO_RIPPLE;
87 }
88 return tesSUCCESS;
89}
90
91} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
Stream info() const
Definition Journal.h:303
A view into a ledger.
Definition ReadView.h:31
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:171
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Definition Indexes.cpp:425
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:186
Keylet trustLine(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition Indexes.cpp:241
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ terNO_LINE
Definition TER.h:211
@ terNO_RIPPLE
Definition TER.h:216
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition UintTypes.h:36
TER checkFreeze(ReadView const &view, AccountID const &src, AccountID const &dst, Currency const &currency)
Definition StepChecks.h:13
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
TERSubset< CanCvtToTER > TER
Definition TER.h:634
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Asset const &asset, Asset const &asset2)
Definition View.cpp:123
@ tecINTERNAL
Definition TER.h:308
TER checkNoRipple(ReadView const &view, AccountID const &prev, AccountID const &cur, AccountID const &next, Currency const &currency, beast::Journal j)
Definition StepChecks.h:64
@ tesSUCCESS
Definition TER.h:240