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
13checkFreeze(ReadView const& view, AccountID const& src, AccountID const& dst, Currency const& currency)
14{
15 XRPL_ASSERT(src != dst, "xrpl::checkFreeze : unequal input accounts");
16
17 // check freeze
18 if (auto sle = view.read(keylet::account(dst)))
19 {
20 if (sle->isFlag(lsfGlobalFreeze))
21 {
22 return terNO_LINE;
23 }
24 }
25
26 if (auto sle = view.read(keylet::line(src, dst, currency)))
27 {
28 if (sle->isFlag((dst > src) ? lsfHighFreeze : lsfLowFreeze))
29 {
30 return terNO_LINE;
31 }
32 // Unlike normal freeze, a deep frozen trust line acts the same
33 // regardless of which side froze it
34 if (sle->isFlag(lsfHighDeepFreeze) || sle->isFlag(lsfLowDeepFreeze))
35 {
36 return terNO_LINE;
37 }
38 }
39
40 if (view.rules().enabled(fixFrozenLPTokenTransfer))
41 {
42 if (auto const sleDst = view.read(keylet::account(dst)); sleDst && sleDst->isFieldPresent(sfAMMID))
43 {
44 auto const sleAmm = view.read(keylet::amm((*sleDst)[sfAMMID]));
45 if (!sleAmm)
46 return tecINTERNAL; // LCOV_EXCL_LINE
47
48 if (isLPTokenFrozen(view, src, (*sleAmm)[sfAsset].get<Issue>(), (*sleAmm)[sfAsset2].get<Issue>()))
49 {
50 return terNO_LINE;
51 }
52 }
53 }
54
55 return tesSUCCESS;
56}
57
58inline TER
60 ReadView const& view,
61 AccountID const& prev,
62 AccountID const& cur,
63 // This is the account whose constraints we are checking
64 AccountID const& next,
65 Currency const& currency,
67{
68 // fetch the ripple lines into and out of this node
69 auto sleIn = view.read(keylet::line(prev, cur, currency));
70 auto sleOut = view.read(keylet::line(cur, next, currency));
71
72 if (!sleIn || !sleOut)
73 return terNO_LINE;
74
75 if ((*sleIn)[sfFlags] & ((cur > prev) ? lsfHighNoRipple : lsfLowNoRipple) &&
76 (*sleOut)[sfFlags] & ((cur > next) ? lsfHighNoRipple : lsfLowNoRipple))
77 {
78 JLOG(j.info()) << "Path violates noRipple constraint between " << prev << ", " << cur << " and " << next;
79
80 return terNO_RIPPLE;
81 }
82 return tesSUCCESS;
83}
84
85} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
Stream info() const
Definition Journal.h:306
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:118
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Definition Indexes.cpp:393
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:214
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:160
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:620
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:59
@ lsfLowDeepFreeze
@ lsfLowNoRipple
@ lsfGlobalFreeze
@ lsfLowFreeze
@ lsfHighFreeze
@ lsfHighNoRipple
@ lsfHighDeepFreeze
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
Definition View.cpp:299
@ tesSUCCESS
Definition TER.h:225