Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
DBHelpers.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include "util/Assert.hpp"
5
6#include <boost/container/flat_set.hpp>
7#include <xrpl/basics/Blob.h>
8#include <xrpl/basics/Log.h>
9#include <xrpl/basics/StringUtilities.h>
10#include <xrpl/basics/base_uint.h>
11#include <xrpl/protocol/AccountID.h>
12#include <xrpl/protocol/SField.h>
13#include <xrpl/protocol/STAccount.h>
14#include <xrpl/protocol/STLedgerEntry.h>
15#include <xrpl/protocol/Serializer.h>
16#include <xrpl/protocol/TxMeta.h>
17
18#include <cstddef>
19#include <cstdint>
20#include <optional>
21#include <string>
22
27 boost::container::flat_set<xrpl::AccountID> accounts;
28 std::uint32_t ledgerSequence{};
29 std::uint32_t transactionIndex{};
30 xrpl::uint256 txHash;
31
38 AccountTransactionsData(xrpl::TxMeta const& meta, xrpl::uint256 const& txHash)
39 : accounts(meta.getAffectedAccounts())
40 , ledgerSequence(meta.getLgrSeq())
41 , transactionIndex(meta.getIndex())
42 , txHash(txHash)
43 {
44 }
45
46 AccountTransactionsData() = default;
47};
48
55 xrpl::uint256 tokenID;
56 std::uint32_t ledgerSequence;
57 std::uint32_t transactionIndex;
58 xrpl::uint256 txHash;
59
68 xrpl::uint256 const& tokenID,
69 xrpl::TxMeta const& meta,
70 xrpl::uint256 const& txHash
71 )
73 , ledgerSequence(meta.getLgrSeq())
74 , transactionIndex(meta.getIndex())
75 , txHash(txHash)
76 {
77 }
78};
79
93struct NFTsData {
94 xrpl::uint256 tokenID;
95 std::uint32_t ledgerSequence;
96 std::optional<std::uint32_t> transactionIndex;
97 xrpl::AccountID owner;
98 std::optional<xrpl::Blob> uri;
99 bool isBurned = false;
100 bool onlyUriChanged = false;
101
116 xrpl::uint256 const& tokenID,
117 xrpl::AccountID const& owner,
118 xrpl::Blob const& uri,
119 xrpl::TxMeta const& meta
120 )
122 , ledgerSequence(meta.getLgrSeq())
123 , transactionIndex(meta.getIndex())
124 , owner(owner)
125 , uri(uri)
126 {
127 }
128
140 xrpl::uint256 const& tokenID,
141 xrpl::AccountID const& owner,
142 xrpl::TxMeta const& meta,
143 bool isBurned
144 )
146 , ledgerSequence(meta.getLgrSeq())
147 , transactionIndex(meta.getIndex())
148 , owner(owner)
150 {
151 }
152
167 xrpl::uint256 const& tokenID,
168 std::uint32_t const ledgerSequence,
169 xrpl::AccountID const& owner,
170 xrpl::Blob const& uri
171 )
173 {
174 }
175
184 NFTsData(xrpl::uint256 const& tokenID, xrpl::TxMeta const& meta, xrpl::Blob const& uri)
186 , ledgerSequence(meta.getLgrSeq())
187 , transactionIndex(meta.getIndex())
188 , uri(uri)
189 , onlyUriChanged(true)
190 {
191 }
192};
193
198 xrpl::uint192 mptID;
199 xrpl::AccountID holder;
200};
201
209 xrpl::uint192 mptIssuanceID;
210 boost::container::flat_set<xrpl::AccountID> accounts;
211 std::uint32_t ledgerSequence{};
212 std::uint32_t transactionIndex{};
213 xrpl::uint256 txHash;
214
215 bool
216 operator==(MPTokenIssuanceTransactionsData const&) const = default;
217};
218
226template <typename T>
227inline bool
228isDirNode(T const& object)
229{
230 static constexpr auto kMinSizeRequired = 3;
231 if (std::size(object) < kMinSizeRequired)
232 return false;
233
234 static constexpr short kDirNodeSpaceKey = 0x0064;
235 short const spaceKey = (object.data()[1] << 8) | object.data()[2];
236 return spaceKey == kDirNodeSpaceKey;
237}
238
248template <typename T, typename R>
249inline bool
250isBookDir(T const& key, R const& object)
251{
252 if (!isDirNode(object))
253 return false;
254
255 xrpl::STLedgerEntry const sle{xrpl::SerialIter{object.data(), object.size()}, key};
256 return !sle[~xrpl::sfOwner].has_value();
257}
258
266template <typename T>
267inline xrpl::uint256
268getBookBase(T const& key)
269{
270 static constexpr size_t kEySize = 24;
271
272 ASSERT(key.size() == xrpl::uint256::size(), "Invalid key size {}", key.size());
273
274 xrpl::uint256 ret;
275 for (size_t i = 0; i < kEySize; ++i)
276 ret.data()[i] = key.data()[i];
277
278 return ret;
279}
280
287inline std::string
288uint256ToString(xrpl::uint256 const& input)
289{
290 return {reinterpret_cast<char const*>(input.data()), xrpl::uint256::size()};
291}
292
296static constexpr std::uint32_t kRippleEpochStart = 946684800;
bool isDirNode(T const &object)
Check whether the supplied object is a dir node.
Definition DBHelpers.hpp:228
xrpl::uint256 getBookBase(T const &key)
Get the book base.
Definition DBHelpers.hpp:268
static constexpr std::uint32_t kRippleEpochStart
The ripple epoch start timestamp. Midnight on 1st January 2000.
Definition DBHelpers.hpp:296
bool isBookDir(T const &key, R const &object)
Check whether the supplied object is a book dir.
Definition DBHelpers.hpp:250
std::string uint256ToString(xrpl::uint256 const &input)
Stringify a xrpl::uint256.
Definition DBHelpers.hpp:288
boost::container::flat_set< xrpl::AccountID > accounts
Accounts affected by the transaction.
Definition DBHelpers.hpp:27
AccountTransactionsData(xrpl::TxMeta const &meta, xrpl::uint256 const &txHash)
Construct a new AccountTransactionsData object.
Definition DBHelpers.hpp:38
std::uint32_t transactionIndex
Index of the transaction within its ledger.
Definition DBHelpers.hpp:29
std::uint32_t ledgerSequence
Sequence of the ledger containing the transaction.
Definition DBHelpers.hpp:28
xrpl::uint256 txHash
Hash of the transaction.
Definition DBHelpers.hpp:30
Represents an MPT and holder pair.
Definition DBHelpers.hpp:197
xrpl::uint192 mptID
ID of the MPToken issuance.
Definition DBHelpers.hpp:198
xrpl::AccountID holder
Account holding the MPToken.
Definition DBHelpers.hpp:199
Represents a transaction link for an MPTokenIssuance.
Definition DBHelpers.hpp:208
std::uint32_t ledgerSequence
Sequence of the ledger containing the transaction.
Definition DBHelpers.hpp:211
boost::container::flat_set< xrpl::AccountID > accounts
Accounts affected by the transaction.
Definition DBHelpers.hpp:210
xrpl::uint256 txHash
Hash of the transaction.
Definition DBHelpers.hpp:213
std::uint32_t transactionIndex
Index of the transaction within its ledger.
Definition DBHelpers.hpp:212
xrpl::uint192 mptIssuanceID
ID of the affected MPToken issuance.
Definition DBHelpers.hpp:209
std::uint32_t transactionIndex
Index of the transaction within its ledger.
Definition DBHelpers.hpp:57
xrpl::uint256 txHash
Hash of the transaction.
Definition DBHelpers.hpp:58
NFTTransactionsData(xrpl::uint256 const &tokenID, xrpl::TxMeta const &meta, xrpl::uint256 const &txHash)
Construct a new NFTTransactionsData object.
Definition DBHelpers.hpp:67
xrpl::uint256 tokenID
ID of the NFT affected by the transaction.
Definition DBHelpers.hpp:55
std::uint32_t ledgerSequence
Sequence of the ledger containing the transaction.
Definition DBHelpers.hpp:56
NFTsData(xrpl::uint256 const &tokenID, xrpl::AccountID const &owner, xrpl::TxMeta const &meta, bool isBurned)
Construct a new NFTsData object.
Definition DBHelpers.hpp:139
NFTsData(xrpl::uint256 const &tokenID, xrpl::AccountID const &owner, xrpl::Blob const &uri, xrpl::TxMeta const &meta)
Construct a new NFTsData object.
Definition DBHelpers.hpp:115
std::uint32_t ledgerSequence
Ledger sequence of this NFT state.
Definition DBHelpers.hpp:95
xrpl::AccountID owner
Owner in this record; unset if URI-only.
Definition DBHelpers.hpp:97
std::optional< xrpl::Blob > uri
URI of the NFT, if recorded.
Definition DBHelpers.hpp:98
NFTsData(xrpl::uint256 const &tokenID, std::uint32_t const ledgerSequence, xrpl::AccountID const &owner, xrpl::Blob const &uri)
Construct a new NFTsData object.
Definition DBHelpers.hpp:166
NFTsData(xrpl::uint256 const &tokenID, xrpl::TxMeta const &meta, xrpl::Blob const &uri)
Construct a new NFTsData object with only the URI changed.
Definition DBHelpers.hpp:184
bool onlyUriChanged
Whether only the URI was changed.
Definition DBHelpers.hpp:100
std::optional< std::uint32_t > transactionIndex
Index of the tx producing this state.
Definition DBHelpers.hpp:96
xrpl::uint256 tokenID
ID of the NFT.
Definition DBHelpers.hpp:94
bool isBurned
Whether the NFT has been burned.
Definition DBHelpers.hpp:99