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