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
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 libxrpl.
66 // If an amendment is in the list below it just means Clio did whatever changes needed to support it.
67 // 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
151 // Obsolete but supported by libxrpl
152 REGISTER(CryptoConditionsSuite);
153 REGISTER(NonFungibleTokensV1);
154 REGISTER(fixNFTokenDirV1);
155 REGISTER(fixNFTokenNegOffer);
156
157 // Retired amendments
158 REGISTER(OwnerPaysFee); // Removed in xrpl 2.6.0 (https://github.com/XRPLF/rippled/pull/5435)
159 REGISTER(MultiSign);
160 REGISTER(TrustSetAuth);
161 REGISTER(FeeEscalation);
162 REGISTER(PayChan);
163 REGISTER(fix1368);
164 REGISTER(CryptoConditions);
165 REGISTER(Escrow);
166 REGISTER(TickSize);
167 REGISTER(fix1373);
168 REGISTER(EnforceInvariants);
169 REGISTER(SortedDirectories);
170 REGISTER(fix1201);
171 REGISTER(fix1512);
172 REGISTER(fix1523);
173 REGISTER(fix1528);
174 // NOLINTEND(readability-identifier-naming)
176};
177
178#undef REGISTER
179
184 std::shared_ptr<data::BackendInterface> backend_;
185
186 std::map<std::string, Amendment> supported_;
187 std::vector<Amendment> all_;
188
189public:
195 explicit AmendmentCenter(std::shared_ptr<data::BackendInterface> const& backend);
196
203 [[nodiscard]] bool
204 isSupported(AmendmentKey const& key) const final;
205
211 [[nodiscard]] std::map<std::string, Amendment> const&
212 getSupported() const final;
213
219 [[nodiscard]] std::vector<Amendment> const&
220 getAll() const final;
221
229 [[nodiscard]] bool
230 isEnabled(AmendmentKey const& key, uint32_t seq) const final;
231
240 [[nodiscard]] bool
241 isEnabled(boost::asio::yield_context yield, AmendmentKey const& key, uint32_t seq) const final;
242
251 [[nodiscard]] std::vector<bool>
252 isEnabled(boost::asio::yield_context yield, std::vector<AmendmentKey> const& keys, uint32_t seq) const final;
253
260 [[nodiscard]] Amendment const&
261 getAmendment(AmendmentKey const& key) const final;
262
269 [[nodiscard]] Amendment const&
270 operator[](AmendmentKey const& key) const final;
271
272private:
273 [[nodiscard]] std::optional<std::vector<ripple::uint256>>
274 fetchAmendmentsList(boost::asio::yield_context yield, uint32_t seq) const;
275};
276
277} // namespace data
The interface of an amendment center.
Definition AmendmentCenterInterface.hpp:36
Knowledge center for amendments within XRPL.
Definition AmendmentCenter.hpp:183
Amendment const & getAmendment(AmendmentKey const &key) const final
Get an amendment.
Definition AmendmentCenter.cpp:173
Amendment const & operator[](AmendmentKey const &key) const final
Get an amendment by its key.
Definition AmendmentCenter.cpp:180
bool isEnabled(AmendmentKey const &key, uint32_t seq) const final
Check whether an amendment was/is enabled for a given sequence.
Definition AmendmentCenter.cpp:141
bool isSupported(AmendmentKey const &key) const final
Check whether an amendment is supported by Clio.
Definition AmendmentCenter.cpp:123
std::map< std::string, Amendment > const & getSupported() const final
Get all supported amendments as a map.
Definition AmendmentCenter.cpp:129
AmendmentCenter(std::shared_ptr< data::BackendInterface > const &backend)
Construct a new AmendmentCenter instance.
Definition AmendmentCenter.cpp:99
std::vector< Amendment > const & getAll() const final
Get all known amendments.
Definition AmendmentCenter.cpp:135
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:70
A helper for amendment name to feature conversions.
Definition Types.hpp:286
Represents an amendment in the XRPL.
Definition Types.hpp:255
List of supported amendments.
Definition AmendmentCenter.hpp:63
Definition AmendmentCenter.hpp:54