rippled
Loading...
Searching...
No Matches
STXChainBridge.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_PROTOCOL_STXCHAINBRIDGE_H_INCLUDED
21#define RIPPLE_PROTOCOL_STXCHAINBRIDGE_H_INCLUDED
22
23#include <xrpl/basics/CountedObject.h>
24#include <xrpl/protocol/STAccount.h>
25#include <xrpl/protocol/STBase.h>
26#include <xrpl/protocol/STIssue.h>
27
28namespace ripple {
29
30class Serializer;
31class STObject;
32
33class STXChainBridge final : public STBase, public CountedObject<STXChainBridge>
34{
35 STAccount lockingChainDoor_{sfLockingChainDoor};
36 STIssue lockingChainIssue_{sfLockingChainIssue};
37 STAccount issuingChainDoor_{sfIssuingChainDoor};
38 STIssue issuingChainIssue_{sfIssuingChainIssue};
39
40public:
42
43 enum class ChainType { locking, issuing };
44
45 static ChainType
47
48 static ChainType
49 srcChain(bool wasLockingChainSend);
50
51 static ChainType
52 dstChain(bool wasLockingChainSend);
53
55
56 explicit STXChainBridge(SField const& name);
57
58 STXChainBridge(STXChainBridge const& rhs) = default;
59
60 STXChainBridge(STObject const& o);
61
63 AccountID const& srcChainDoor,
64 Issue const& srcChainIssue,
65 AccountID const& dstChainDoor,
66 Issue const& dstChainIssue);
67
68 explicit STXChainBridge(Json::Value const& v);
69
70 explicit STXChainBridge(SField const& name, Json::Value const& v);
71
72 explicit STXChainBridge(SerialIter& sit, SField const& name);
73
75 operator=(STXChainBridge const& rhs) = default;
76
78 getText() const override;
79
81 toSTObject() const;
82
83 AccountID const&
84 lockingChainDoor() const;
85
86 Issue const&
87 lockingChainIssue() const;
88
89 AccountID const&
90 issuingChainDoor() const;
91
92 Issue const&
93 issuingChainIssue() const;
94
95 AccountID const&
96 door(ChainType ct) const;
97
98 Issue const&
99 issue(ChainType ct) const;
100
102 getSType() const override;
103
104 Json::Value getJson(JsonOptions) const override;
105
106 void
107 add(Serializer& s) const override;
108
109 bool
110 isEquivalent(STBase const& t) const override;
111
112 bool
113 isDefault() const override;
114
115 value_type const&
116 value() const noexcept;
117
118private:
119 static std::unique_ptr<STXChainBridge>
120 construct(SerialIter&, SField const& name);
121
122 STBase*
123 copy(std::size_t n, void* buf) const override;
124 STBase*
125 move(std::size_t n, void* buf) override;
126
127 friend bool
128 operator==(STXChainBridge const& lhs, STXChainBridge const& rhs);
129
130 friend bool
131 operator<(STXChainBridge const& lhs, STXChainBridge const& rhs);
132};
133
134inline bool
135operator==(STXChainBridge const& lhs, STXChainBridge const& rhs)
136{
137 return std::tie(
138 lhs.lockingChainDoor_,
139 lhs.lockingChainIssue_,
140 lhs.issuingChainDoor_,
141 lhs.issuingChainIssue_) ==
142 std::tie(
143 rhs.lockingChainDoor_,
144 rhs.lockingChainIssue_,
145 rhs.issuingChainDoor_,
146 rhs.issuingChainIssue_);
147}
148
149inline bool
150operator<(STXChainBridge const& lhs, STXChainBridge const& rhs)
151{
152 return std::tie(
156 lhs.issuingChainIssue_) <
157 std::tie(
162}
163
164inline AccountID const&
169
170inline Issue const&
172{
173 return lockingChainIssue_.value().get<Issue>();
174};
175
176inline AccountID const&
181
182inline Issue const&
184{
185 return issuingChainIssue_.value().get<Issue>();
186};
187
188inline STXChainBridge::value_type const&
189STXChainBridge::value() const noexcept
190{
191 return *this;
192}
193
194inline AccountID const&
196{
197 if (ct == ChainType::locking)
198 return lockingChainDoor();
199 return issuingChainDoor();
200}
201
202inline Issue const&
204{
205 if (ct == ChainType::locking)
206 return lockingChainIssue();
207 return issuingChainIssue();
208}
209
217
219STXChainBridge::srcChain(bool wasLockingChainSend)
220{
221 if (wasLockingChainSend)
222 return ChainType::locking;
223 return ChainType::issuing;
224}
225
227STXChainBridge::dstChain(bool wasLockingChainSend)
228{
229 if (wasLockingChainSend)
230 return ChainType::issuing;
231 return ChainType::locking;
232}
233
234} // namespace ripple
235
236#endif
Represents a JSON value.
Definition json_value.h:149
Tracks the number of instances of an object.
A currency issued by an account.
Definition Issue.h:33
Identifies fields.
Definition SField.h:146
AccountID const & value() const noexcept
Definition STAccount.h:92
A type which can be exported to a well known binary format.
Definition STBase.h:135
value_type const & value() const noexcept
Definition STIssue.h:133
AccountID const & door(ChainType ct) const
bool isEquivalent(STBase const &t) const override
STXChainBridge & operator=(STXChainBridge const &rhs)=default
static ChainType dstChain(bool wasLockingChainSend)
STObject toSTObject() const
STBase * copy(std::size_t n, void *buf) const override
STXChainBridge(STXChainBridge const &rhs)=default
static ChainType srcChain(bool wasLockingChainSend)
AccountID const & issuingChainDoor() const
Issue const & issuingChainIssue() const
value_type const & value() const noexcept
std::string getText() const override
Json::Value getJson(JsonOptions) const override
friend bool operator<(STXChainBridge const &lhs, STXChainBridge const &rhs)
void add(Serializer &s) const override
Issue const & lockingChainIssue() const
SerializedTypeID getSType() const override
bool isDefault() const override
static ChainType otherChain(ChainType ct)
STBase * move(std::size_t n, void *buf) override
static std::unique_ptr< STXChainBridge > construct(SerialIter &, SField const &name)
AccountID const & lockingChainDoor() const
Issue const & issue(ChainType ct) const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
SerializedTypeID
Definition SField.h:110
STL namespace.
Note, should be treated as flags that can be | and &.
Definition STBase.h:37
T tie(T... args)