rippled
CanonicalTXSet.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 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 #include <ripple/app/misc/CanonicalTXSet.h>
21 #include <boost/range/adaptor/transformed.hpp>
22 
23 namespace ripple {
24 
25 bool
27 {
28  if (mAccount < rhs.mAccount)
29  return true;
30 
31  if (mAccount > rhs.mAccount)
32  return false;
33 
34  if (mSeq < rhs.mSeq)
35  return true;
36 
37  if (mSeq > rhs.mSeq)
38  return false;
39 
40  return mTXid < rhs.mTXid;
41 }
42 
43 bool
45 {
46  if (mAccount > rhs.mAccount)
47  return true;
48 
49  if (mAccount < rhs.mAccount)
50  return false;
51 
52  if (mSeq > rhs.mSeq)
53  return true;
54 
55  if (mSeq < rhs.mSeq)
56  return false;
57 
58  return mTXid > rhs.mTXid;
59 }
60 
61 bool
63 {
64  if (mAccount < rhs.mAccount)
65  return true;
66 
67  if (mAccount > rhs.mAccount)
68  return false;
69 
70  if (mSeq < rhs.mSeq)
71  return true;
72 
73  if (mSeq > rhs.mSeq)
74  return false;
75 
76  return mTXid <= rhs.mTXid;
77 }
78 
79 bool
81 {
82  if (mAccount > rhs.mAccount)
83  return true;
84 
85  if (mAccount < rhs.mAccount)
86  return false;
87 
88  if (mSeq > rhs.mSeq)
89  return true;
90 
91  if (mSeq < rhs.mSeq)
92  return false;
93 
94  return mTXid >= rhs.mTXid;
95 }
96 
97 uint256
99 {
100  uint256 ret = beast::zero;
101  memcpy(ret.begin(), account.begin(), account.size());
102  ret ^= salt_;
103  return ret;
104 }
105 
106 void
108 {
109  map_.insert(std::make_pair(
110  Key(accountKey(txn->getAccountID(sfAccount)),
111  txn->getSequence(),
112  txn->getTransactionID()),
113  txn));
114 }
115 
118 {
119  auto effectiveAccount = accountKey(account);
120 
121  Key keyLow(effectiveAccount, seq, beast::zero);
122  Key keyHigh(effectiveAccount, seq + 1, beast::zero);
123 
124  auto range = boost::make_iterator_range(
125  map_.lower_bound(keyLow), map_.lower_bound(keyHigh));
126  auto txRange = boost::adaptors::transform(
127  range, [](auto const& p) { return p.second; });
128 
130  txRange.begin(), txRange.end());
131 
132  map_.erase(range.begin(), range.end());
133  return result;
134 }
135 
136 } // namespace ripple
ripple::CanonicalTXSet::Key::operator>
bool operator>(Key const &rhs) const
Definition: CanonicalTXSet.cpp:44
ripple::CanonicalTXSet::Key::mAccount
uint256 mAccount
Definition: CanonicalTXSet.h:74
std::shared_ptr
STL class.
ripple::CanonicalTXSet::map_
std::map< Key, std::shared_ptr< STTx const > > map_
Definition: CanonicalTXSet.h:142
ripple::CanonicalTXSet::Key::operator<=
bool operator<=(Key const &rhs) const
Definition: CanonicalTXSet.cpp:62
std::vector
STL class.
ripple::CanonicalTXSet::salt_
uint256 salt_
Definition: CanonicalTXSet.h:145
ripple::sfAccount
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
Definition: SField.h:480
ripple::base_uint< 256 >
ripple::CanonicalTXSet::Key::mTXid
uint256 mTXid
Definition: CanonicalTXSet.h:75
std::uint32_t
ripple::CanonicalTXSet::accountKey
uint256 accountKey(AccountID const &account)
Definition: CanonicalTXSet.cpp:98
ripple::range
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
Definition: RangeSet.h:53
ripple::CanonicalTXSet::insert
void insert(std::shared_ptr< STTx const > const &txn)
Definition: CanonicalTXSet.cpp:107
ripple::CanonicalTXSet::Key::operator>=
bool operator>=(Key const &rhs) const
Definition: CanonicalTXSet.cpp:80
ripple::CanonicalTXSet::Key::mSeq
std::uint32_t mSeq
Definition: CanonicalTXSet.h:76
ripple::CanonicalTXSet::Key
Definition: CanonicalTXSet.h:39
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::base_uint::begin
iterator begin()
Definition: base_uint.h:114
ripple::CanonicalTXSet::prune
std::vector< std::shared_ptr< STTx const > > prune(AccountID const &account, std::uint32_t const seq)
Definition: CanonicalTXSet.cpp:117
std::make_pair
T make_pair(T... args)
ripple::CanonicalTXSet::Key::operator<
bool operator<(Key const &rhs) const
Definition: CanonicalTXSet.cpp:26