rippled
Loading...
Searching...
No Matches
StepChecks.h
1#ifndef XRPL_APP_PATHS_IMPL_STEP_CHECKS_H_INCLUDED
2#define XRPL_APP_PATHS_IMPL_STEP_CHECKS_H_INCLUDED
3
4#include <xrpl/basics/Log.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/ledger/View.h>
8#include <xrpl/protocol/AccountID.h>
9#include <xrpl/protocol/UintTypes.h>
10
11namespace ripple {
12
13inline TER
15 ReadView const& view,
16 AccountID const& src,
17 AccountID const& dst,
18 Currency const& currency)
19{
20 XRPL_ASSERT(src != dst, "ripple::checkFreeze : unequal input accounts");
21
22 // check freeze
23 if (auto sle = view.read(keylet::account(dst)))
24 {
25 if (sle->isFlag(lsfGlobalFreeze))
26 {
27 return terNO_LINE;
28 }
29 }
30
31 if (auto sle = view.read(keylet::line(src, dst, currency)))
32 {
33 if (sle->isFlag((dst > src) ? lsfHighFreeze : lsfLowFreeze))
34 {
35 return terNO_LINE;
36 }
37 // Unlike normal freeze, a deep frozen trust line acts the same
38 // regardless of which side froze it
39 if (sle->isFlag(lsfHighDeepFreeze) || sle->isFlag(lsfLowDeepFreeze))
40 {
41 return terNO_LINE;
42 }
43 }
44
45 if (view.rules().enabled(fixFrozenLPTokenTransfer))
46 {
47 if (auto const sleDst = view.read(keylet::account(dst));
48 sleDst && sleDst->isFieldPresent(sfAMMID))
49 {
50 auto const sleAmm = view.read(keylet::amm((*sleDst)[sfAMMID]));
51 if (!sleAmm)
52 return tecINTERNAL; // LCOV_EXCL_LINE
53
55 view,
56 src,
57 (*sleAmm)[sfAsset].get<Issue>(),
58 (*sleAmm)[sfAsset2].get<Issue>()))
59 {
60 return terNO_LINE;
61 }
62 }
63 }
64
65 return tesSUCCESS;
66}
67
68inline TER
70 ReadView const& view,
71 AccountID const& prev,
72 AccountID const& cur,
73 // This is the account whose constraints we are checking
74 AccountID const& next,
75 Currency const& currency,
77{
78 // fetch the ripple lines into and out of this node
79 auto sleIn = view.read(keylet::line(prev, cur, currency));
80 auto sleOut = view.read(keylet::line(cur, next, currency));
81
82 if (!sleIn || !sleOut)
83 return terNO_LINE;
84
85 if ((*sleIn)[sfFlags] & ((cur > prev) ? lsfHighNoRipple : lsfLowNoRipple) &&
86 (*sleOut)[sfFlags] & ((cur > next) ? lsfHighNoRipple : lsfLowNoRipple))
87 {
88 JLOG(j.info()) << "Path violates noRipple constraint between " << prev
89 << ", " << cur << " and " << next;
90
91 return terNO_RIPPLE;
92 }
93 return tesSUCCESS;
94}
95
96} // namespace ripple
97
98#endif
A generic endpoint for log messages.
Definition Journal.h:41
Stream info() const
Definition Journal.h:315
A currency issued by an account.
Definition Issue.h:14
A view into a ledger.
Definition ReadView.h:32
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
virtual Rules const & rules() const =0
Returns the tx processing rules.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:111
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Definition Indexes.cpp:427
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:225
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:6
TER checkFreeze(ReadView const &view, AccountID const &src, AccountID const &dst, Currency const &currency)
Definition StepChecks.h:14
@ lsfHighDeepFreeze
@ lsfHighNoRipple
@ lsfGlobalFreeze
@ lsfLowDeepFreeze
TER checkNoRipple(ReadView const &view, AccountID const &prev, AccountID const &cur, AccountID const &next, Currency const &currency, beast::Journal j)
Definition StepChecks.h:69
@ tecINTERNAL
Definition TER.h:292
@ tesSUCCESS
Definition TER.h:226
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
Definition View.cpp:357
@ terNO_RIPPLE
Definition TER.h:205
@ terNO_LINE
Definition TER.h:200
TERSubset< CanCvtToTER > TER
Definition TER.h:630