@@ -266,8 +266,8 @@ impl crate::chains::bridge_contracts::BridgeContract<EthAddress> for EthClient {
266
266
// is different as it's initalized with a different ABI. So therefor we must explicitly
267
267
// call the correct one
268
268
match & self . initiator_contract {
269
- InitiatorContract :: Weth ( contract ) => {
270
- let call = contract
269
+ InitiatorContract :: Weth ( weth_contract ) => {
270
+ let call = weth_contract
271
271
. initiateBridgeTransfer (
272
272
U256 :: from ( amount. weth_value ( ) ) ,
273
273
FixedBytes ( recipient_bytes) ,
@@ -286,8 +286,8 @@ impl crate::chains::bridge_contracts::BridgeContract<EthAddress> for EthClient {
286
286
BridgeContractError :: GenericError ( format ! ( "Failed to send transaction: {}" , e) )
287
287
} ) ?;
288
288
}
289
- InitiatorContract :: Move ( contract ) => {
290
- let call = contract
289
+ InitiatorContract :: Move ( move_contract ) => {
290
+ let call = move_contract
291
291
. initiateBridgeTransfer (
292
292
U256 :: from ( amount. weth_value ( ) ) ,
293
293
FixedBytes ( recipient_bytes) ,
@@ -325,20 +325,41 @@ impl crate::chains::bridge_contracts::BridgeContract<EthAddress> for EthClient {
325
325
. try_into ( )
326
326
. map_err ( |_| generic_error ( "Could not convert pre-image to [u8; 32]" ) ) ?;
327
327
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
+
342
363
Ok ( ( ) )
343
364
}
344
365
@@ -357,40 +378,77 @@ impl crate::chains::bridge_contracts::BridgeContract<EthAddress> for EthClient {
357
378
. try_into ( )
358
379
. map_err ( |_| generic_error ( "Could not convert pre-image to [u8; 32]" ) ) ?;
359
380
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
+
374
416
Ok ( ( ) )
375
417
}
376
418
377
419
async fn refund_bridge_transfer (
378
420
& mut self ,
379
421
bridge_transfer_id : BridgeTransferId ,
380
422
) -> 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
+
394
452
Ok ( ( ) )
395
453
}
396
454
@@ -402,47 +460,86 @@ impl crate::chains::bridge_contracts::BridgeContract<EthAddress> for EthClient {
402
460
recipient : BridgeAddress < EthAddress > ,
403
461
amount : Amount ,
404
462
) -> BridgeContractResult < ( ) > {
405
- let contract =
406
- AtomicBridgeCounterparty :: new ( self . counterparty_contract_address ( ) , & self . rpc_provider ) ;
407
463
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
+
426
507
Ok ( ( ) )
427
508
}
428
509
429
510
async fn abort_bridge_transfer (
430
511
& mut self ,
431
512
bridge_transfer_id : BridgeTransferId ,
432
513
) -> 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
+
446
543
Ok ( ( ) )
447
544
}
448
545
0 commit comments