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