rippled
Loading...
Searching...
No Matches
XChainBridge.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2022 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or 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#ifndef RIPPLE_TX_XCHAINBRIDGE_H_INCLUDED
21#define RIPPLE_TX_XCHAINBRIDGE_H_INCLUDED
22
23#include <xrpld/app/tx/detail/Transactor.h>
24
25#include <xrpl/protocol/XChainAttestations.h>
26
27namespace ripple {
28
29constexpr size_t xbridgeMaxAccountCreateClaims = 128;
30
31// Attach a new bridge to a door account. Once this is done, the cross-chain
32// transfer transactions may be used to transfer funds from this account.
34{
35public:
37
39 {
40 }
41
42 static NotTEC
43 preflight(PreflightContext const& ctx);
44
45 static TER
46 preclaim(PreclaimContext const& ctx);
47
48 TER
49 doApply() override;
50};
51
53{
54public:
56
57 explicit BridgeModify(ApplyContext& ctx) : Transactor(ctx)
58 {
59 }
60
61 static NotTEC
62 preflight(PreflightContext const& ctx);
63
64 static TER
65 preclaim(PreclaimContext const& ctx);
66
67 TER
68 doApply() override;
69};
70
72
73//------------------------------------------------------------------------------
74
75// Claim funds from a `XChainCommit` transaction. This is normally not needed,
76// but may be used to handle transaction failures or if the destination account
77// was not specified in the `XChainCommit` transaction. It may only be used
78// after a quorum of signatures have been sent from the witness servers.
79//
80// If the transaction succeeds in moving funds, the referenced `XChainClaimID`
81// ledger object will be destroyed. This prevents transaction replay. If the
82// transaction fails, the `XChainClaimID` will not be destroyed and the
83// transaction may be re-run with different parameters.
84class XChainClaim : public Transactor
85{
86public:
87 // Blocker since we cannot accurately calculate the consequences
89
90 explicit XChainClaim(ApplyContext& ctx) : Transactor(ctx)
91 {
92 }
93
94 static NotTEC
95 preflight(PreflightContext const& ctx);
96
97 static TER
98 preclaim(PreclaimContext const& ctx);
99
100 TER
101 doApply() override;
102};
103
104//------------------------------------------------------------------------------
105
106// Put assets into trust on the locking-chain so they may be wrapped on the
107// issuing-chain, or return wrapped assets on the issuing-chain so they can be
108// unlocked on the locking-chain. The second step in a cross-chain transfer.
110{
111public:
113
114 static TxConsequences
116
118 {
119 }
120
121 static NotTEC
122 preflight(PreflightContext const& ctx);
123
124 static TER
125 preclaim(PreclaimContext const& ctx);
126
127 TER
128 doApply() override;
129};
130
131//------------------------------------------------------------------------------
132
133// Create a new claim id owned by the account. This is the first step in a
134// cross-chain transfer. The claim id must be created on the destination chain
135// before the `XChainCommit` transaction (which must reference this number) can
136// be sent on the source chain. The account that will send the `XChainCommit` on
137// the source chain must be specified in this transaction (see note on the
138// `SourceAccount` field in the `XChainClaimID` ledger object for
139// justification). The actual sequence number must be retrieved from a validated
140// ledger.
142{
143public:
145
147 {
148 }
149
150 static NotTEC
151 preflight(PreflightContext const& ctx);
152
153 static TER
154 preclaim(PreclaimContext const& ctx);
155
156 TER
157 doApply() override;
158};
159
160//------------------------------------------------------------------------------
161
162// Provide attestations from a witness server attesting to events on
163// the other chain. The signatures must be from one of the keys on the door's
164// signer's list at the time the signature was provided. However, if the
165// signature list changes between the time the signature was submitted and the
166// quorum is reached, the new signature set is used and some of the currently
167// collected signatures may be removed. Also note the reward is only sent to
168// accounts that have keys on the current list.
170{
171public:
172 // Blocker since we cannot accurately calculate the consequences
174
176 {
177 }
178
179 static NotTEC
180 preflight(PreflightContext const& ctx);
181
182 static TER
183 preclaim(PreclaimContext const& ctx);
184
185 TER
186 doApply() override;
187};
188
190{
191public:
192 // Blocker since we cannot accurately calculate the consequences
194
196 : Transactor(ctx)
197 {
198 }
199
200 static NotTEC
201 preflight(PreflightContext const& ctx);
202
203 static TER
204 preclaim(PreclaimContext const& ctx);
205
206 TER
207 doApply() override;
208};
209
210//------------------------------------------------------------------------------
211
212// This is a special transaction used for creating accounts through a
213// cross-chain transfer. A normal cross-chain transfer requires a "chain claim
214// id" (which requires an existing account on the destination chain). One
215// purpose of the "chain claim id" is to prevent transaction replay. For this
216// transaction, we use a different mechanism: the accounts must be claimed on
217// the destination chain in the same order that the `XChainCreateAccountCommit`
218// transactions occurred on the source chain.
219//
220// This transaction can only be used for XRP to XRP bridges.
221//
222// IMPORTANT: This transaction should only be enabled if the witness
223// attestations will be reliably delivered to the destination chain. If the
224// signatures are not delivered (for example, the chain relies on user wallets
225// to collect signatures) then account creation would be blocked for all
226// transactions that happened after the one waiting on attestations. This could
227// be used maliciously. To disable this transaction on XRP to XRP bridges, the
228// bridge's `MinAccountCreateAmount` should not be present.
229//
230// Note: If this account already exists, the XRP is transferred to the existing
231// account. However, note that unlike the `XChainCommit` transaction, there is
232// no error handling mechanism. If the claim transaction fails, there is no
233// mechanism for refunds. The funds are permanently lost. This transaction
234// should still only be used for account creation.
236{
237public:
239
241 {
242 }
243
244 static NotTEC
245 preflight(PreflightContext const& ctx);
246
247 static TER
248 preclaim(PreclaimContext const& ctx);
249
250 TER
251 doApply() override;
252};
253
255
256//------------------------------------------------------------------------------
257
258} // namespace ripple
259
260#endif
State information when applying a tx.
BridgeModify(ApplyContext &ctx)
static constexpr ConsequencesFactoryType ConsequencesFactory
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
Class describing the consequences to the account of applying a transaction if the transaction consume...
Definition applySteps.h:58
static constexpr ConsequencesFactoryType ConsequencesFactory
static TER preclaim(PreclaimContext const &ctx)
XChainAddAccountCreateAttestation(ApplyContext &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
XChainAddClaimAttestation(ApplyContext &ctx)
static constexpr ConsequencesFactoryType ConsequencesFactory
static constexpr ConsequencesFactoryType ConsequencesFactory
static TER preclaim(PreclaimContext const &ctx)
XChainClaim(ApplyContext &ctx)
static NotTEC preflight(PreflightContext const &ctx)
TER doApply() override
XChainCommit(ApplyContext &ctx)
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
static constexpr ConsequencesFactoryType ConsequencesFactory
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static constexpr ConsequencesFactoryType ConsequencesFactory
static TER preclaim(PreclaimContext const &ctx)
XChainCreateAccountCommit(ApplyContext &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static constexpr ConsequencesFactoryType ConsequencesFactory
static NotTEC preflight(PreflightContext const &ctx)
XChainCreateBridge(ApplyContext &ctx)
static constexpr ConsequencesFactoryType ConsequencesFactory
XChainCreateClaimID(ApplyContext &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
constexpr size_t xbridgeMaxAccountCreateClaims
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:80
State information when preflighting a tx.
Definition Transactor.h:35