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/beast/utility/instrumentation.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/ledger/View.h>
8#include <xrpl/protocol/AccountID.h>
9#include <xrpl/protocol/Feature.h>
10#include <xrpl/protocol/Indexes.h>
11#include <xrpl/protocol/LedgerFormats.h>
12#include <xrpl/protocol/SField.h>
13#include <xrpl/protocol/TER.h>
14#include <xrpl/protocol/UintTypes.h>
15
16namespace xrpl {
17
18inline TER
20 ReadView const& view,
21 AccountID const& src,
22 AccountID const& dst,
23 Currency const& currency)
24{
25 XRPL_ASSERT(src != dst, "xrpl::checkFreeze : unequal input accounts");
26
27 // check freeze
28 if (auto sle = view.read(keylet::account(dst)))
29 {
30 if (sle->isFlag(lsfGlobalFreeze))
31 {
32 return terNO_LINE;
33 }
34 }
35
36 if (auto sle = view.read(keylet::trustLine(src, dst, currency)))
37 {
38 if (sle->isFlag((dst > src) ? lsfHighFreeze : lsfLowFreeze))
39 {
40 return terNO_LINE;
41 }
42 // Unlike normal freeze, a deep frozen trust line acts the same
43 // regardless of which side froze it
44 if (sle->isFlag(lsfHighDeepFreeze) || sle->isFlag(lsfLowDeepFreeze))
45 {
46 return terNO_LINE;
47 }
48 }
49
50 if (view.rules().enabled(fixFrozenLPTokenTransfer))
51 {
52 if (auto const sleDst = view.read(keylet::account(dst));
53 sleDst && sleDst->isFieldPresent(sfAMMID))
54 {
55 auto const sleAmm = view.read(keylet::amm((*sleDst)[sfAMMID]));
56 if (!sleAmm)
57 return tecINTERNAL; // LCOV_EXCL_LINE
58
59 if (isLPTokenFrozen(view, src, (*sleAmm)[sfAsset], (*sleAmm)[sfAsset2]))
60 {
61 return terNO_LINE;
62 }
63 }
64 }
65
66 return tesSUCCESS;
67}
68
69inline TER
71 ReadView const& view,
72 AccountID const& prev,
73 AccountID const& cur,
74 // This is the account whose constraints we are checking
75 AccountID const& next,
76 Currency const& currency,
78{
79 // fetch the ripple lines into and out of this node
80 auto sleIn = view.read(keylet::trustLine(prev, cur, currency));
81 auto sleOut = view.read(keylet::trustLine(cur, next, currency));
82
83 if (!sleIn || !sleOut)
84 return terNO_LINE;
85
86 if (sleIn->isFlag((cur > prev) ? lsfHighNoRipple : lsfLowNoRipple) &&
87 sleOut->isFlag((cur > next) ? lsfHighNoRipple : lsfLowNoRipple))
88 {
89 JLOG(j.info()) << "Path violates noRipple constraint between " << prev << ", " << cur
90 << " and " << next;
91
92 return terNO_RIPPLE;
93 }
94 return tesSUCCESS;
95}
96
97} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Stream info() const
Definition Journal.h:350
A view into a ledger.
Definition ReadView.h:41
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:180
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Definition Indexes.cpp:441
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:198
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:253
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ terNO_LINE
Definition TER.h:215
@ terNO_RIPPLE
Definition TER.h:220
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition UintTypes.h:42
TER checkFreeze(ReadView const &view, AccountID const &src, AccountID const &dst, Currency const &currency)
Definition StepChecks.h:19
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
TERSubset< CanCvtToTER > TER
Definition TER.h:647
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Asset const &asset, Asset const &asset2)
Definition View.cpp:132
@ tecINTERNAL
Definition TER.h:313
TER checkNoRipple(ReadView const &view, AccountID const &prev, AccountID const &cur, AccountID const &next, Currency const &currency, beast::Journal j)
Definition StepChecks.h:70
@ tesSUCCESS
Definition TER.h:245