xrpld
Loading...
Searching...
No Matches
XChainBridge.h
1#pragma once
2
3#include <xrpl/beast/utility/Journal.h>
4#include <xrpl/core/ServiceRegistry.h>
5#include <xrpl/ledger/ReadView.h>
6#include <xrpl/protocol/STTx.h>
7#include <xrpl/protocol/TER.h>
8#include <xrpl/protocol/XRPAmount.h>
9#include <xrpl/tx/ApplyContext.h>
10#include <xrpl/tx/Transactor.h>
11
12#include <cstddef>
13#include <cstdint>
14
15namespace xrpl {
16
17constexpr size_t kXbridgeMaxAccountCreateClaims = 128;
18
19// Attach a new bridge to a door account. Once this is done, the cross-chain
20// transfer transactions may be used to transfer funds from this account.
22{
23public:
25
27 {
28 }
29
30 static NotTEC
31 preflight(PreflightContext const& ctx);
32
33 static TER
34 preclaim(PreclaimContext const& ctx);
35
36 TER
37 doApply() override;
38
39 void
40 visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override;
41
42 [[nodiscard]] bool
44 STTx const& tx,
45 TER result,
46 XRPAmount fee,
47 ReadView const& view,
48 beast::Journal const& j) override;
49};
50
52{
53public:
55
56 explicit BridgeModify(ApplyContext& ctx) : Transactor(ctx)
57 {
58 }
59
60 static std::uint32_t
62
63 static NotTEC
64 preflight(PreflightContext const& ctx);
65
66 static TER
67 preclaim(PreclaimContext const& ctx);
68
69 TER
70 doApply() override;
71
72 void
73 visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override;
74
75 [[nodiscard]] bool
77 STTx const& tx,
78 TER result,
79 XRPAmount fee,
80 ReadView const& view,
81 beast::Journal const& j) override;
82};
83
85
86//------------------------------------------------------------------------------
87
88// Claim funds from a `XChainCommit` transaction. This is normally not needed,
89// but may be used to handle transaction failures or if the destination account
90// was not specified in the `XChainCommit` transaction. It may only be used
91// after a quorum of signatures have been sent from the witness servers.
92//
93// If the transaction succeeds in moving funds, the referenced `XChainClaimID`
94// ledger object will be destroyed. This prevents transaction replay. If the
95// transaction fails, the `XChainClaimID` will not be destroyed and the
96// transaction may be re-run with different parameters.
97class XChainClaim : public Transactor
98{
99public:
100 // Blocker since we cannot accurately calculate the consequences
102
103 explicit XChainClaim(ApplyContext& ctx) : Transactor(ctx)
104 {
105 }
106
107 static NotTEC
108 preflight(PreflightContext const& ctx);
109
110 static TER
111 preclaim(PreclaimContext const& ctx);
112
113 TER
114 doApply() override;
115
116 void
117 visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override;
118
119 [[nodiscard]] bool
121 STTx const& tx,
122 TER result,
123 XRPAmount fee,
124 ReadView const& view,
125 beast::Journal const& j) override;
126};
127
128//------------------------------------------------------------------------------
129
130// Put assets into trust on the locking-chain so they may be wrapped on the
131// issuing-chain, or return wrapped assets on the issuing-chain so they can be
132// unlocked on the locking-chain. The second step in a cross-chain transfer.
134{
135public:
137
138 static TxConsequences
140
142 {
143 }
144
145 static NotTEC
146 preflight(PreflightContext const& ctx);
147
148 static TER
149 preclaim(PreclaimContext const& ctx);
150
151 TER
152 doApply() override;
153
154 void
155 visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override;
156
157 [[nodiscard]] bool
159 STTx const& tx,
160 TER result,
161 XRPAmount fee,
162 ReadView const& view,
163 beast::Journal const& j) override;
164};
165
166//------------------------------------------------------------------------------
167
168// Create a new claim id owned by the account. This is the first step in a
169// cross-chain transfer. The claim id must be created on the destination chain
170// before the `XChainCommit` transaction (which must reference this number) can
171// be sent on the source chain. The account that will send the `XChainCommit` on
172// the source chain must be specified in this transaction (see note on the
173// `SourceAccount` field in the `XChainClaimID` ledger object for
174// justification). The actual sequence number must be retrieved from a validated
175// ledger.
177{
178public:
180
182 {
183 }
184
185 static NotTEC
186 preflight(PreflightContext const& ctx);
187
188 static TER
189 preclaim(PreclaimContext const& ctx);
190
191 TER
192 doApply() override;
193
194 void
195 visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override;
196
197 [[nodiscard]] bool
199 STTx const& tx,
200 TER result,
201 XRPAmount fee,
202 ReadView const& view,
203 beast::Journal const& j) override;
204};
205
206//------------------------------------------------------------------------------
207
208// Provide attestations from a witness server attesting to events on
209// the other chain. The signatures must be from one of the keys on the door's
210// signer's list at the time the signature was provided. However, if the
211// signature list changes between the time the signature was submitted and the
212// quorum is reached, the new signature set is used and some of the currently
213// collected signatures may be removed. Also note the reward is only sent to
214// accounts that have keys on the current list.
216{
217public:
218 // Blocker since we cannot accurately calculate the consequences
220
222 {
223 }
224
225 static NotTEC
226 preflight(PreflightContext const& ctx);
227
228 static TER
229 preclaim(PreclaimContext const& ctx);
230
231 TER
232 doApply() override;
233
234 void
235 visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override;
236
237 [[nodiscard]] bool
239 STTx const& tx,
240 TER result,
241 XRPAmount fee,
242 ReadView const& view,
243 beast::Journal const& j) override;
244};
245
247{
248public:
249 // Blocker since we cannot accurately calculate the consequences
251
255
256 static NotTEC
257 preflight(PreflightContext const& ctx);
258
259 static TER
260 preclaim(PreclaimContext const& ctx);
261
262 TER
263 doApply() override;
264
265 void
266 visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override;
267
268 [[nodiscard]] bool
270 STTx const& tx,
271 TER result,
272 XRPAmount fee,
273 ReadView const& view,
274 beast::Journal const& j) override;
275};
276
277//------------------------------------------------------------------------------
278
279// This is a special transaction used for creating accounts through a
280// cross-chain transfer. A normal cross-chain transfer requires a "chain claim
281// id" (which requires an existing account on the destination chain). One
282// purpose of the "chain claim id" is to prevent transaction replay. For this
283// transaction, we use a different mechanism: the accounts must be claimed on
284// the destination chain in the same order that the `XChainCreateAccountCommit`
285// transactions occurred on the source chain.
286//
287// This transaction can only be used for XRP to XRP bridges.
288//
289// IMPORTANT: This transaction should only be enabled if the witness
290// attestations will be reliably delivered to the destination chain. If the
291// signatures are not delivered (for example, the chain relies on user wallets
292// to collect signatures) then account creation would be blocked for all
293// transactions that happened after the one waiting on attestations. This could
294// be used maliciously. To disable this transaction on XRP to XRP bridges, the
295// bridge's `MinAccountCreateAmount` should not be present.
296//
297// Note: If this account already exists, the XRP is transferred to the existing
298// account. However, note that unlike the `XChainCommit` transaction, there is
299// no error handling mechanism. If the claim transaction fails, there is no
300// mechanism for refunds. The funds are permanently lost. This transaction
301// should still only be used for account creation.
303{
304public:
306
308 {
309 }
310
311 static NotTEC
312 preflight(PreflightContext const& ctx);
313
314 static TER
315 preclaim(PreclaimContext const& ctx);
316
317 TER
318 doApply() override;
319
320 void
321 visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override;
322
323 [[nodiscard]] bool
325 STTx const& tx,
326 TER result,
327 XRPAmount fee,
328 ReadView const& view,
329 beast::Journal const& j) override;
330};
331
333
334//------------------------------------------------------------------------------
335
336} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
State information when applying a tx.
TER doApply() override
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
BridgeModify(ApplyContext &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
static constexpr auto kConsequencesFactory
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
A view into a ledger.
Definition ReadView.h:41
std::shared_ptr< STLedgerEntry const > const & const_ref
ApplyView & view()
Definition Transactor.h:175
Transactor(Transactor const &)=delete
Class describing the consequences to the account of applying a transaction if the transaction consume...
Definition applySteps.h:52
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
XChainAddAccountCreateAttestation(ApplyContext &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
static constexpr auto kConsequencesFactory
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
XChainAddClaimAttestation(ApplyContext &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static constexpr auto kConsequencesFactory
XChainClaim(ApplyContext &ctx)
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static TER preclaim(PreclaimContext const &ctx)
TER doApply() override
static constexpr auto kConsequencesFactory
static NotTEC preflight(PreflightContext const &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
XChainCommit(ApplyContext &ctx)
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
TER doApply() override
static constexpr auto kConsequencesFactory
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
static constexpr auto kConsequencesFactory
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
XChainCreateAccountCommit(ApplyContext &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
static constexpr auto kConsequencesFactory
XChainCreateBridge(ApplyContext &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static constexpr auto kConsequencesFactory
XChainCreateClaimID(ApplyContext &ctx)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
BridgeModify XChainModifyBridge
constexpr size_t kXbridgeMaxAccountCreateClaims
XChainCreateAccountCommit XChainAccountCreateCommit
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:607
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:572
TERSubset< CanCvtToTER > TER
Definition TER.h:647
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:83
State information when preflighting a tx.
Definition Transactor.h:38