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/basics/base_uint.h>
24 #include <ripple/protocol/Book.h>
25 #include <ripple/protocol/Keylet.h>
26 #include <ripple/protocol/LedgerFormats.h>
27 #include <ripple/protocol/Protocol.h>
28 #include <ripple/protocol/PublicKey.h>
29 #include <ripple/protocol/Serializer.h>
30 #include <ripple/protocol/UintTypes.h>
31 #include <cstdint>
32 
33 namespace ripple {
34 
35 class SeqProxy;
50 namespace keylet {
51 
53 Keylet
54 account(AccountID const& id) noexcept;
55 
57 Keylet const&
58 amendments() noexcept;
59 
61 Keylet
62 child(uint256 const& key) noexcept;
63 
69 Keylet const&
70 skip() noexcept;
71 
82 Keylet
83 skip(LedgerIndex ledger) noexcept;
84 
86 Keylet const&
87 fees() noexcept;
88 
90 Keylet const&
91 negativeUNL() noexcept;
92 
94 struct book_t
95 {
96  explicit book_t() = default;
97 
98  Keylet
99  operator()(Book const& b) const;
100 };
101 static book_t const book{};
102 
111 Keylet
112 line(
113  AccountID const& id0,
114  AccountID const& id1,
115  Currency const& currency) noexcept;
116 
117 inline Keylet
118 line(AccountID const& id, Issue const& issue) noexcept
119 {
120  return line(id, issue.account, issue.currency);
121 }
126 Keylet
127 offer(AccountID const& id, std::uint32_t seq) noexcept;
128 
129 inline Keylet
130 offer(uint256 const& key) noexcept
131 {
132  return {ltOFFER, key};
133 }
137 Keylet
138 quality(Keylet const& k, std::uint64_t q) noexcept;
139 
141 struct next_t
142 {
143  explicit next_t() = default;
144 
145  Keylet
146  operator()(Keylet const& k) const;
147 };
148 static next_t const next{};
149 
151 struct ticket_t
152 {
153  explicit ticket_t() = default;
154 
155  Keylet
156  operator()(AccountID const& id, std::uint32_t ticketSeq) const;
157 
158  Keylet
159  operator()(AccountID const& id, SeqProxy ticketSeq) const;
160 
161  Keylet
162  operator()(uint256 const& key) const
163  {
164  return {ltTICKET, key};
165  }
166 };
167 static ticket_t const ticket{};
168 
170 Keylet
171 signers(AccountID const& account) noexcept;
172 
175 Keylet
176 check(AccountID const& id, std::uint32_t seq) noexcept;
177 
178 inline Keylet
179 check(uint256 const& key) noexcept
180 {
181  return {ltCHECK, key};
182 }
187 Keylet
188 depositPreauth(AccountID const& owner, AccountID const& preauthorized) noexcept;
189 
190 inline Keylet
191 depositPreauth(uint256 const& key) noexcept
192 {
193  return {ltDEPOSIT_PREAUTH, key};
194 }
197 //------------------------------------------------------------------------------
198 
200 Keylet
201 unchecked(uint256 const& key) noexcept;
202 
204 Keylet
205 ownerDir(AccountID const& id) noexcept;
206 
209 Keylet
210 page(uint256 const& root, std::uint64_t index = 0) noexcept;
211 
212 inline Keylet
213 page(Keylet const& root, std::uint64_t index = 0) noexcept
214 {
215  assert(root.type == ltDIR_NODE);
216  return page(root.key, index);
217 }
221 Keylet
222 escrow(AccountID const& src, std::uint32_t seq) noexcept;
223 
225 Keylet
226 payChan(AccountID const& src, AccountID const& dst, std::uint32_t seq) noexcept;
227 
228 } // namespace keylet
229 
230 // Everything below is deprecated and should be removed in favor of keylets:
231 
232 uint256
233 getBookBase(Book const& book);
234 
235 uint256
236 getQualityNext(uint256 const& uBase);
237 
238 // VFALCO This name could be better
240 getQuality(uint256 const& uBase);
241 
242 uint256
243 getTicketIndex(AccountID const& account, std::uint32_t uSequence);
244 
245 uint256
246 getTicketIndex(AccountID const& account, SeqProxy ticketSeq);
247 
248 } // namespace ripple
249 
250 #endif
ripple::keylet::ownerDir
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition: Indexes.cpp:304
ripple::keylet::next_t
The directory for the next lower quality.
Definition: Indexes.h:141
ripple::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:38
ripple::LedgerIndex
std::uint32_t LedgerIndex
A ledger index.
Definition: Protocol.h:57
ripple::Issue
A currency issued by an account.
Definition: Issue.h:34
ripple::keylet::amendments
Keylet const & amendments() noexcept
The index of the amendment table.
Definition: Indexes.cpp:164
ripple::keylet::next_t::next_t
next_t()=default
ripple::getBookBase
uint256 getBookBase(Book const &book)
Definition: Indexes.cpp:79
ripple::keylet::offer
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition: Indexes.cpp:223
ripple::keylet::skip
Keylet const & skip() noexcept
The index of the "short" skip list.
Definition: Indexes.cpp:146
ripple::keylet::child
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Definition: Indexes.cpp:140
ripple::keylet::ticket
static const ticket_t ticket
Definition: Indexes.h:167
ripple::getQualityNext
uint256 getQualityNext(uint256 const &uBase)
Definition: Indexes.cpp:97
ripple::keylet::next
static const next_t next
Definition: Indexes.h:148
ripple::getTicketIndex
uint256 getTicketIndex(AccountID const &account, std::uint32_t ticketSeq)
Definition: Indexes.cpp:116
ripple::ltTICKET
@ ltTICKET
Definition: LedgerFormats.h:68
ripple::keylet::next_t::operator()
Keylet operator()(Keylet const &k) const
Definition: Indexes.cpp:247
ripple::ltCHECK
@ ltCHECK
Definition: LedgerFormats.h:85
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:457
ripple::base_uint< 160, detail::AccountIDTag >
ripple::keylet::ticket_t::ticket_t
ticket_t()=default
ripple::keylet::escrow
Keylet escrow(AccountID const &src, std::uint32_t seq) noexcept
An escrow entry.
Definition: Indexes.cpp:319
ripple::keylet::book_t
The beginning of an order book.
Definition: Indexes.h:94
ripple::keylet::account
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:134
ripple::keylet::page
Keylet page(uint256 const &key, std::uint64_t index) noexcept
A page in a directory.
Definition: Indexes.cpp:310
cstdint
ripple::keylet::ticket_t::operator()
Keylet operator()(AccountID const &id, std::uint32_t ticketSeq) const
Definition: Indexes.cpp:254
std::uint32_t
ripple::keylet::book
static const book_t book
Definition: Indexes.h:101
ripple::keylet::line
Keylet line(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition: Indexes.cpp:194
ripple::ltDEPOSIT_PREAUTH
@ ltDEPOSIT_PREAUTH
Definition: LedgerFormats.h:87
ripple::keylet::unchecked
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Definition: Indexes.cpp:298
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::keylet::payChan
Keylet payChan(AccountID const &src, AccountID const &dst, std::uint32_t seq) noexcept
A PaymentChannel.
Definition: Indexes.cpp:325
std
STL namespace.
ripple::SeqProxy
A type that represents either a sequence value or a ticket value.
Definition: SeqProxy.h:55
ripple::keylet::fees
Keylet const & fees() noexcept
The (fixed) index of the object containing the ledger fees.
Definition: Indexes.cpp:172
ripple::Book
Specifies an order book.
Definition: Book.h:32
ripple::keylet::quality
Keylet quality(Keylet const &k, std::uint64_t q) noexcept
The initial directory page for a specific quality.
Definition: Indexes.cpp:229
ripple::ltDIR_NODE
@ ltDIR_NODE
Directory node.
Definition: LedgerFormats.h:64
ripple::ltOFFER
@ ltOFFER
Definition: LedgerFormats.h:72
ripple::keylet::signers
static Keylet signers(AccountID const &account, std::uint32_t page) noexcept
Definition: Indexes.cpp:269
ripple::keylet::ticket_t::operator()
Keylet operator()(uint256 const &key) const
Definition: Indexes.h:162
ripple::keylet::negativeUNL
Keylet const & negativeUNL() noexcept
The (fixed) index of the object containing the ledger negativeUNL.
Definition: Indexes.cpp:180
ripple::keylet::check
Keylet check(AccountID const &id, std::uint32_t seq) noexcept
A Check.
Definition: Indexes.cpp:282
ripple::keylet::depositPreauth
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Definition: Indexes.cpp:288
ripple::getQuality
std::uint64_t getQuality(uint256 const &uBase)
Definition: Indexes.cpp:109
ripple::keylet::ticket_t
A ticket belonging to an account.
Definition: Indexes.h:151
ripple::AccountID
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:47