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 REGISTER(fixInvalidTxFlags);
138 REGISTER(fixFrozenLPTokenTransfer);
139 REGISTER(DeepFreeze);
140
141 // Obsolete but supported by libxrpl
142 REGISTER(CryptoConditionsSuite);
143 REGISTER(NonFungibleTokensV1);
144 REGISTER(fixNFTokenDirV1);
145 REGISTER(fixNFTokenNegOffer);
146
147 // Retired amendments
148 REGISTER(MultiSign);
149 REGISTER(TrustSetAuth);
150 REGISTER(FeeEscalation);
151 REGISTER(PayChan);
152 REGISTER(fix1368);
153 REGISTER(CryptoConditions);
154 REGISTER(Escrow);
155 REGISTER(TickSize);
156 REGISTER(fix1373);
157 REGISTER(EnforceInvariants);
158 REGISTER(SortedDirectories);
159 REGISTER(fix1201);
160 REGISTER(fix1512);
161 REGISTER(fix1523);
162 REGISTER(fix1528);
163 // NOLINTEND(readability-identifier-naming)
165};
166
167#undef REGISTER
168
173 std::shared_ptr<data::BackendInterface> backend_;
174
175 std::map<std::string, Amendment> supported_;
176 std::vector<Amendment> all_;
177
178public:
184 explicit AmendmentCenter(std::shared_ptr<data::BackendInterface> const& backend);
185
192 [[nodiscard]] bool
193 isSupported(AmendmentKey const& key) const final;
194
200 [[nodiscard]] std::map<std::string, Amendment> const&
201 getSupported() const final;
202
208 [[nodiscard]] std::vector<Amendment> const&
209 getAll() const final;
210
218 [[nodiscard]] bool
219 isEnabled(AmendmentKey const& key, uint32_t seq) const final;
220
229 [[nodiscard]] bool
230 isEnabled(boost::asio::yield_context yield, AmendmentKey const& key, uint32_t seq) const final;
231
240 [[nodiscard]] std::vector<bool>
241 isEnabled(boost::asio::yield_context yield, std::vector<AmendmentKey> const& keys, uint32_t seq) const final;
242
249 [[nodiscard]] Amendment const&
250 getAmendment(AmendmentKey const& key) const final;
251
258 [[nodiscard]] Amendment const&
259 operator[](AmendmentKey const& key) const final;
260
261private:
262 [[nodiscard]] std::optional<std::vector<ripple::uint256>>
263 fetchAmendmentsList(boost::asio::yield_context yield, uint32_t seq) const;
264};
265
266} // namespace data
The interface of an amendment center.
Definition AmendmentCenterInterface.hpp:36
Knowledge center for amendments within XRPL.
Definition AmendmentCenter.hpp:172
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