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 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 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 // NOLINTEND(readability-identifier-naming)
182};
183
184#undef REGISTER
185
190 std::shared_ptr<data::BackendInterface> backend_;
191
192 std::map<std::string, Amendment> supported_;
193 std::vector<Amendment> all_;
194
195public:
201 explicit AmendmentCenter(std::shared_ptr<data::BackendInterface> const& backend);
202
209 [[nodiscard]] bool
210 isSupported(AmendmentKey const& key) const final;
211
217 [[nodiscard]] std::map<std::string, Amendment> const&
218 getSupported() const final;
219
225 [[nodiscard]] std::vector<Amendment> const&
226 getAll() const final;
227
235 [[nodiscard]] bool
236 isEnabled(AmendmentKey const& key, uint32_t seq) const final;
237
246 [[nodiscard]] bool
247 isEnabled(boost::asio::yield_context yield, AmendmentKey const& key, uint32_t seq) const final;
248
257 [[nodiscard]] std::vector<bool>
258 isEnabled(boost::asio::yield_context yield, std::vector<AmendmentKey> const& keys, uint32_t seq) const final;
259
266 [[nodiscard]] Amendment const&
267 getAmendment(AmendmentKey const& key) const final;
268
275 [[nodiscard]] Amendment const&
276 operator[](AmendmentKey const& key) const final;
277
278private:
279 [[nodiscard]] std::optional<std::vector<ripple::uint256>>
280 fetchAmendmentsList(boost::asio::yield_context yield, uint32_t seq) const;
281};
282
283} // 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: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:289
AmendmentKey(std::convertible_to< std::string > auto &&val)
Construct a new AmendmentKey.
Definition Types.hpp:296
Represents an amendment in the XRPL.
Definition Types.hpp:258
List of supported amendments.
Definition AmendmentCenter.hpp:63