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 
49 namespace keylet {
50 
52 Keylet
53 account(AccountID const& id) noexcept;
54 
56 Keylet const&
57 amendments() noexcept;
58 
60 Keylet
61 child(uint256 const& key) noexcept;
62 
68 Keylet const&
69 skip() noexcept;
70 
81 Keylet
82 skip(LedgerIndex ledger) noexcept;
83 
85 Keylet const&
86 fees() noexcept;
87 
89 Keylet const&
90 negativeUNL() noexcept;
91 
93 struct book_t
94 {
95  explicit book_t() = default;
96 
97  Keylet
98  operator()(Book const& b) const;
99 };
100 static book_t const book{};
101 
110 Keylet
111 line(
112  AccountID const& id0,
113  AccountID const& id1,
114  Currency const& currency) noexcept;
115 
116 inline Keylet
117 line(AccountID const& id, Issue const& issue) noexcept
118 {
119  return line(id, issue.account, issue.currency);
120 }
125 Keylet
126 offer(AccountID const& id, std::uint32_t seq) noexcept;
127 
128 inline Keylet
129 offer(uint256 const& key) noexcept
130 {
131  return {ltOFFER, key};
132 }
136 Keylet
137 quality(Keylet const& k, std::uint64_t q) noexcept;
138 
140 struct next_t
141 {
142  explicit next_t() = default;
143 
144  Keylet
145  operator()(Keylet const& k) const;
146 };
147 static next_t const next{};
148 
150 struct ticket_t
151 {
152  explicit ticket_t() = default;
153 
154  Keylet
155  operator()(AccountID const& id, std::uint32_t seq) const;
156 
157  Keylet
158  operator()(uint256 const& key) const
159  {
160  return {ltTICKET, key};
161  }
162 };
163 static ticket_t const ticket{};
164 
166 Keylet
167 signers(AccountID const& account) noexcept;
168 
171 Keylet
172 check(AccountID const& id, std::uint32_t seq) noexcept;
173 
174 inline Keylet
175 check(uint256 const& key) noexcept
176 {
177  return {ltCHECK, key};
178 }
183 Keylet
184 depositPreauth(AccountID const& owner, AccountID const& preauthorized) noexcept;
185 
186 inline Keylet
187 depositPreauth(uint256 const& key) noexcept
188 {
189  return {ltDEPOSIT_PREAUTH, key};
190 }
193 //------------------------------------------------------------------------------
194 
196 Keylet
197 unchecked(uint256 const& key) noexcept;
198 
200 Keylet
201 ownerDir(AccountID const& id) noexcept;
202 
205 Keylet
206 page(uint256 const& root, std::uint64_t index = 0) noexcept;
207 
208 inline Keylet
209 page(Keylet const& root, std::uint64_t index = 0) noexcept
210 {
211  assert(root.type == ltDIR_NODE);
212  return page(root.key, index);
213 }
217 Keylet
218 escrow(AccountID const& src, std::uint32_t seq) noexcept;
219 
221 Keylet
222 payChan(AccountID const& src, AccountID const& dst, std::uint32_t seq) noexcept;
223 
224 } // namespace keylet
225 
226 // Everything below is deprecated and should be removed in favor of keylets:
227 
228 uint256
229 getBookBase(Book const& book);
230 
231 uint256
232 getQualityNext(uint256 const& uBase);
233 
234 // VFALCO This name could be better
236 getQuality(uint256 const& uBase);
237 
238 uint256
239 getTicketIndex(AccountID const& account, std::uint32_t uSequence);
240 
241 } // namespace ripple
242 
243 #endif
ripple::keylet::ownerDir
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition: Indexes.cpp:285
ripple::keylet::next_t
The directory for the next lower quality.
Definition: Indexes.h:140
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:151
ripple::keylet::next_t::next_t
next_t()=default
ripple::getBookBase
uint256 getBookBase(Book const &book)
Definition: Indexes.cpp:78
ripple::keylet::offer
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition: Indexes.cpp:210
ripple::keylet::skip
Keylet const & skip() noexcept
The index of the "short" skip list.
Definition: Indexes.cpp:133
ripple::keylet::child
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Definition: Indexes.cpp:127
ripple::keylet::ticket
static const ticket_t ticket
Definition: Indexes.h:163
ripple::getQualityNext
uint256 getQualityNext(uint256 const &uBase)
Definition: Indexes.cpp:96
ripple::keylet::next
static const next_t next
Definition: Indexes.h:147
ripple::ltTICKET
@ ltTICKET
Definition: LedgerFormats.h:68
ripple::keylet::next_t::operator()
Keylet operator()(Keylet const &k) const
Definition: Indexes.cpp:234
ripple::ltCHECK
@ ltCHECK
Definition: LedgerFormats.h:85
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:493
ripple::base_uint
Definition: base_uint.h:63
ripple::keylet::ticket_t::operator()
Keylet operator()(AccountID const &id, std::uint32_t seq) const
Definition: Indexes.cpp:241
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:300
ripple::keylet::book_t
The beginning of an order book.
Definition: Indexes.h:93
ripple::keylet::account
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:121
ripple::keylet::page
Keylet page(uint256 const &key, std::uint64_t index) noexcept
A page in a directory.
Definition: Indexes.cpp:291
cstdint
std::uint32_t
ripple::keylet::book
static const book_t book
Definition: Indexes.h:100
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:181
ripple::ltDEPOSIT_PREAUTH
@ ltDEPOSIT_PREAUTH
Definition: LedgerFormats.h:87
ripple::keylet::unchecked
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Definition: Indexes.cpp:279
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:306
ripple::getTicketIndex
uint256 getTicketIndex(AccountID const &account, std::uint32_t uSequence)
Definition: Indexes.cpp:110
std
STL namespace.
ripple::keylet::fees
Keylet const & fees() noexcept
The (fixed) index of the object containing the ledger fees.
Definition: Indexes.cpp:159
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:216
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:250
ripple::keylet::ticket_t::operator()
Keylet operator()(uint256 const &key) const
Definition: Indexes.h:158
ripple::keylet::negativeUNL
Keylet const & negativeUNL() noexcept
The (fixed) index of the object containing the ledger negativeUNL.
Definition: Indexes.cpp:167
ripple::keylet::check
Keylet check(AccountID const &id, std::uint32_t seq) noexcept
A Check.
Definition: Indexes.cpp:263
ripple::keylet::depositPreauth
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Definition: Indexes.cpp:269
ripple::getQuality
std::uint64_t getQuality(uint256 const &uBase)
Definition: Indexes.cpp:103
ripple::keylet::ticket_t
A ticket belonging to an account.
Definition: Indexes.h:150
ripple::AccountID
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:47