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 <xrpld/ledger/ReadView.h>
24#include <xrpld/ledger/View.h>
25
26#include <xrpl/basics/Log.h>
27#include <xrpl/beast/utility/Journal.h>
28#include <xrpl/protocol/AccountID.h>
29#include <xrpl/protocol/UintTypes.h>
30
31namespace ripple {
32
33inline TER
35 ReadView const& view,
36 AccountID const& src,
37 AccountID const& dst,
38 Currency const& currency)
39{
40 XRPL_ASSERT(src != dst, "ripple::checkFreeze : unequal input accounts");
41
42 // check freeze
43 if (auto sle = view.read(keylet::account(dst)))
44 {
45 if (sle->isFlag(lsfGlobalFreeze))
46 {
47 return terNO_LINE;
48 }
49 }
50
51 if (auto sle = view.read(keylet::line(src, dst, currency)))
52 {
53 if (sle->isFlag((dst > src) ? lsfHighFreeze : lsfLowFreeze))
54 {
55 return terNO_LINE;
56 }
57 // Unlike normal freeze, a deep frozen trust line acts the same
58 // regardless of which side froze it
59 if (sle->isFlag(lsfHighDeepFreeze) || sle->isFlag(lsfLowDeepFreeze))
60 {
61 return terNO_LINE;
62 }
63 }
64
65 if (view.rules().enabled(fixFrozenLPTokenTransfer))
66 {
67 if (auto const sleDst = view.read(keylet::account(dst));
68 sleDst && sleDst->isFieldPresent(sfAMMID))
69 {
70 auto const sleAmm = view.read(keylet::amm((*sleDst)[sfAMMID]));
71 if (!sleAmm)
72 return tecINTERNAL; // LCOV_EXCL_LINE
73
75 view,
76 src,
77 (*sleAmm)[sfAsset].get<Issue>(),
78 (*sleAmm)[sfAsset2].get<Issue>()))
79 {
80 return terNO_LINE;
81 }
82 }
83 }
84
85 return tesSUCCESS;
86}
87
88inline TER
90 ReadView const& view,
91 AccountID const& prev,
92 AccountID const& cur,
93 // This is the account whose constraints we are checking
94 AccountID const& next,
95 Currency const& currency,
97{
98 // fetch the ripple lines into and out of this node
99 auto sleIn = view.read(keylet::line(prev, cur, currency));
100 auto sleOut = view.read(keylet::line(cur, next, currency));
101
102 if (!sleIn || !sleOut)
103 return terNO_LINE;
104
105 if ((*sleIn)[sfFlags] & ((cur > prev) ? lsfHighNoRipple : lsfLowNoRipple) &&
106 (*sleOut)[sfFlags] & ((cur > next) ? lsfHighNoRipple : lsfLowNoRipple))
107 {
108 JLOG(j.info()) << "Path violates noRipple constraint between " << prev
109 << ", " << cur << " and " << next;
110
111 return terNO_RIPPLE;
112 }
113 return tesSUCCESS;
114}
115
116} // namespace ripple
117
118#endif
A generic endpoint for log messages.
Definition: Journal.h:60
Stream info() const
Definition: Journal.h:334
A view into a ledger.
Definition: ReadView.h:52
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:34
@ lsfHighDeepFreeze
@ lsfHighNoRipple
@ lsfHighFreeze
@ lsfLowNoRipple
@ lsfGlobalFreeze
@ lsfLowFreeze
@ lsfLowDeepFreeze
TER checkNoRipple(ReadView const &view, AccountID const &prev, AccountID const &cur, AccountID const &next, Currency const &currency, beast::Journal j)
Definition: StepChecks.h:89
@ tecINTERNAL
Definition: TER.h:310
@ tesSUCCESS
Definition: TER.h:244
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
Definition: View.cpp:374
@ terNO_RIPPLE
Definition: TER.h:224
@ terNO_LINE
Definition: TER.h:219
TERSubset< CanCvtToTER > TER
Definition: TER.h:645