rippled
CanonicalTXSet.h
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 #ifndef RIPPLE_APP_MISC_CANONICALTXSET_H_INCLUDED
21 #define RIPPLE_APP_MISC_CANONICALTXSET_H_INCLUDED
22 
23 #include <ripple/protocol/RippleLedgerHash.h>
24 #include <ripple/protocol/STTx.h>
25 #include <ripple/protocol/SeqProxy.h>
26 
27 namespace ripple {
28 
36 // VFALCO TODO rename to SortedTxSet
38 {
39 private:
40  class Key
41  {
42  public:
43  Key(uint256 const& account, SeqProxy seqProx, uint256 const& id)
44  : account_(account), txId_(id), seqProxy_(seqProx)
45  {
46  }
47 
48  friend bool
49  operator<(Key const& lhs, Key const& rhs);
50 
51  inline friend bool
52  operator>(Key const& lhs, Key const& rhs)
53  {
54  return rhs < lhs;
55  }
56 
57  inline friend bool
58  operator<=(Key const& lhs, Key const& rhs)
59  {
60  return !(lhs > rhs);
61  }
62 
63  inline friend bool
64  operator>=(Key const& lhs, Key const& rhs)
65  {
66  return !(lhs < rhs);
67  }
68 
69  inline friend bool
70  operator==(Key const& lhs, Key const& rhs)
71  {
72  return lhs.txId_ == rhs.txId_;
73  }
74 
75  inline friend bool
76  operator!=(Key const& lhs, Key const& rhs)
77  {
78  return !(lhs == rhs);
79  }
80 
81  uint256 const&
82  getAccount() const
83  {
84  return account_;
85  }
86 
87  uint256 const&
88  getTXID() const
89  {
90  return txId_;
91  }
92 
93  private:
97  };
98 
99  friend bool
100  operator<(Key const& lhs, Key const& rhs);
101 
102  // Calculate the salted key for the given account
103  uint256
104  accountKey(AccountID const& account);
105 
106 public:
107  using const_iterator =
109 
110 public:
111  explicit CanonicalTXSet(LedgerHash const& saltHash) : salt_(saltHash)
112  {
113  }
114 
115  void
117 
118  // Pops the next transaction on account that follows seqProx in the
119  // sort order. Normally called when a transaction is successfully
120  // applied to the open ledger so the next transaction can be resubmitted
121  // without waiting for ledger close.
122  //
123  // The return value is often null, when an account has no more
124  // transactions.
127 
128  void
129  reset(LedgerHash const& salt)
130  {
131  salt_ = salt;
132  map_.clear();
133  }
134 
137  {
138  return map_.erase(it);
139  }
140 
142  begin() const
143  {
144  return map_.begin();
145  }
146 
148  end() const
149  {
150  return map_.end();
151  }
152 
153  size_t
154  size() const
155  {
156  return map_.size();
157  }
158  bool
159  empty() const
160  {
161  return map_.empty();
162  }
163 
164  uint256 const&
165  key() const
166  {
167  return salt_;
168  }
169 
170 private:
172 
173  // Used to salt the accounts so people can't mine for low account numbers
175 };
176 
177 } // namespace ripple
178 
179 #endif
ripple::Dir::const_iterator
Definition: Directory.h:49
std::shared_ptr
STL class.
ripple::CanonicalTXSet::map_
std::map< Key, std::shared_ptr< STTx const > > map_
Definition: CanonicalTXSet.h:171
ripple::CanonicalTXSet::key
uint256 const & key() const
Definition: CanonicalTXSet.h:165
ripple::CanonicalTXSet::Key::operator==
friend bool operator==(Key const &lhs, Key const &rhs)
Definition: CanonicalTXSet.h:70
ripple::CanonicalTXSet::erase
const_iterator erase(const_iterator const &it)
Definition: CanonicalTXSet.h:136
ripple::CanonicalTXSet::popAcctTransaction
std::shared_ptr< STTx const > popAcctTransaction(std::shared_ptr< STTx const > const &tx)
Definition: CanonicalTXSet.cpp:62
ripple::CanonicalTXSet::Key::operator>=
friend bool operator>=(Key const &lhs, Key const &rhs)
Definition: CanonicalTXSet.h:64
ripple::CanonicalTXSet::salt_
uint256 salt_
Definition: CanonicalTXSet.h:174
ripple::CanonicalTXSet::Key::seqProxy_
SeqProxy seqProxy_
Definition: CanonicalTXSet.h:96
ripple::CanonicalTXSet
Holds transactions which were deferred to the next pass of consensus.
Definition: CanonicalTXSet.h:37
ripple::CanonicalTXSet::begin
const_iterator begin() const
Definition: CanonicalTXSet.h:142
ripple::CanonicalTXSet::Key::account_
uint256 account_
Definition: CanonicalTXSet.h:94
ripple::base_uint< 256 >
ripple::CanonicalTXSet::CanonicalTXSet
CanonicalTXSet(LedgerHash const &saltHash)
Definition: CanonicalTXSet.h:111
ripple::CanonicalTXSet::Key::getTXID
uint256 const & getTXID() const
Definition: CanonicalTXSet.h:88
ripple::CanonicalTXSet::Key::Key
Key(uint256 const &account, SeqProxy seqProx, uint256 const &id)
Definition: CanonicalTXSet.h:43
ripple::CanonicalTXSet::Key::getAccount
uint256 const & getAccount() const
Definition: CanonicalTXSet.h:82
ripple::CanonicalTXSet::Key::operator>
friend bool operator>(Key const &lhs, Key const &rhs)
Definition: CanonicalTXSet.h:52
std::map
STL class.
ripple::CanonicalTXSet::accountKey
uint256 accountKey(AccountID const &account)
Definition: CanonicalTXSet.cpp:43
ripple::CanonicalTXSet::insert
void insert(std::shared_ptr< STTx const > const &txn)
Definition: CanonicalTXSet.cpp:52
ripple::CanonicalTXSet::end
const_iterator end() const
Definition: CanonicalTXSet.h:148
ripple::CanonicalTXSet::Key
Definition: CanonicalTXSet.h:40
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::CanonicalTXSet::size
size_t size() const
Definition: CanonicalTXSet.h:154
ripple::CanonicalTXSet::const_iterator
std::map< Key, std::shared_ptr< STTx const > >::const_iterator const_iterator
Definition: CanonicalTXSet.h:108
ripple::CanonicalTXSet::Key::txId_
uint256 txId_
Definition: CanonicalTXSet.h:95
ripple::CanonicalTXSet::empty
bool empty() const
Definition: CanonicalTXSet.h:159
ripple::SeqProxy
A type that represents either a sequence value or a ticket value.
Definition: SeqProxy.h:55
ripple::CanonicalTXSet::operator<
friend bool operator<(Key const &lhs, Key const &rhs)
Definition: CanonicalTXSet.cpp:25
ripple::CanonicalTXSet::Key::operator<=
friend bool operator<=(Key const &lhs, Key const &rhs)
Definition: CanonicalTXSet.h:58
ripple::CanonicalTXSet::Key::operator!=
friend bool operator!=(Key const &lhs, Key const &rhs)
Definition: CanonicalTXSet.h:76
ripple::CanonicalTXSet::reset
void reset(LedgerHash const &salt)
Definition: CanonicalTXSet.h:129
ripple::CanonicalTXSet::Key::operator<
friend bool operator<(Key const &lhs, Key const &rhs)
Definition: CanonicalTXSet.cpp:25