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/STXChainBridge.h>
30 #include <ripple/protocol/Serializer.h>
31 #include <ripple/protocol/UintTypes.h>
32 #include <cstdint>
33 
34 namespace ripple {
35 
36 class SeqProxy;
51 namespace keylet {
52 
54 Keylet
55 account(AccountID const& id) noexcept;
56 
58 Keylet const&
59 amendments() noexcept;
60 
62 Keylet
63 child(uint256 const& key) noexcept;
64 
70 Keylet const&
71 skip() noexcept;
72 
83 Keylet
84 skip(LedgerIndex ledger) noexcept;
85 
87 Keylet const&
88 fees() noexcept;
89 
91 Keylet const&
92 negativeUNL() noexcept;
93 
95 struct book_t
96 {
97  explicit book_t() = default;
98 
99  Keylet
100  operator()(Book const& b) const;
101 };
102 static book_t const book{};
103 
112 Keylet
113 line(
114  AccountID const& id0,
115  AccountID const& id1,
116  Currency const& currency) noexcept;
117 
118 inline Keylet
119 line(AccountID const& id, Issue const& issue) noexcept
120 {
121  return line(id, issue.account, issue.currency);
122 }
127 Keylet
128 offer(AccountID const& id, std::uint32_t seq) noexcept;
129 
130 inline Keylet
131 offer(uint256 const& key) noexcept
132 {
133  return {ltOFFER, key};
134 }
138 Keylet
139 quality(Keylet const& k, std::uint64_t q) noexcept;
140 
142 struct next_t
143 {
144  explicit next_t() = default;
145 
146  Keylet
147  operator()(Keylet const& k) const;
148 };
149 static next_t const next{};
150 
152 struct ticket_t
153 {
154  explicit ticket_t() = default;
155 
156  Keylet
157  operator()(AccountID const& id, std::uint32_t ticketSeq) const;
158 
159  Keylet
160  operator()(AccountID const& id, SeqProxy ticketSeq) const;
161 
162  Keylet
163  operator()(uint256 const& key) const
164  {
165  return {ltTICKET, key};
166  }
167 };
168 static ticket_t const ticket{};
169 
171 Keylet
172 signers(AccountID const& account) noexcept;
173 
176 Keylet
177 check(AccountID const& id, std::uint32_t seq) noexcept;
178 
179 inline Keylet
180 check(uint256 const& key) noexcept
181 {
182  return {ltCHECK, key};
183 }
188 Keylet
189 depositPreauth(AccountID const& owner, AccountID const& preauthorized) noexcept;
190 
191 inline Keylet
192 depositPreauth(uint256 const& key) noexcept
193 {
194  return {ltDEPOSIT_PREAUTH, key};
195 }
198 //------------------------------------------------------------------------------
199 
201 Keylet
202 unchecked(uint256 const& key) noexcept;
203 
205 Keylet
206 ownerDir(AccountID const& id) noexcept;
207 
210 Keylet
211 page(uint256 const& root, std::uint64_t index = 0) noexcept;
212 
213 inline Keylet
214 page(Keylet const& root, std::uint64_t index = 0) noexcept
215 {
216  assert(root.type == ltDIR_NODE);
217  return page(root.key, index);
218 }
222 Keylet
223 escrow(AccountID const& src, std::uint32_t seq) noexcept;
224 
226 Keylet
227 payChan(AccountID const& src, AccountID const& dst, std::uint32_t seq) noexcept;
228 
238 Keylet
239 nftpage_min(AccountID const& owner);
240 
242 Keylet
243 nftpage_max(AccountID const& owner);
244 
245 Keylet
246 nftpage(Keylet const& k, uint256 const& token);
250 Keylet
251 nftoffer(AccountID const& owner, std::uint32_t seq);
252 
253 inline Keylet
255 {
256  return {ltNFTOKEN_OFFER, offer};
257 }
258 
260 Keylet
261 nft_buys(uint256 const& id) noexcept;
262 
264 Keylet
265 nft_sells(uint256 const& id) noexcept;
266 
268 Keylet
269 amm(Issue const& issue1, Issue const& issue2) noexcept;
270 
271 Keylet
272 amm(uint256 const& amm) noexcept;
273 
274 Keylet
276 
277 Keylet
279 
280 Keylet
282 
283 Keylet
284 did(AccountID const& account) noexcept;
285 
286 Keylet
287 oracle(AccountID const& account, std::uint32_t const& documentID) noexcept;
288 
289 } // namespace keylet
290 
291 // Everything below is deprecated and should be removed in favor of keylets:
292 
293 uint256
294 getBookBase(Book const& book);
295 
296 uint256
297 getQualityNext(uint256 const& uBase);
298 
299 // VFALCO This name could be better
301 getQuality(uint256 const& uBase);
302 
303 uint256
304 getTicketIndex(AccountID const& account, std::uint32_t uSequence);
305 
306 uint256
307 getTicketIndex(AccountID const& account, SeqProxy ticketSeq);
308 
309 } // namespace ripple
310 
311 #endif
ripple::keylet::ownerDir
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition: Indexes.cpp:313
ripple::keylet::next_t
The directory for the next lower quality.
Definition: Indexes.h:142
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:99
ripple::Issue
A currency issued by an account.
Definition: Issue.h:35
ripple::keylet::amendments
Keylet const & amendments() noexcept
The index of the amendment table.
Definition: Indexes.cpp:173
ripple::STXChainBridge::ChainType
ChainType
Definition: STXChainBridge.h:43
ripple::keylet::next_t::next_t
next_t()=default
ripple::keylet::oracle
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
Definition: Indexes.cpp:449
ripple::getBookBase
uint256 getBookBase(Book const &book)
Definition: Indexes.cpp:92
ripple::keylet::amm
Keylet amm(Issue const &issue1, Issue const &issue2) noexcept
AMM entry.
Definition: Indexes.cpp:384
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:365
ripple::keylet::offer
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition: Indexes.cpp:232
ripple::keylet::skip
Keylet const & skip() noexcept
The index of the "short" skip list.
Definition: Indexes.cpp:155
ripple::keylet::did
Keylet did(AccountID const &account) noexcept
Definition: Indexes.cpp:443
ripple::keylet::child
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Definition: Indexes.cpp:149
ripple::keylet::xChainClaimID
Keylet xChainClaimID(STXChainBridge const &bridge, std::uint64_t seq)
Definition: Indexes.cpp:415
ripple::keylet::ticket
static const ticket_t ticket
Definition: Indexes.h:168
ripple::ltCHECK
@ ltCHECK
A ledger object which describes a check.
Definition: LedgerFormats.h:155
ripple::getQualityNext
uint256 getQualityNext(uint256 const &uBase)
Definition: Indexes.cpp:110
ripple::keylet::next
static const next_t next
Definition: Indexes.h:149
ripple::getTicketIndex
uint256 getTicketIndex(AccountID const &account, std::uint32_t ticketSeq)
Definition: Indexes.cpp:125
ripple::keylet::next_t::operator()
Keylet operator()(Keylet const &k) const
Definition: Indexes.cpp:256
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:328
ripple::keylet::nftpage_min
Keylet nftpage_min(AccountID const &owner)
NFT page keylets.
Definition: Indexes.cpp:342
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:358
ripple::keylet::book_t
The beginning of an order book.
Definition: Indexes.h:95
ripple::keylet::account
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:143
ripple::keylet::bridge
Keylet bridge(STXChainBridge const &bridge, STXChainBridge::ChainType chainType)
Definition: Indexes.cpp:402
ripple::ltNFTOKEN_OFFER
@ ltNFTOKEN_OFFER
A ledger object which identifies an offer to buy or sell an NFT.
Definition: LedgerFormats.h:181
ripple::keylet::page
Keylet page(uint256 const &key, std::uint64_t index) noexcept
A page in a directory.
Definition: Indexes.cpp:319
ripple::ltDEPOSIT_PREAUTH
@ ltDEPOSIT_PREAUTH
A ledger object which describes a deposit preauthorization.
Definition: LedgerFormats.h:161
ripple::keylet::nft_sells
Keylet nft_sells(uint256 const &id) noexcept
The directory of sell offers for the specified NFT.
Definition: Indexes.cpp:378
ripple::keylet::nftpage_max
Keylet nftpage_max(AccountID const &owner)
A keylet for the owner's last possible NFT page.
Definition: Indexes.cpp:350
cstdint
ripple::keylet::ticket_t::operator()
Keylet operator()(AccountID const &id, std::uint32_t ticketSeq) const
Definition: Indexes.cpp:263
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:372
ripple::keylet::book
static const book_t book
Definition: Indexes.h:102
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:203
ripple::keylet::unchecked
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Definition: Indexes.cpp:307
ripple::STXChainBridge
Definition: STXChainBridge.h:33
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:334
std
STL namespace.
ripple::SeqProxy
A type that represents either a sequence value or a ticket value.
Definition: SeqProxy.h:55
ripple::keylet::xChainCreateAccountClaimID
Keylet xChainCreateAccountClaimID(STXChainBridge const &bridge, std::uint64_t seq)
Definition: Indexes.cpp:429
ripple::keylet::fees
Keylet const & fees() noexcept
The (fixed) index of the object containing the ledger fees.
Definition: Indexes.cpp:181
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:238
ripple::keylet::signers
static Keylet signers(AccountID const &account, std::uint32_t page) noexcept
Definition: Indexes.cpp:278
ripple::keylet::ticket_t::operator()
Keylet operator()(uint256 const &key) const
Definition: Indexes.h:163
ripple::keylet::negativeUNL
Keylet const & negativeUNL() noexcept
The (fixed) index of the object containing the ledger negativeUNL.
Definition: Indexes.cpp:189
ripple::keylet::check
Keylet check(AccountID const &id, std::uint32_t seq) noexcept
A Check.
Definition: Indexes.cpp:291
ripple::keylet::depositPreauth
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Definition: Indexes.cpp:297
ripple::getQuality
std::uint64_t getQuality(uint256 const &uBase)
Definition: Indexes.cpp:118
ripple::keylet::ticket_t
A ticket belonging to an account.
Definition: Indexes.h:152
ripple::AccountID
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:49
ripple::root
Number root(Number f, unsigned d)
Definition: Number.cpp:624