rippled
Loading...
Searching...
No Matches
CanonicalTXSet.h
1#ifndef XRPL_APP_MISC_CANONICALTXSET_H_INCLUDED
2#define XRPL_APP_MISC_CANONICALTXSET_H_INCLUDED
3
4#include <xrpl/basics/CountedObject.h>
5#include <xrpl/protocol/RippleLedgerHash.h>
6#include <xrpl/protocol/STTx.h>
7#include <xrpl/protocol/SeqProxy.h>
8
9namespace ripple {
10
18// VFALCO TODO rename to SortedTxSet
19class CanonicalTXSet : public CountedObject<CanonicalTXSet>
20{
21private:
22 class Key
23 {
24 public:
25 Key(uint256 const& account, SeqProxy seqProx, uint256 const& id)
26 : account_(account), txId_(id), seqProxy_(seqProx)
27 {
28 }
29
30 friend bool
31 operator<(Key const& lhs, Key const& rhs);
32
33 inline friend bool
34 operator>(Key const& lhs, Key const& rhs)
35 {
36 return rhs < lhs;
37 }
38
39 inline friend bool
40 operator<=(Key const& lhs, Key const& rhs)
41 {
42 return !(lhs > rhs);
43 }
44
45 inline friend bool
46 operator>=(Key const& lhs, Key const& rhs)
47 {
48 return !(lhs < rhs);
49 }
50
51 inline friend bool
52 operator==(Key const& lhs, Key const& rhs)
53 {
54 return lhs.txId_ == rhs.txId_;
55 }
56
57 inline friend bool
58 operator!=(Key const& lhs, Key const& rhs)
59 {
60 return !(lhs == rhs);
61 }
62
63 uint256 const&
64 getAccount() const
65 {
66 return account_;
67 }
68
69 uint256 const&
70 getTXID() const
71 {
72 return txId_;
73 }
74
75 private:
79 };
80
81 friend bool
82 operator<(Key const& lhs, Key const& rhs);
83
84 // Calculate the salted key for the given account
86 accountKey(AccountID const& account);
87
88public:
91
92public:
93 explicit CanonicalTXSet(LedgerHash const& saltHash) : salt_(saltHash)
94 {
95 }
96
97 void
99
100 // Pops the next transaction on account that follows seqProx in the
101 // sort order. Normally called when a transaction is successfully
102 // applied to the open ledger so the next transaction can be resubmitted
103 // without waiting for ledger close.
104 //
105 // The return value is often null, when an account has no more
106 // transactions.
109
110 void
111 reset(LedgerHash const& salt)
112 {
113 salt_ = salt;
114 map_.clear();
115 }
116
119 {
120 return map_.erase(it);
121 }
122
124 begin() const
125 {
126 return map_.begin();
127 }
128
130 end() const
131 {
132 return map_.end();
133 }
134
135 size_t
136 size() const
137 {
138 return map_.size();
139 }
140 bool
141 empty() const
142 {
143 return map_.empty();
144 }
145
146 uint256 const&
147 key() const
148 {
149 return salt_;
150 }
151
152private:
154
155 // Used to salt the accounts so people can't mine for low account numbers
157};
158
159} // namespace ripple
160
161#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:37
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6