rippled
Loading...
Searching...
No Matches
StepChecks.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2015 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_PATHS_IMPL_STEP_CHECKS_H_INCLUDED
21#define RIPPLE_APP_PATHS_IMPL_STEP_CHECKS_H_INCLUDED
22
23#include <xrpl/basics/Log.h>
24#include <xrpl/beast/utility/Journal.h>
25#include <xrpl/ledger/ReadView.h>
26#include <xrpl/ledger/View.h>
27#include <xrpl/protocol/AccountID.h>
28#include <xrpl/protocol/UintTypes.h>
29
30namespace ripple {
31
32inline TER
34 ReadView const& view,
35 AccountID const& src,
36 AccountID const& dst,
37 Currency const& currency)
38{
39 XRPL_ASSERT(src != dst, "ripple::checkFreeze : unequal input accounts");
40
41 // check freeze
42 if (auto sle = view.read(keylet::account(dst)))
43 {
44 if (sle->isFlag(lsfGlobalFreeze))
45 {
46 return terNO_LINE;
47 }
48 }
49
50 if (auto sle = view.read(keylet::line(src, dst, currency)))
51 {
52 if (sle->isFlag((dst > src) ? lsfHighFreeze : lsfLowFreeze))
53 {
54 return terNO_LINE;
55 }
56 // Unlike normal freeze, a deep frozen trust line acts the same
57 // regardless of which side froze it
58 if (sle->isFlag(lsfHighDeepFreeze) || sle->isFlag(lsfLowDeepFreeze))
59 {
60 return terNO_LINE;
61 }
62 }
63
64 if (view.rules().enabled(fixFrozenLPTokenTransfer))
65 {
66 if (auto const sleDst = view.read(keylet::account(dst));
67 sleDst && sleDst->isFieldPresent(sfAMMID))
68 {
69 auto const sleAmm = view.read(keylet::amm((*sleDst)[sfAMMID]));
70 if (!sleAmm)
71 return tecINTERNAL; // LCOV_EXCL_LINE
72
74 view,
75 src,
76 (*sleAmm)[sfAsset].get<Issue>(),
77 (*sleAmm)[sfAsset2].get<Issue>()))
78 {
79 return terNO_LINE;
80 }
81 }
82 }
83
84 return tesSUCCESS;
85}
86
87inline TER
89 ReadView const& view,
90 AccountID const& prev,
91 AccountID const& cur,
92 // This is the account whose constraints we are checking
93 AccountID const& next,
94 Currency const& currency,
96{
97 // fetch the ripple lines into and out of this node
98 auto sleIn = view.read(keylet::line(prev, cur, currency));
99 auto sleOut = view.read(keylet::line(cur, next, currency));
100
101 if (!sleIn || !sleOut)
102 return terNO_LINE;
103
104 if ((*sleIn)[sfFlags] & ((cur > prev) ? lsfHighNoRipple : lsfLowNoRipple) &&
105 (*sleOut)[sfFlags] & ((cur > next) ? lsfHighNoRipple : lsfLowNoRipple))
106 {
107 JLOG(j.info()) << "Path violates noRipple constraint between " << prev
108 << ", " << cur << " and " << next;
109
110 return terNO_RIPPLE;
111 }
112 return tesSUCCESS;
113}
114
115} // namespace ripple
116
117#endif
A generic endpoint for log messages.
Definition Journal.h:60
Stream info() const
Definition Journal.h:334
A currency issued by an account.
Definition Issue.h:33
A view into a ledger.
Definition ReadView.h:51
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:130
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Definition Indexes.cpp:446
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:244
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:184
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
TER checkFreeze(ReadView const &view, AccountID const &src, AccountID const &dst, Currency const &currency)
Definition StepChecks.h:33
@ 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:88
@ tecINTERNAL
Definition TER.h:311
@ tesSUCCESS
Definition TER.h:245
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
Definition View.cpp:376
@ terNO_RIPPLE
Definition TER.h:224
@ terNO_LINE
Definition TER.h:219
TERSubset< CanCvtToTER > TER
Definition TER.h:649