rippled
Indexes.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_PROTOCOL_INDEXES_H_INCLUDED
21 #define RIPPLE_PROTOCOL_INDEXES_H_INCLUDED
22 
23 #include <ripple/protocol/Keylet.h>
24 #include <ripple/protocol/LedgerFormats.h>
25 #include <ripple/protocol/Protocol.h>
26 #include <ripple/protocol/PublicKey.h>
27 #include <ripple/protocol/Serializer.h>
28 #include <ripple/protocol/UintTypes.h>
29 #include <ripple/basics/base_uint.h>
30 #include <ripple/protocol/Book.h>
31 #include <cstdint>
32 
33 namespace ripple {
34 
35 // get the index of the node that holds the last 256 ledgers
36 uint256
38 
39 // Get the index of the node that holds the set of 256 ledgers that includes
40 // this ledger's hash (or the first ledger after it if it's not a multiple
41 // of 256).
42 uint256
43 getLedgerHashIndex (std::uint32_t desiredLedgerIndex);
44 
45 // get the index of the node that holds the enabled amendments
46 uint256
48 
49 // get the index of the node that holds the fee schedule
50 uint256
52 
53 uint256
54 getGeneratorIndex (AccountID const& uGeneratorID);
55 
56 uint256
57 getBookBase (Book const& book);
58 
59 uint256
60 getOfferIndex (AccountID const& account, std::uint32_t uSequence);
61 
62 uint256
63 getOwnerDirIndex (AccountID const& account);
64 
65 uint256
66 getDirNodeIndex (uint256 const& uDirRoot, const std::uint64_t uNodeIndex);
67 
68 uint256
69 getQualityIndex (uint256 const& uBase, const std::uint64_t uNodeDir = 0);
70 
71 uint256
72 getQualityNext (uint256 const& uBase);
73 
74 // VFALCO This name could be better
76 getQuality (uint256 const& uBase);
77 
78 uint256
79 getTicketIndex (AccountID const& account, std::uint32_t uSequence);
80 
81 uint256
82 getRippleStateIndex (AccountID const& a, AccountID const& b, Currency const& currency);
83 
84 uint256
85 getRippleStateIndex (AccountID const& a, Issue const& issue);
86 
87 uint256
88 getSignerListIndex (AccountID const& account);
89 
90 uint256
91 getCheckIndex (AccountID const& account, std::uint32_t uSequence);
92 
93 uint256
94 getDepositPreauthIndex (AccountID const& owner, AccountID const& preauthorized);
95 
96 //------------------------------------------------------------------------------
97 
98 /* VFALCO TODO
99  For each of these operators that take just the uin256 and
100  only attach the LedgerEntryType, we can comment out that
101  operator to see what breaks, and those call sites are
102  candidates for having the Keylet either passed in as a
103  parameter, or having a data member that stores the keylet.
104 */
105 
107 namespace keylet {
108 
110 struct account_t
111 {
112  explicit account_t() = default;
113 
114  Keylet operator()(AccountID const& id) const;
115 };
116 static account_t const account {};
117 
120 {
121  explicit amendments_t() = default;
122 
123  Keylet operator()() const;
124 };
125 static amendments_t const amendments {};
126 
128 Keylet child (uint256 const& key);
129 
131 struct skip_t
132 {
133  explicit skip_t() = default;
134 
135  Keylet operator()() const;
136 
137  Keylet operator()(LedgerIndex ledger) const;
138 };
139 static skip_t const skip {};
140 
142 struct fees_t
143 {
144  explicit fees_t() = default;
145 
146  // VFALCO This could maybe be constexpr
147  Keylet operator()() const;
148 };
149 static fees_t const fees {};
150 
152 struct book_t
153 {
154  explicit book_t() = default;
155 
156  Keylet operator()(Book const& b) const;
157 };
158 static book_t const book {};
159 
161 struct line_t
162 {
163  explicit line_t() = default;
164 
165  Keylet operator()(AccountID const& id0,
166  AccountID const& id1, Currency const& currency) const;
167 
168  Keylet operator()(AccountID const& id,
169  Issue const& issue) const;
170 
171  Keylet operator()(uint256 const& key) const
172  {
173  return { ltRIPPLE_STATE, key };
174  }
175 };
176 static line_t const line {};
177 
179 struct offer_t
180 {
181  explicit offer_t() = default;
182 
183  Keylet operator()(AccountID const& id,
184  std::uint32_t seq) const;
185 
186  Keylet operator()(uint256 const& key) const
187  {
188  return { ltOFFER, key };
189  }
190 };
191 static offer_t const offer {};
192 
194 struct quality_t
195 {
196  explicit quality_t() = default;
197 
198  Keylet operator()(Keylet const& k,
199  std::uint64_t q) const;
200 };
201 static quality_t const quality {};
202 
204 struct next_t
205 {
206  explicit next_t() = default;
207 
208  Keylet operator()(Keylet const& k) const;
209 };
210 static next_t const next {};
211 
213 struct ticket_t
214 {
215  explicit ticket_t() = default;
216 
217  Keylet operator()(AccountID const& id,
218  std::uint32_t seq) const;
219 
220  Keylet operator()(uint256 const& key) const
221  {
222  return { ltTICKET, key };
223  }
224 };
225 static ticket_t const ticket {};
226 
228 struct signers_t
229 {
230  explicit signers_t() = default;
231 
232  Keylet operator()(AccountID const& id) const;
233 
234  Keylet operator()(uint256 const& key) const
235  {
236  return { ltSIGNER_LIST, key };
237  }
238 };
239 static signers_t const signers {};
240 
242 struct check_t
243 {
244  explicit check_t() = default;
245 
246  Keylet operator()(AccountID const& id,
247  std::uint32_t seq) const;
248 
249  Keylet operator()(uint256 const& key) const
250  {
251  return { ltCHECK, key };
252  }
253 };
254 static check_t const check {};
255 
258 {
259  explicit depositPreauth_t() = default;
260 
261  Keylet operator()(AccountID const& owner,
262  AccountID const& preauthorized) const;
263 
264  Keylet operator()(uint256 const& key) const
265  {
266  return { ltDEPOSIT_PREAUTH, key };
267  }
268 };
270 
271 //------------------------------------------------------------------------------
272 
274 Keylet unchecked(uint256 const& key);
275 
277 Keylet ownerDir (AccountID const& id);
278 
281 Keylet page (uint256 const& root, std::uint64_t index);
282 Keylet page (Keylet const& root, std::uint64_t index);
285 // DEPRECATED
286 inline
287 Keylet page (uint256 const& key)
288 {
289  return { ltDIR_NODE, key };
290 }
291 
293 Keylet
294 escrow (AccountID const& source, std::uint32_t seq);
295 
297 Keylet
298 payChan (AccountID const& source, AccountID const& dst, std::uint32_t seq);
299 
300 } // keylet
301 
302 }
303 
304 #endif
ripple::keylet::signers_t::operator()
Keylet operator()(uint256 const &key) const
Definition: Indexes.h:234
ripple::keylet::amendments_t::operator()
Keylet operator()() const
Definition: Indexes.cpp:230
ripple::keylet::next_t
The directory for the next lower quality.
Definition: Indexes.h:204
ripple::keylet::skip
static const skip_t skip
Definition: Indexes.h:139
ripple::keylet::line_t::operator()
Keylet operator()(AccountID const &id0, AccountID const &id1, Currency const &currency) const
Definition: Indexes.cpp:248
ripple::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:38
ripple::Issue
A currency issued by an account.
Definition: Issue.h:34
ripple::keylet::signers
static const signers_t signers
Definition: Indexes.h:239
ripple::keylet::account_t
AccountID root.
Definition: Indexes.h:110
ripple::keylet::account_t::operator()
Keylet operator()(AccountID const &id) const
Definition: Indexes.cpp:207
ripple::keylet::fees_t
The ledger fees.
Definition: Indexes.h:142
ripple::keylet::fees
static const fees_t fees
Definition: Indexes.h:149
ripple::keylet::skip_t
Skip list.
Definition: Indexes.h:131
ripple::keylet::next_t::next_t
next_t()=default
ripple::getLedgerAmendmentIndex
uint256 getLedgerAmendmentIndex()
Definition: Indexes.cpp:46
ripple::getBookBase
uint256 getBookBase(Book const &book)
Definition: Indexes.cpp:67
ripple::getQualityIndex
uint256 getQualityIndex(uint256 const &uBase, const std::uint64_t uNodeDir)
Definition: Indexes.cpp:110
ripple::getOfferIndex
uint256 getOfferIndex(AccountID const &account, std::uint32_t uSequence)
Definition: Indexes.cpp:80
ripple::keylet::payChan
Keylet payChan(AccountID const &source, AccountID const &dst, std::uint32_t seq)
A PaymentChannel.
Definition: Indexes.cpp:350
ripple::AccountID
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:48
ripple::keylet::depositPreauth_t
A DepositPreauth.
Definition: Indexes.h:257
ripple::getSignerListIndex
uint256 getSignerListIndex(AccountID const &account)
Definition: Indexes.cpp:173
ripple::keylet::child
Keylet child(uint256 const &key)
Any item that can be in an owner dir.
Definition: Indexes.cpp:213
ripple::keylet::fees_t::operator()
Keylet operator()() const
Definition: Indexes.cpp:236
ripple::keylet::ticket
static const ticket_t ticket
Definition: Indexes.h:225
ripple::keylet::check
static const check_t check
Definition: Indexes.h:254
ripple::getQualityNext
uint256 getQualityNext(uint256 const &uBase)
Definition: Indexes.cpp:127
ripple::ltSIGNER_LIST
@ ltSIGNER_LIST
Definition: LedgerFormats.h:71
ripple::keylet::account_t::account_t
account_t()=default
ripple::keylet::offer_t
An offer from an account.
Definition: Indexes.h:179
ripple::keylet::depositPreauth_t::operator()
Keylet operator()(AccountID const &owner, AccountID const &preauthorized) const
Definition: Indexes.cpp:304
ripple::keylet::signers_t
A SignerList.
Definition: Indexes.h:228
ripple::keylet::next
static const next_t next
Definition: Indexes.h:210
ripple::getLedgerFeeIndex
uint256 getLedgerFeeIndex()
Definition: Indexes.cpp:53
ripple::keylet::skip_t::operator()
Keylet operator()() const
Definition: Indexes.cpp:218
ripple::ltTICKET
@ ltTICKET
Definition: LedgerFormats.h:69
ripple::keylet::next_t::operator()
Keylet operator()(Keylet const &k) const
Definition: Indexes.cpp:277
ripple::ltCHECK
@ ltCHECK
Definition: LedgerFormats.h:86
ripple::keylet::signers_t::signers_t
signers_t()=default
ripple::keylet::depositPreauth
static const depositPreauth_t depositPreauth
Definition: Indexes.h:269
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:436
ripple::keylet::line_t::operator()
Keylet operator()(uint256 const &key) const
Definition: Indexes.h:171
ripple::getGeneratorIndex
uint256 getGeneratorIndex(AccountID const &uGeneratorID)
Definition: Indexes.cpp:59
ripple::base_uint< 160, detail::AccountIDTag >
ripple::getDirNodeIndex
uint256 getDirNodeIndex(uint256 const &uDirRoot, const std::uint64_t uNodeIndex)
Definition: Indexes.cpp:98
ripple::keylet::ticket_t::operator()
Keylet operator()(AccountID const &id, std::uint32_t seq) const
Definition: Indexes.cpp:284
ripple::keylet::ticket_t::ticket_t
ticket_t()=default
ripple::getCheckIndex
uint256 getCheckIndex(AccountID const &account, std::uint32_t uSequence)
Definition: Indexes.cpp:186
ripple::keylet::line
static const line_t line
Definition: Indexes.h:176
ripple::keylet::book_t::book_t
book_t()=default
ripple::keylet::line_t::line_t
line_t()=default
ripple::keylet::book_t
The beginning of an order book.
Definition: Indexes.h:152
ripple::keylet::signers_t::operator()
Keylet operator()(AccountID const &id) const
Definition: Indexes.cpp:291
ripple::keylet::account
static const account_t account
Definition: Indexes.h:116
ripple::keylet::line_t
A trust line.
Definition: Indexes.h:161
ripple::getRippleStateIndex
uint256 getRippleStateIndex(AccountID const &a, AccountID const &b, Currency const &currency)
Definition: Indexes.cpp:151
ripple::keylet::ownerDir
Keylet ownerDir(AccountID const &id)
The root page of an account's directory.
Definition: Indexes.cpp:318
ripple::keylet::escrow
Keylet escrow(AccountID const &source, std::uint32_t seq)
An escrow entry.
Definition: Indexes.cpp:339
ripple::getOwnerDirIndex
uint256 getOwnerDirIndex(AccountID const &account)
Definition: Indexes.cpp:89
ripple::keylet::skip_t::skip_t
skip_t()=default
cstdint
ripple::keylet::quality_t::quality_t
quality_t()=default
std::uint32_t
ripple::keylet::book
static const book_t book
Definition: Indexes.h:158
ripple::keylet::check_t::check_t
check_t()=default
ripple::keylet::fees_t::fees_t
fees_t()=default
ripple::ltDEPOSIT_PREAUTH
@ ltDEPOSIT_PREAUTH
Definition: LedgerFormats.h:88
ripple::keylet::check_t
A Check.
Definition: Indexes.h:242
ripple::keylet::unchecked
Keylet unchecked(uint256 const &key)
Any ledger entry.
Definition: Indexes.cpp:313
ripple::keylet::amendments
static const amendments_t amendments
Definition: Indexes.h:125
ripple::Currency
base_uint< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition: UintTypes.h:56
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::getDepositPreauthIndex
uint256 getDepositPreauthIndex(AccountID const &owner, AccountID const &preauthorized)
Definition: Indexes.cpp:195
ripple::ltRIPPLE_STATE
@ ltRIPPLE_STATE
Definition: LedgerFormats.h:67
ripple::keylet::book_t::operator()
Keylet operator()(Book const &b) const
Definition: Indexes.cpp:242
ripple::keylet::depositPreauth_t::depositPreauth_t
depositPreauth_t()=default
ripple::getLedgerHashIndex
uint256 getLedgerHashIndex()
Definition: Indexes.cpp:29
ripple::getTicketIndex
uint256 getTicketIndex(AccountID const &account, std::uint32_t uSequence)
Definition: Indexes.cpp:142
ripple::keylet::depositPreauth_t::operator()
Keylet operator()(uint256 const &key) const
Definition: Indexes.h:264
ripple::keylet::check_t::operator()
Keylet operator()(uint256 const &key) const
Definition: Indexes.h:249
ripple::keylet::amendments_t::amendments_t
amendments_t()=default
ripple::keylet::quality_t::operator()
Keylet operator()(Keylet const &k, std::uint64_t q) const
Definition: Indexes.cpp:269
ripple::Book
Specifies an order book.
Definition: Book.h:32
ripple::keylet::quality
static const quality_t quality
Definition: Indexes.h:201
ripple::ltDIR_NODE
@ ltDIR_NODE
Directory node.
Definition: LedgerFormats.h:65
ripple::ltOFFER
@ ltOFFER
Definition: LedgerFormats.h:73
ripple::keylet::offer_t::operator()
Keylet operator()(uint256 const &key) const
Definition: Indexes.h:186
ripple::keylet::amendments_t
The amendment table.
Definition: Indexes.h:119
ripple::keylet::quality_t
The initial directory page for a specific quality.
Definition: Indexes.h:194
ripple::keylet::ticket_t::operator()
Keylet operator()(uint256 const &key) const
Definition: Indexes.h:220
ripple::keylet::offer_t::offer_t
offer_t()=default
ripple::keylet::offer
static const offer_t offer
Definition: Indexes.h:191
ripple::keylet::offer_t::operator()
Keylet operator()(AccountID const &id, std::uint32_t seq) const
Definition: Indexes.cpp:262
ripple::getQuality
std::uint64_t getQuality(uint256 const &uBase)
Definition: Indexes.cpp:135
ripple::keylet::ticket_t
A ticket belonging to an account.
Definition: Indexes.h:213
ripple::keylet::page
Keylet page(uint256 const &key, std::uint64_t index)
A page in a directory.
Definition: Indexes.cpp:324
ripple::keylet::check_t::operator()
Keylet operator()(AccountID const &id, std::uint32_t seq) const
Definition: Indexes.cpp:297