xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
ledger
CanonicalTXSet.h
1
#pragma once
2
3
#include <xrpl/basics/CountedObject.h>
4
#include <xrpl/basics/base_uint.h>
5
#include <xrpl/protocol/AccountID.h>
6
#include <xrpl/protocol/RippleLedgerHash.h>
7
#include <xrpl/protocol/STTx.h>
8
#include <xrpl/protocol/SeqProxy.h>
9
10
#include <
cstddef
>
11
#include <
map
>
12
#include <
memory
>
13
14
namespace
xrpl
{
15
23
// VFALCO TODO rename to SortedTxSet
24
class
CanonicalTXSet
:
public
CountedObject
<CanonicalTXSet>
25
{
26
private
:
27
class
Key
28
{
29
public
:
30
Key
(
UInt256
const
& account,
SeqProxy
seqProx,
UInt256
const
&
id
)
31
:
account_
(account),
txId_
(id),
seqProxy_
(seqProx)
32
{
33
}
34
35
friend
bool
36
operator<
(
Key
const
& lhs,
Key
const
& rhs);
37
38
friend
bool
39
operator>
(
Key
const
& lhs,
Key
const
& rhs)
40
{
41
return
rhs < lhs;
42
}
43
44
friend
bool
45
operator<=
(
Key
const
& lhs,
Key
const
& rhs)
46
{
47
return
!(lhs > rhs);
48
}
49
50
friend
bool
51
operator>=
(
Key
const
& lhs,
Key
const
& rhs)
52
{
53
return
!(lhs < rhs);
54
}
55
56
friend
bool
57
operator==
(
Key
const
& lhs,
Key
const
& rhs)
58
{
59
return
lhs.
txId_
== rhs.
txId_
;
60
}
61
62
[[nodiscard]]
UInt256
const
&
63
getAccount
()
const
64
{
65
return
account_
;
66
}
67
68
[[nodiscard]]
UInt256
const
&
69
getTXID
()
const
70
{
71
return
txId_
;
72
}
73
74
private
:
75
UInt256
account_
;
76
UInt256
txId_
;
77
SeqProxy
seqProxy_
;
78
};
79
80
friend
bool
81
operator<
(
Key
const
& lhs,
Key
const
& rhs);
82
83
// Calculate the salted key for the given account
84
UInt256
85
accountKey
(
AccountID
const
& account);
86
87
public
:
88
using
const_iterator
=
std::map<Key, std::shared_ptr<STTx const>
>
::const_iterator
;
89
90
public
:
91
explicit
CanonicalTXSet
(
LedgerHash
const
& saltHash) :
salt_
(saltHash)
92
{
93
}
94
95
void
96
insert
(
std::shared_ptr<STTx const>
txn);
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.
105
std::shared_ptr<STTx const>
106
popAcctTransaction
(
std::shared_ptr<STTx const>
const
& tx);
107
108
void
109
reset
(
LedgerHash
const
& salt)
110
{
111
salt_
= salt;
112
map_
.clear();
113
}
114
115
const_iterator
116
erase
(
const_iterator
const
& it)
117
{
118
return
map_
.erase(it);
119
}
120
121
[[nodiscard]]
const_iterator
122
begin
()
const
123
{
124
return
map_
.begin();
125
}
126
127
[[nodiscard]]
const_iterator
128
end
()
const
129
{
130
return
map_
.end();
131
}
132
133
[[nodiscard]]
size_t
134
size
()
const
135
{
136
return
map_
.size();
137
}
138
[[nodiscard]]
bool
139
empty
()
const
140
{
141
return
map_
.empty();
142
}
143
144
[[nodiscard]]
UInt256
const
&
145
key
()
const
146
{
147
return
salt_
;
148
}
149
150
private
:
151
std::map<Key, std::shared_ptr<STTx const>
>
map_
;
152
153
// Used to salt the accounts so people can't mine for low account numbers
154
UInt256
salt_
;
155
};
156
157
}
// namespace xrpl
xrpl::CanonicalTXSet::Key
Definition
CanonicalTXSet.h:28
xrpl::CanonicalTXSet::Key::account_
UInt256 account_
Definition
CanonicalTXSet.h:75
xrpl::CanonicalTXSet::Key::getAccount
UInt256 const & getAccount() const
Definition
CanonicalTXSet.h:63
xrpl::CanonicalTXSet::Key::operator<=
friend bool operator<=(Key const &lhs, Key const &rhs)
Definition
CanonicalTXSet.h:45
xrpl::CanonicalTXSet::Key::Key
Key(UInt256 const &account, SeqProxy seqProx, UInt256 const &id)
Definition
CanonicalTXSet.h:30
xrpl::CanonicalTXSet::Key::operator>=
friend bool operator>=(Key const &lhs, Key const &rhs)
Definition
CanonicalTXSet.h:51
xrpl::CanonicalTXSet::Key::txId_
UInt256 txId_
Definition
CanonicalTXSet.h:76
xrpl::CanonicalTXSet::Key::seqProxy_
SeqProxy seqProxy_
Definition
CanonicalTXSet.h:77
xrpl::CanonicalTXSet::Key::operator>
friend bool operator>(Key const &lhs, Key const &rhs)
Definition
CanonicalTXSet.h:39
xrpl::CanonicalTXSet::Key::operator<
friend bool operator<(Key const &lhs, Key const &rhs)
Definition
CanonicalTXSet.cpp:16
xrpl::CanonicalTXSet::Key::operator==
friend bool operator==(Key const &lhs, Key const &rhs)
Definition
CanonicalTXSet.h:57
xrpl::CanonicalTXSet::Key::getTXID
UInt256 const & getTXID() const
Definition
CanonicalTXSet.h:69
xrpl::CanonicalTXSet::salt_
UInt256 salt_
Definition
CanonicalTXSet.h:154
xrpl::CanonicalTXSet::const_iterator
std::map< Key, std::shared_ptr< STTx const > >::const_iterator const_iterator
Definition
CanonicalTXSet.h:88
xrpl::CanonicalTXSet::key
UInt256 const & key() const
Definition
CanonicalTXSet.h:145
xrpl::CanonicalTXSet::empty
bool empty() const
Definition
CanonicalTXSet.h:139
xrpl::CanonicalTXSet::accountKey
UInt256 accountKey(AccountID const &account)
Definition
CanonicalTXSet.cpp:34
xrpl::CanonicalTXSet::begin
const_iterator begin() const
Definition
CanonicalTXSet.h:122
xrpl::CanonicalTXSet::erase
const_iterator erase(const_iterator const &it)
Definition
CanonicalTXSet.h:116
xrpl::CanonicalTXSet::map_
std::map< Key, std::shared_ptr< STTx const > > map_
Definition
CanonicalTXSet.h:151
xrpl::CanonicalTXSet::insert
void insert(std::shared_ptr< STTx const > txn)
Definition
CanonicalTXSet.cpp:43
xrpl::CanonicalTXSet::end
const_iterator end() const
Definition
CanonicalTXSet.h:128
xrpl::CanonicalTXSet::popAcctTransaction
std::shared_ptr< STTx const > popAcctTransaction(std::shared_ptr< STTx const > const &tx)
Definition
CanonicalTXSet.cpp:51
xrpl::CanonicalTXSet::operator<
friend bool operator<(Key const &lhs, Key const &rhs)
Definition
CanonicalTXSet.cpp:16
xrpl::CanonicalTXSet::size
size_t size() const
Definition
CanonicalTXSet.h:134
xrpl::CanonicalTXSet::CanonicalTXSet
CanonicalTXSet(LedgerHash const &saltHash)
Definition
CanonicalTXSet.h:91
xrpl::CanonicalTXSet::reset
void reset(LedgerHash const &salt)
Definition
CanonicalTXSet.h:109
xrpl::CountedObject< CanonicalTXSet >::CountedObject
CountedObject() noexcept
Definition
CountedObject.h:119
xrpl::SeqProxy
A type that represents either a sequence value or a ticket value.
Definition
SeqProxy.h:37
cstddef
map
memory
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::LedgerHash
UInt256 LedgerHash
Definition
RippleLedgerHash.h:7
xrpl::const_iterator
Dir::ConstIterator const_iterator
Definition
Dir.cpp:16
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
std::shared_ptr
Generated by
1.17.0