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