@@ -141,76 +141,66 @@ impl From<Uint<256, 4>> for TimeLock {
141
141
}
142
142
143
143
#[ derive( Deref , DerefMut , Debug , Clone , Copy , PartialEq , Eq ) ]
144
- pub struct Amount ( pub BridgedToken ) ;
145
-
146
- impl Amount {
147
- pub fn weth ( & self ) -> u64 {
148
- match self . 0 {
149
- BridgedToken :: Weth ( value) => value,
150
- BridgedToken :: WethAndEth ( ( weth_value, eth_value) ) => weth_value,
151
- _ => 0 ,
152
- }
153
- }
154
- pub fn eth ( & self ) -> u64 {
155
- match self . 0 {
156
- BridgedToken :: Eth ( value) => value,
157
- BridgedToken :: WethAndEth ( ( weth_value, eth_value) ) => eth_value,
158
- _ => 0 ,
159
- }
160
- }
144
+ pub struct Amount < V > ( pub V ) ;
145
+
146
+ pub enum EthValue {
147
+ Weth ( u64 ) ,
148
+ Eth ( u64 ) ,
149
+ WethAndEth ( ( u64 , u64 ) ) ,
161
150
}
162
151
163
- impl From < Uint < 256 , 4 > > for Amount {
152
+ impl From < Uint < 256 , 4 > > for Amount < EthValue > {
164
153
fn from ( value : Uint < 256 , 4 > ) -> Self {
165
154
// Extract the lower 64 bits.
166
155
let lower_64_bits: u64 = value. as_limbs ( ) [ 0 ] ;
167
- Amount ( BridgedToken :: Eth ( lower_64_bits) )
156
+ //TODO: unit test this for Weth and Eth
157
+ Amount ( EthValue :: Eth ( lower_64_bits) )
168
158
}
169
159
}
170
160
171
161
#[ derive( Debug , PartialEq , Eq , Clone ) ]
172
- pub struct BridgeTransferDetails < A , H > {
162
+ pub struct BridgeTransferDetails < A , H , V > {
173
163
pub bridge_transfer_id : BridgeTransferId < H > ,
174
164
pub initiator_address : InitiatorAddress < A > ,
175
165
pub recipient_address : RecipientAddress < Vec < u8 > > ,
176
166
pub hash_lock : HashLock < H > ,
177
167
pub time_lock : TimeLock ,
178
- pub amount : Amount ,
168
+ pub amount : Amount < V > ,
179
169
}
180
170
181
- impl < A , H > Default for BridgeTransferDetails < A , H > {
171
+ impl < A , H , V > Default for BridgeTransferDetails < A , H , V > {
182
172
fn default ( ) -> Self {
183
173
todo ! ( )
184
174
}
185
175
}
186
176
187
177
#[ derive( Debug , PartialEq , Eq , Clone ) ]
188
- pub struct LockDetails < A , H > {
178
+ pub struct LockDetails < A , H , V > {
189
179
pub bridge_transfer_id : BridgeTransferId < H > ,
190
180
pub initiator_address : InitiatorAddress < Vec < u8 > > ,
191
181
pub recipient_address : RecipientAddress < A > ,
192
182
pub hash_lock : HashLock < H > ,
193
183
pub time_lock : TimeLock ,
194
- pub amount : Amount ,
184
+ pub amount : Amount < V > ,
195
185
}
196
186
197
187
#[ derive( Debug , PartialEq , Eq , Clone ) ]
198
- pub struct CounterpartyCompletedDetails < A , H > {
188
+ pub struct CounterpartyCompletedDetails < A , H , V > {
199
189
pub bridge_transfer_id : BridgeTransferId < H > ,
200
190
pub initiator_address : InitiatorAddress < Vec < u8 > > ,
201
191
pub recipient_address : RecipientAddress < A > ,
202
192
pub hash_lock : HashLock < H > ,
203
193
pub secret : HashLockPreImage ,
204
- pub amount : Amount ,
194
+ pub amount : Amount < V > ,
205
195
}
206
196
207
- impl < A , H > CounterpartyCompletedDetails < A , H >
197
+ impl < A , H , V > CounterpartyCompletedDetails < A , H , V >
208
198
where
209
199
InitiatorAddress < Vec < u8 > > : From < InitiatorAddress < A > > ,
210
200
RecipientAddress < A > : From < RecipientAddress < Vec < u8 > > > ,
211
201
{
212
202
pub fn from_bridge_transfer_details (
213
- bridge_transfer_details : BridgeTransferDetails < A , H > ,
203
+ bridge_transfer_details : BridgeTransferDetails < A , H , V > ,
214
204
secret : HashLockPreImage ,
215
205
) -> Self {
216
206
CounterpartyCompletedDetails {
@@ -224,8 +214,8 @@ where
224
214
}
225
215
}
226
216
227
- impl < A , H > CounterpartyCompletedDetails < A , H > {
228
- pub fn from_lock_details ( lock_details : LockDetails < A , H > , secret : HashLockPreImage ) -> Self {
217
+ impl < A , H , V > CounterpartyCompletedDetails < A , H , V > {
218
+ pub fn from_lock_details ( lock_details : LockDetails < A , H , V > , secret : HashLockPreImage ) -> Self {
229
219
CounterpartyCompletedDetails {
230
220
bridge_transfer_id : lock_details. bridge_transfer_id ,
231
221
initiator_address : lock_details. initiator_address ,
@@ -243,6 +233,7 @@ pub trait BridgeAddressType:
243
233
Debug + PartialEq + Eq + Hash + Unpin + Send + Sync + Clone + From < Vec < u8 > >
244
234
{
245
235
}
236
+ pub trait BridgeValueType : Debug + PartialEq + Eq + Clone + Send + Sync + Unpin { }
246
237
247
238
pub trait Convert < O > {
248
239
fn convert ( other : & Self ) -> O ;
0 commit comments