Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
AmendmentCenter.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and 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#pragma once
21
22#include "data/AmendmentCenterInterface.hpp"
23#include "data/BackendInterface.hpp"
24#include "data/Types.hpp"
25
26#include <boost/asio/spawn.hpp>
27#include <boost/preprocessor.hpp>
28#include <boost/preprocessor/seq/for_each.hpp>
29#include <boost/preprocessor/stringize.hpp>
30#include <boost/preprocessor/variadic/to_seq.hpp>
31#include <xrpl/basics/Slice.h>
32#include <xrpl/basics/base_uint.h>
33#include <xrpl/protocol/Feature.h>
34#include <xrpl/protocol/Indexes.h>
35#include <xrpl/protocol/SField.h>
36#include <xrpl/protocol/STLedgerEntry.h>
37#include <xrpl/protocol/Serializer.h>
38#include <xrpl/protocol/digest.h>
39
40#include <cstdint>
41#include <map>
42#include <memory>
43#include <optional>
44#include <string>
45#include <vector>
46
47#define REGISTER(name) \
48 inline static impl::WritingAmendmentKey const name = \
49 impl::WritingAmendmentKey(std::string(BOOST_PP_STRINGIZE(name)))
50
51namespace data {
52namespace impl {
53
54struct WritingAmendmentKey : AmendmentKey {
55 explicit WritingAmendmentKey(std::string amendmentName);
56};
57
58} // namespace impl
59
63struct Amendments {
64 // NOTE: if Clio wants to report it supports an Amendment it should be listed here.
65 // Whether an amendment is obsolete and/or supported by libxrpl is extracted directly from
66 // libxrpl. If an amendment is in the list below it just means Clio did whatever changes needed
67 // to support it. Most of the time it's going to be no changes at all.
68
70 // NOLINTBEGIN(readability-identifier-naming)
71 REGISTER(Flow);
72 REGISTER(FlowCross);
73 REGISTER(fix1513);
74 REGISTER(DepositAuth);
75 REGISTER(Checks);
76 REGISTER(fix1571);
77 REGISTER(fix1543);
78 REGISTER(fix1623);
79 REGISTER(DepositPreauth);
80 REGISTER(fix1515);
81 REGISTER(fix1578);
82 REGISTER(MultiSignReserve);
83 REGISTER(fixTakerDryOfferRemoval);
84 REGISTER(fixMasterKeyAsRegularKey);
85 REGISTER(fixCheckThreading);
86 REGISTER(fixPayChanRecipientOwnerDir);
87 REGISTER(DeletableAccounts);
88 REGISTER(fixQualityUpperBound);
89 REGISTER(RequireFullyCanonicalSig);
90 REGISTER(fix1781);
91 REGISTER(HardenedValidations);
92 REGISTER(fixAmendmentMajorityCalc);
93 REGISTER(NegativeUNL);
94 REGISTER(TicketBatch);
95 REGISTER(FlowSortStrands);
96 REGISTER(fixSTAmountCanonicalize);
97 REGISTER(fixRmSmallIncreasedQOffers);
98 REGISTER(CheckCashMakesTrustLine);
99 REGISTER(ExpandedSignerList);
100 REGISTER(NonFungibleTokensV1_1);
101 REGISTER(fixTrustLinesToSelf);
102 REGISTER(fixRemoveNFTokenAutoTrustLine);
103 REGISTER(ImmediateOfferKilled);
104 REGISTER(DisallowIncoming);
105 REGISTER(XRPFees);
106 REGISTER(fixUniversalNumber);
107 REGISTER(fixNonFungibleTokensV1_2);
108 REGISTER(fixNFTokenRemint);
109 REGISTER(fixReducedOffersV1);
110 REGISTER(Clawback);
111 REGISTER(AMM);
112 REGISTER(XChainBridge);
113 REGISTER(fixDisallowIncomingV1);
114 REGISTER(DID);
115 REGISTER(fixFillOrKill);
116 REGISTER(fixNFTokenReserve);
117 REGISTER(fixInnerObjTemplate);
118 REGISTER(fixAMMOverflowOffer);
119 REGISTER(PriceOracle);
120 REGISTER(fixEmptyDID);
121 REGISTER(fixXChainRewardRounding);
122 REGISTER(fixPreviousTxnID);
123 REGISTER(fixAMMv1_1);
124 REGISTER(NFTokenMintOffer);
125 REGISTER(fixReducedOffersV2);
126 REGISTER(fixEnforceNFTokenTrustline);
127 REGISTER(fixInnerObjTemplate2);
128 REGISTER(fixNFTokenPageLinks);
129 REGISTER(InvariantsV1_1);
130 REGISTER(MPTokensV1);
131 REGISTER(fixAMMv1_2);
132 REGISTER(AMMClawback);
133 REGISTER(Credentials);
134 REGISTER(DynamicNFT);
135 REGISTER(PermissionedDomains);
136 REGISTER(fixInvalidTxFlags);
137 REGISTER(fixFrozenLPTokenTransfer);
138 REGISTER(DeepFreeze);
139 REGISTER(PermissionDelegation);
140 REGISTER(fixPayChanCancelAfter);
141 REGISTER(Batch);
142 REGISTER(PermissionedDEX);
143 REGISTER(SingleAssetVault);
144 REGISTER(TokenEscrow);
145 REGISTER(fixAMMv1_3);
146 REGISTER(fixEnforceNFTokenTrustlineV2);
147 REGISTER(fixAMMClawbackRounding);
148 REGISTER(fixMPTDeliveredAmount);
149 REGISTER(fixPriceOracleOrder);
150 REGISTER(DynamicMPT);
151 REGISTER(fixDelegateV1_1);
152 REGISTER(fixDirectoryLimit);
153 REGISTER(fixIncludeKeyletFields);
154 REGISTER(fixTokenEscrowV1);
155 REGISTER(LendingProtocol);
156
157 // Obsolete but supported by libxrpl
158 REGISTER(CryptoConditionsSuite);
159 REGISTER(NonFungibleTokensV1);
160 REGISTER(fixNFTokenDirV1);
161 REGISTER(fixNFTokenNegOffer);
162
163 // Retired amendments
164 REGISTER(OwnerPaysFee); // Removed in xrpl 2.6.0 (https://github.com/XRPLF/rippled/pull/5435)
165 REGISTER(MultiSign);
166 REGISTER(TrustSetAuth);
167 REGISTER(FeeEscalation);
168 REGISTER(PayChan);
169 REGISTER(fix1368);
170 REGISTER(CryptoConditions);
171 REGISTER(Escrow);
172 REGISTER(TickSize);
173 REGISTER(fix1373);
174 REGISTER(EnforceInvariants);
175 REGISTER(SortedDirectories);
176 REGISTER(fix1201);
177 REGISTER(fix1512);
178 REGISTER(fix1523);
179 REGISTER(fix1528);
180 REGISTER(fixBatchInnerSigs);
181 // NOLINTEND(readability-identifier-naming)
183};
184
185#undef REGISTER
186
191 std::shared_ptr<data::BackendInterface> backend_;
192
193 std::map<std::string, Amendment> supported_;
194 std::vector<Amendment> all_;
195
196public:
202 explicit AmendmentCenter(std::shared_ptr<data::BackendInterface> const& backend);
203
210 [[nodiscard]] bool
211 isSupported(AmendmentKey const& key) const final;
212
218 [[nodiscard]] std::map<std::string, Amendment> const&
219 getSupported() const final;
220
226 [[nodiscard]] std::vector<Amendment> const&
227 getAll() const final;
228
236 [[nodiscard]] bool
237 isEnabled(AmendmentKey const& key, uint32_t seq) const final;
238
247 [[nodiscard]] bool
248 isEnabled(boost::asio::yield_context yield, AmendmentKey const& key, uint32_t seq) const final;
249
258 [[nodiscard]] std::vector<bool>
259 isEnabled(
260 boost::asio::yield_context yield,
261 std::vector<AmendmentKey> const& keys,
262 uint32_t seq
263 ) const final;
264
271 [[nodiscard]] Amendment const&
272 getAmendment(AmendmentKey const& key) const final;
273
280 [[nodiscard]] Amendment const&
281 operator[](AmendmentKey const& key) const final;
282
283private:
284 [[nodiscard]] std::optional<std::vector<ripple::uint256>>
285 fetchAmendmentsList(boost::asio::yield_context yield, uint32_t seq) const;
286};
287
288} // namespace data
The interface of an amendment center.
Definition AmendmentCenterInterface.hpp:36
Amendment const & getAmendment(AmendmentKey const &key) const final
Get an amendment.
Definition AmendmentCenter.cpp:201
Amendment const & operator[](AmendmentKey const &key) const final
Get an amendment by its key.
Definition AmendmentCenter.cpp:212
bool isEnabled(AmendmentKey const &key, uint32_t seq) const final
Check whether an amendment was/is enabled for a given sequence.
Definition AmendmentCenter.cpp:151
bool isSupported(AmendmentKey const &key) const final
Check whether an amendment is supported by Clio.
Definition AmendmentCenter.cpp:133
std::map< std::string, Amendment > const & getSupported() const final
Get all supported amendments as a map.
Definition AmendmentCenter.cpp:139
AmendmentCenter(std::shared_ptr< data::BackendInterface > const &backend)
Construct a new AmendmentCenter instance.
Definition AmendmentCenter.cpp:107
std::vector< Amendment > const & getAll() const final
Get all known amendments.
Definition AmendmentCenter.cpp:145
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:75
A helper for amendment name to feature conversions.
Definition Types.hpp:304
AmendmentKey(std::convertible_to< std::string > auto &&val)
Construct a new AmendmentKey.
Definition Types.hpp:311
Represents an amendment in the XRPL.
Definition Types.hpp:273
List of supported amendments.
Definition AmendmentCenter.hpp:63