rippled
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::line(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
54 view, src, (*sleAmm)[sfAsset].get<Issue>(), (*sleAmm)[sfAsset2].get<Issue>()))
55 {
56 return terNO_LINE;
57 }
58 }
59 }
60
61 return tesSUCCESS;
62}
63
64inline TER
66 ReadView const& view,
67 AccountID const& prev,
68 AccountID const& cur,
69 // This is the account whose constraints we are checking
70 AccountID const& next,
71 Currency const& currency,
73{
74 // fetch the ripple lines into and out of this node
75 auto sleIn = view.read(keylet::line(prev, cur, currency));
76 auto sleOut = view.read(keylet::line(cur, next, currency));
77
78 if (!sleIn || !sleOut)
79 return terNO_LINE;
80
81 if ((*sleIn)[sfFlags] & ((cur > prev) ? lsfHighNoRipple : lsfLowNoRipple) &&
82 (*sleOut)[sfFlags] & ((cur > next) ? lsfHighNoRipple : lsfLowNoRipple))
83 {
84 JLOG(j.info()) << "Path violates noRipple constraint between " << prev << ", " << cur
85 << " and " << next;
86
87 return terNO_RIPPLE;
88 }
89 return tesSUCCESS;
90}
91
92} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
Stream info() const
Definition Journal.h:307
A currency issued by an account.
Definition Issue.h:13
A view into a ledger.
Definition ReadView.h:31
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual std::shared_ptr< SLE const > 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:120
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Definition Indexes.cpp:404
Keylet line(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition Indexes.cpp:220
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:165
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ terNO_LINE
Definition TER.h:199
@ terNO_RIPPLE
Definition TER.h:204
TERSubset< CanCvtToTER > TER
Definition TER.h:622
TER checkFreeze(ReadView const &view, AccountID const &src, AccountID const &dst, Currency const &currency)
Definition StepChecks.h:13
@ tecINTERNAL
Definition TER.h:291
TER checkNoRipple(ReadView const &view, AccountID const &prev, AccountID const &cur, AccountID const &next, Currency const &currency, beast::Journal j)
Definition StepChecks.h:65
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
Definition View.cpp:84
@ tesSUCCESS
Definition TER.h:225