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(OwnerPaysFee);
72 REGISTER(Flow);
73 REGISTER(FlowCross);
74 REGISTER(fix1513);
75 REGISTER(DepositAuth);
76 REGISTER(Checks);
77 REGISTER(fix1571);
78 REGISTER(fix1543);
79 REGISTER(fix1623);
80 REGISTER(DepositPreauth);
81 REGISTER(fix1515);
82 REGISTER(fix1578);
83 REGISTER(MultiSignReserve);
84 REGISTER(fixTakerDryOfferRemoval);
85 REGISTER(fixMasterKeyAsRegularKey);
86 REGISTER(fixCheckThreading);
87 REGISTER(fixPayChanRecipientOwnerDir);
88 REGISTER(DeletableAccounts);
89 REGISTER(fixQualityUpperBound);
90 REGISTER(RequireFullyCanonicalSig);
91 REGISTER(fix1781);
92 REGISTER(HardenedValidations);
93 REGISTER(fixAmendmentMajorityCalc);
94 REGISTER(NegativeUNL);
95 REGISTER(TicketBatch);
96 REGISTER(FlowSortStrands);
97 REGISTER(fixSTAmountCanonicalize);
98 REGISTER(fixRmSmallIncreasedQOffers);
99 REGISTER(CheckCashMakesTrustLine);
100 REGISTER(ExpandedSignerList);
101 REGISTER(NonFungibleTokensV1_1);
102 REGISTER(fixTrustLinesToSelf);
103 REGISTER(fixRemoveNFTokenAutoTrustLine);
104 REGISTER(ImmediateOfferKilled);
105 REGISTER(DisallowIncoming);
106 REGISTER(XRPFees);
107 REGISTER(fixUniversalNumber);
108 REGISTER(fixNonFungibleTokensV1_2);
109 REGISTER(fixNFTokenRemint);
110 REGISTER(fixReducedOffersV1);
111 REGISTER(Clawback);
112 REGISTER(AMM);
113 REGISTER(XChainBridge);
114 REGISTER(fixDisallowIncomingV1);
115 REGISTER(DID);
116 REGISTER(fixFillOrKill);
117 REGISTER(fixNFTokenReserve);
118 REGISTER(fixInnerObjTemplate);
119 REGISTER(fixAMMOverflowOffer);
120 REGISTER(PriceOracle);
121 REGISTER(fixEmptyDID);
122 REGISTER(fixXChainRewardRounding);
123 REGISTER(fixPreviousTxnID);
124 REGISTER(fixAMMv1_1);
125 REGISTER(NFTokenMintOffer);
126 REGISTER(fixReducedOffersV2);
127 REGISTER(fixEnforceNFTokenTrustline);
128 REGISTER(fixInnerObjTemplate2);
129 REGISTER(fixNFTokenPageLinks);
130 REGISTER(InvariantsV1_1);
131 REGISTER(MPTokensV1);
132 REGISTER(fixAMMv1_2);
133 REGISTER(AMMClawback);
134 REGISTER(Credentials);
135 REGISTER(DynamicNFT);
136 REGISTER(PermissionedDomains);
137
138 // Obsolete but supported by libxrpl
139 REGISTER(CryptoConditionsSuite);
140 REGISTER(NonFungibleTokensV1);
141 REGISTER(fixNFTokenDirV1);
142 REGISTER(fixNFTokenNegOffer);
143
144 // Retired amendments
145 REGISTER(MultiSign);
146 REGISTER(TrustSetAuth);
147 REGISTER(FeeEscalation);
148 REGISTER(PayChan);
149 REGISTER(fix1368);
150 REGISTER(CryptoConditions);
151 REGISTER(Escrow);
152 REGISTER(TickSize);
153 REGISTER(fix1373);
154 REGISTER(EnforceInvariants);
155 REGISTER(SortedDirectories);
156 REGISTER(fix1201);
157 REGISTER(fix1512);
158 REGISTER(fix1523);
159 REGISTER(fix1528);
160 // NOLINTEND(readability-identifier-naming)
162};
163
164#undef REGISTER
165
170 std::shared_ptr<data::BackendInterface> backend_;
171
172 std::map<std::string, Amendment> supported_;
173 std::vector<Amendment> all_;
174
175public:
181 explicit AmendmentCenter(std::shared_ptr<data::BackendInterface> const& backend);
182
189 [[nodiscard]] bool
190 isSupported(AmendmentKey const& key) const final;
191
197 [[nodiscard]] std::map<std::string, Amendment> const&
198 getSupported() const final;
199
205 [[nodiscard]] std::vector<Amendment> const&
206 getAll() const final;
207
215 [[nodiscard]] bool
216 isEnabled(AmendmentKey const& key, uint32_t seq) const final;
217
226 [[nodiscard]] bool
227 isEnabled(boost::asio::yield_context yield, AmendmentKey const& key, uint32_t seq) const final;
228
237 [[nodiscard]] std::vector<bool>
238 isEnabled(boost::asio::yield_context yield, std::vector<AmendmentKey> const& keys, uint32_t seq) const final;
239
246 [[nodiscard]] Amendment const&
247 getAmendment(AmendmentKey const& key) const final;
248
255 [[nodiscard]] Amendment const&
256 operator[](AmendmentKey const& key) const final;
257
258private:
259 [[nodiscard]] std::optional<std::vector<ripple::uint256>>
260 fetchAmendmentsList(boost::asio::yield_context yield, uint32_t seq) const;
261};
262
263} // namespace data
The interface of an amendment center.
Definition AmendmentCenterInterface.hpp:36
Knowledge center for amendments within XRPL.
Definition AmendmentCenter.hpp:169
Amendment const & getAmendment(AmendmentKey const &key) const final
Get an amendment.
Definition AmendmentCenter.cpp:170
Amendment const & operator[](AmendmentKey const &key) const final
Get an amendment by its key.
Definition AmendmentCenter.cpp:177
bool isEnabled(AmendmentKey const &key, uint32_t seq) const final
Check whether an amendment was/is enabled for a given sequence.
Definition AmendmentCenter.cpp:138
bool isSupported(AmendmentKey const &key) const final
Check whether an amendment is supported by Clio.
Definition AmendmentCenter.cpp:120
std::map< std::string, Amendment > const & getSupported() const final
Get all supported amendments as a map.
Definition AmendmentCenter.cpp:126
AmendmentCenter(std::shared_ptr< data::BackendInterface > const &backend)
Construct a new AmendmentCenter instance.
Definition AmendmentCenter.cpp:96
std::vector< Amendment > const & getAll() const final
Get all known amendments.
Definition AmendmentCenter.cpp:132
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