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 <xrpl/basics/Log.h>
25#include <xrpl/beast/utility/Journal.h>
26#include <xrpl/protocol/AccountID.h>
27#include <xrpl/protocol/UintTypes.h>
28
29namespace ripple {
30
31inline TER
33 ReadView const& view,
34 AccountID const& src,
35 AccountID const& dst,
36 Currency const& currency)
37{
38 XRPL_ASSERT(src != dst, "ripple::checkFreeze : unequal input accounts");
39
40 // check freeze
41 if (auto sle = view.read(keylet::account(dst)))
42 {
43 if (sle->isFlag(lsfGlobalFreeze))
44 {
45 return terNO_LINE;
46 }
47 }
48
49 if (auto sle = view.read(keylet::line(src, dst, currency)))
50 {
51 if (sle->isFlag((dst > src) ? lsfHighFreeze : lsfLowFreeze))
52 {
53 return terNO_LINE;
54 }
55 }
56
57 return tesSUCCESS;
58}
59
60inline TER
62 ReadView const& view,
63 AccountID const& prev,
64 AccountID const& cur,
65 // This is the account whose constraints we are checking
66 AccountID const& next,
67 Currency const& currency,
69{
70 // fetch the ripple lines into and out of this node
71 auto sleIn = view.read(keylet::line(prev, cur, currency));
72 auto sleOut = view.read(keylet::line(cur, next, currency));
73
74 if (!sleIn || !sleOut)
75 return terNO_LINE;
76
77 if ((*sleIn)[sfFlags] & ((cur > prev) ? lsfHighNoRipple : lsfLowNoRipple) &&
78 (*sleOut)[sfFlags] & ((cur > next) ? lsfHighNoRipple : lsfLowNoRipple))
79 {
80 JLOG(j.info()) << "Path violates noRipple constraint between " << prev
81 << ", " << cur << " and " << next;
82
83 return terNO_RIPPLE;
84 }
85 return tesSUCCESS;
86}
87
88} // namespace ripple
89
90#endif
A generic endpoint for log messages.
Definition: Journal.h:59
Stream info() const
Definition: Journal.h:323
A view into a ledger.
Definition: ReadView.h:55
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
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:160
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
TER checkFreeze(ReadView const &view, AccountID const &src, AccountID const &dst, Currency const &currency)
Definition: StepChecks.h:32
@ lsfHighNoRipple
@ lsfHighFreeze
@ lsfLowNoRipple
@ lsfGlobalFreeze
@ lsfLowFreeze
TER checkNoRipple(ReadView const &view, AccountID const &prev, AccountID const &cur, AccountID const &next, Currency const &currency, beast::Journal j)
Definition: StepChecks.h:61
@ tesSUCCESS
Definition: TER.h:242
@ terNO_RIPPLE
Definition: TER.h:224
@ terNO_LINE
Definition: TER.h:219
TERSubset< CanCvtToTER > TER
Definition: TER.h:627