Skip to content

Commit 249228a

Browse files
committed
update: client calls with match arms
1 parent e71d816 commit 249228a

File tree

1 file changed

+175
-78
lines changed
  • protocol-units/bridge/service/src/chains/ethereum

1 file changed

+175
-78
lines changed

protocol-units/bridge/service/src/chains/ethereum/client.rs

+175-78
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ impl crate::chains::bridge_contracts::BridgeContract<EthAddress> for EthClient {
266266
// is different as it's initalized with a different ABI. So therefor we must explicitly
267267
// call the correct one
268268
match &self.initiator_contract {
269-
InitiatorContract::Weth(contract) => {
270-
let call = contract
269+
InitiatorContract::Weth(weth_contract) => {
270+
let call = weth_contract
271271
.initiateBridgeTransfer(
272272
U256::from(amount.weth_value()),
273273
FixedBytes(recipient_bytes),
@@ -286,8 +286,8 @@ impl crate::chains::bridge_contracts::BridgeContract<EthAddress> for EthClient {
286286
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
287287
})?;
288288
}
289-
InitiatorContract::Move(contract) => {
290-
let call = contract
289+
InitiatorContract::Move(move_contract) => {
290+
let call = move_contract
291291
.initiateBridgeTransfer(
292292
U256::from(amount.weth_value()),
293293
FixedBytes(recipient_bytes),
@@ -325,20 +325,41 @@ impl crate::chains::bridge_contracts::BridgeContract<EthAddress> for EthClient {
325325
.try_into()
326326
.map_err(|_| generic_error("Could not convert pre-image to [u8; 32]"))?;
327327
info! {"Pre-image: {:?}", pre_image};
328-
let contract =
329-
AtomicBridgeInitiator::new(self.initiator_contract_address(), &self.rpc_provider);
330-
let call = contract
331-
.completeBridgeTransfer(FixedBytes(bridge_transfer_id.0), FixedBytes(pre_image));
332-
send_transaction(
333-
call,
334-
&send_transaction_rules(),
335-
self.config.transaction_send_retries,
336-
self.config.gas_limit,
337-
)
338-
.await
339-
.map_err(|e| {
340-
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
341-
})?;
328+
match &self.initiator_contract {
329+
InitiatorContract::Weth(weth_contract) => {
330+
let call = weth_contract.completeBridgeTransfer(
331+
FixedBytes(bridge_transfer_id.0),
332+
FixedBytes(pre_image),
333+
);
334+
send_transaction(
335+
call,
336+
&send_transaction_rules(),
337+
self.config.transaction_send_retries,
338+
self.config.gas_limit,
339+
)
340+
.await
341+
.map_err(|e| {
342+
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
343+
})?;
344+
}
345+
InitiatorContract::Move(move_contract) => {
346+
let call = move_contract.completeBridgeTransfer(
347+
FixedBytes(bridge_transfer_id.0),
348+
FixedBytes(pre_image),
349+
);
350+
send_transaction(
351+
call,
352+
&send_transaction_rules(),
353+
self.config.transaction_send_retries,
354+
self.config.gas_limit,
355+
)
356+
.await
357+
.map_err(|e| {
358+
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
359+
})?;
360+
}
361+
}
362+
342363
Ok(())
343364
}
344365

@@ -357,40 +378,77 @@ impl crate::chains::bridge_contracts::BridgeContract<EthAddress> for EthClient {
357378
.try_into()
358379
.map_err(|_| generic_error("Could not convert pre-image to [u8; 32]"))?;
359380

360-
let contract =
361-
AtomicBridgeCounterparty::new(self.counterparty_contract_address(), &self.rpc_provider);
362-
let call = contract
363-
.completeBridgeTransfer(FixedBytes(bridge_transfer_id.0), FixedBytes(pre_image));
364-
send_transaction(
365-
call,
366-
&send_transaction_rules(),
367-
self.config.transaction_send_retries,
368-
self.config.gas_limit,
369-
)
370-
.await
371-
.map_err(|e| {
372-
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
373-
})?;
381+
match &self.counterparty_contract {
382+
CounterpartyContract::Weth(weth_contract) => {
383+
let call = weth_contract.completeBridgeTransfer(
384+
FixedBytes(bridge_transfer_id.0),
385+
FixedBytes(pre_image),
386+
);
387+
send_transaction(
388+
call,
389+
&send_transaction_rules(),
390+
self.config.transaction_send_retries,
391+
self.config.gas_limit,
392+
)
393+
.await
394+
.map_err(|e| {
395+
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
396+
})?;
397+
}
398+
CounterpartyContract::Move(move_contract) => {
399+
let call = move_contract.completeBridgeTransfer(
400+
FixedBytes(bridge_transfer_id.0),
401+
FixedBytes(pre_image),
402+
);
403+
send_transaction(
404+
call,
405+
&send_transaction_rules(),
406+
self.config.transaction_send_retries,
407+
self.config.gas_limit,
408+
)
409+
.await
410+
.map_err(|e| {
411+
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
412+
})?;
413+
}
414+
}
415+
374416
Ok(())
375417
}
376418

377419
async fn refund_bridge_transfer(
378420
&mut self,
379421
bridge_transfer_id: BridgeTransferId,
380422
) -> BridgeContractResult<()> {
381-
let contract =
382-
AtomicBridgeInitiator::new(self.initiator_contract_address(), &self.rpc_provider);
383-
let call = contract.refundBridgeTransfer(FixedBytes(bridge_transfer_id.0));
384-
send_transaction(
385-
call,
386-
&send_transaction_rules(),
387-
self.config.transaction_send_retries,
388-
self.config.gas_limit,
389-
)
390-
.await
391-
.map_err(|e| {
392-
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
393-
})?;
423+
match &self.initiator_contract {
424+
InitiatorContract::Weth(weth_contract) => {
425+
let call = weth_contract.refundBridgeTransfer(FixedBytes(bridge_transfer_id.0));
426+
send_transaction(
427+
call,
428+
&send_transaction_rules(),
429+
self.config.transaction_send_retries,
430+
self.config.gas_limit,
431+
)
432+
.await
433+
.map_err(|e| {
434+
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
435+
})?;
436+
}
437+
InitiatorContract::Move(move_contract) => {
438+
let call = move_contract.refundBridgeTransfer(FixedBytes(bridge_transfer_id.0));
439+
send_transaction(
440+
call,
441+
&send_transaction_rules(),
442+
self.config.transaction_send_retries,
443+
self.config.gas_limit,
444+
)
445+
.await
446+
.map_err(|e| {
447+
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
448+
})?;
449+
}
450+
}
451+
394452
Ok(())
395453
}
396454

@@ -402,47 +460,86 @@ impl crate::chains::bridge_contracts::BridgeContract<EthAddress> for EthClient {
402460
recipient: BridgeAddress<EthAddress>,
403461
amount: Amount,
404462
) -> BridgeContractResult<()> {
405-
let contract =
406-
AtomicBridgeCounterparty::new(self.counterparty_contract_address(), &self.rpc_provider);
407463
let initiator: [u8; 32] = initiator.0.try_into().unwrap();
408-
let call = contract.lockBridgeTransfer(
409-
FixedBytes(initiator),
410-
FixedBytes(bridge_transfer_id.0),
411-
FixedBytes(hash_lock.0),
412-
*recipient.0,
413-
U256::try_from(amount.0)
414-
.map_err(|_| BridgeContractError::ConversionFailed("U256".to_string()))?,
415-
);
416-
send_transaction(
417-
call,
418-
&send_transaction_rules(),
419-
self.config.transaction_send_retries,
420-
self.config.gas_limit,
421-
)
422-
.await
423-
.map_err(|e| {
424-
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
425-
})?;
464+
match &self.counterparty_contract {
465+
CounterpartyContract::Weth(weth_contract) => {
466+
let call = weth_contract.lockBridgeTransfer(
467+
FixedBytes(initiator),
468+
FixedBytes(bridge_transfer_id.0),
469+
FixedBytes(hash_lock.0),
470+
*recipient.0,
471+
U256::try_from(amount.0)
472+
.map_err(|_| BridgeContractError::ConversionFailed("U256".to_string()))?,
473+
);
474+
send_transaction(
475+
call,
476+
&send_transaction_rules(),
477+
self.config.transaction_send_retries,
478+
self.config.gas_limit,
479+
)
480+
.await
481+
.map_err(|e| {
482+
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
483+
})?;
484+
}
485+
CounterpartyContract::Move(move_contract) => {
486+
let call = move_contract.lockBridgeTransfer(
487+
FixedBytes(initiator),
488+
FixedBytes(bridge_transfer_id.0),
489+
FixedBytes(hash_lock.0),
490+
*recipient.0,
491+
U256::try_from(amount.0)
492+
.map_err(|_| BridgeContractError::ConversionFailed("U256".to_string()))?,
493+
);
494+
send_transaction(
495+
call,
496+
&send_transaction_rules(),
497+
self.config.transaction_send_retries,
498+
self.config.gas_limit,
499+
)
500+
.await
501+
.map_err(|e| {
502+
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
503+
})?;
504+
}
505+
}
506+
426507
Ok(())
427508
}
428509

429510
async fn abort_bridge_transfer(
430511
&mut self,
431512
bridge_transfer_id: BridgeTransferId,
432513
) -> BridgeContractResult<()> {
433-
let contract =
434-
AtomicBridgeCounterparty::new(self.counterparty_contract_address(), &self.rpc_provider);
435-
let call = contract.abortBridgeTransfer(FixedBytes(bridge_transfer_id.0));
436-
send_transaction(
437-
call,
438-
&send_transaction_rules(),
439-
self.config.transaction_send_retries,
440-
self.config.gas_limit,
441-
)
442-
.await
443-
.map_err(|e| {
444-
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
445-
})?;
514+
match &self.counterparty_contract {
515+
CounterpartyContract::Weth(weth_contract) => {
516+
let call = weth_contract.abortBridgeTransfer(FixedBytes(bridge_transfer_id.0));
517+
send_transaction(
518+
call,
519+
&send_transaction_rules(),
520+
self.config.transaction_send_retries,
521+
self.config.gas_limit,
522+
)
523+
.await
524+
.map_err(|e| {
525+
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
526+
})?;
527+
}
528+
CounterpartyContract::Move(move_contract) => {
529+
let call = move_contract.abortBridgeTransfer(FixedBytes(bridge_transfer_id.0));
530+
send_transaction(
531+
call,
532+
&send_transaction_rules(),
533+
self.config.transaction_send_retries,
534+
self.config.gas_limit,
535+
)
536+
.await
537+
.map_err(|e| {
538+
BridgeContractError::GenericError(format!("Failed to send transaction: {}", e))
539+
})?;
540+
}
541+
}
542+
446543
Ok(())
447544
}
448545

0 commit comments

Comments
 (0)