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 
237 Keylet
238 nftpage_min(AccountID const& owner);
239 
241 Keylet
242 nftpage_max(AccountID const& owner);
243 
244 Keylet
245 nftpage(Keylet const& k, uint256 const& token);
249 Keylet
250 nftoffer(AccountID const& owner, std::uint32_t seq);
251 
252 inline Keylet
254 {
255  return {ltNFTOKEN_OFFER, offer};
256 }
257 
259 Keylet
260 nft_buys(uint256 const& id) noexcept;
261 
263 Keylet
264 nft_sells(uint256 const& id) noexcept;
265 
266 } // namespace keylet
267 
268 // Everything below is deprecated and should be removed in favor of keylets:
269 
270 uint256
271 getBookBase(Book const& book);
272 
273 uint256
274 getQualityNext(uint256 const& uBase);
275 
276 // VFALCO This name could be better
278 getQuality(uint256 const& uBase);
279 
280 uint256
281 getTicketIndex(AccountID const& account, std::uint32_t uSequence);
282 
283 uint256
284 getTicketIndex(AccountID const& account, SeqProxy ticketSeq);
285 
286 } // namespace ripple
287 
288 #endif
ripple::keylet::ownerDir
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition: Indexes.cpp:303
ripple::keylet::next_t
The directory for the next lower quality.
Definition: Indexes.h:141
ripple::ltTICKET
@ ltTICKET
A ledger object which describes a ticket.
Definition: LedgerFormats.h:80
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:90
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:163
ripple::keylet::next_t::next_t
next_t()=default
ripple::getBookBase
uint256 getBookBase(Book const &book)
Definition: Indexes.cpp:82
ripple::keylet::nftoffer
Keylet nftoffer(AccountID const &owner, std::uint32_t seq)
An offer from an account to buy or sell an NFT.
Definition: Indexes.cpp:355
ripple::keylet::offer
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition: Indexes.cpp:222
ripple::keylet::skip
Keylet const & skip() noexcept
The index of the "short" skip list.
Definition: Indexes.cpp:145
ripple::keylet::child
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Definition: Indexes.cpp:139
ripple::keylet::ticket
static const ticket_t ticket
Definition: Indexes.h:167
ripple::ltCHECK
@ ltCHECK
A ledger object which describes a check.
Definition: LedgerFormats.h:136
ripple::getQualityNext
uint256 getQualityNext(uint256 const &uBase)
Definition: Indexes.cpp:100
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:115
ripple::keylet::next_t::operator()
Keylet operator()(Keylet const &k) const
Definition: Indexes.cpp:246
ripple::ltDIR_NODE
@ ltDIR_NODE
A ledger object which contains a list of object identifiers.
Definition: LedgerFormats.h:66
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:550
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:82
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:318
ripple::keylet::nftpage_min
Keylet nftpage_min(AccountID const &owner)
NFT page keylets.
Definition: Indexes.cpp:332
ripple::ltOFFER
@ ltOFFER
A ledger object which describes an offer on the DEX.
Definition: LedgerFormats.h:92
ripple::keylet::nftpage
Keylet nftpage(Keylet const &k, uint256 const &token)
Definition: Indexes.cpp:348
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:133
ripple::ltNFTOKEN_OFFER
@ ltNFTOKEN_OFFER
A ledger object which identifies an offer to buy or sell an NFT.
Definition: LedgerFormats.h:162
ripple::keylet::page
Keylet page(uint256 const &key, std::uint64_t index) noexcept
A page in a directory.
Definition: Indexes.cpp:309
ripple::ltDEPOSIT_PREAUTH
@ ltDEPOSIT_PREAUTH
A ledger object which describes a deposit preauthorization.
Definition: LedgerFormats.h:142
ripple::keylet::nft_sells
Keylet nft_sells(uint256 const &id) noexcept
The directory of sell offers for the specified NFT.
Definition: Indexes.cpp:368
ripple::keylet::nftpage_max
Keylet nftpage_max(AccountID const &owner)
A keylet for the owner's last possible NFT page.
Definition: Indexes.cpp:340
cstdint
ripple::keylet::ticket_t::operator()
Keylet operator()(AccountID const &id, std::uint32_t ticketSeq) const
Definition: Indexes.cpp:253
std::uint32_t
ripple::keylet::nft_buys
Keylet nft_buys(uint256 const &id) noexcept
The directory of buy offers for the specified NFT.
Definition: Indexes.cpp:362
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:193
ripple::keylet::unchecked
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Definition: Indexes.cpp:297
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:324
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:171
ripple::Book
Specifies an order book.
Definition: Book.h:33
ripple::keylet::quality
Keylet quality(Keylet const &k, std::uint64_t q) noexcept
The initial directory page for a specific quality.
Definition: Indexes.cpp:228
ripple::keylet::signers
static Keylet signers(AccountID const &account, std::uint32_t page) noexcept
Definition: Indexes.cpp:268
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:179
ripple::keylet::check
Keylet check(AccountID const &id, std::uint32_t seq) noexcept
A Check.
Definition: Indexes.cpp:281
ripple::keylet::depositPreauth
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Definition: Indexes.cpp:287
ripple::getQuality
std::uint64_t getQuality(uint256 const &uBase)
Definition: Indexes.cpp:108
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
ripple::root
Number root(Number f, unsigned d)
Definition: Number.cpp:624