diff --git a/bridge-proxy/src/bridge-proxy.rs b/bridge-proxy/src/bridge-proxy.rs index f66581d4..14f3ac63 100644 --- a/bridge-proxy/src/bridge-proxy.rs +++ b/bridge-proxy/src/bridge-proxy.rs @@ -122,13 +122,15 @@ pub trait BridgeProxyContract: #[promises_callback] fn execution_callback(&self, #[call_result] result: ManagedAsyncCallResult<()>, tx_id: usize) { if result.is_err() { - self.refund_transaction(tx_id); + let tx = self.get_pending_transaction_by_id(tx_id); + self.refund_transactions(tx_id).set(&tx); } self.cleanup_transaction(tx_id); } + #[endpoint(refundTransaction)] fn refund_transaction(&self, tx_id: usize) { - let tx = self.get_pending_transaction_by_id(tx_id); + let tx = self.refund_transactions(tx_id).get(); let esdt_safe_contract_address = self.get_esdt_safe_address(); let unwrapped_token = self.unwrap_token(&tx.token_id, tx_id); @@ -185,7 +187,8 @@ pub trait BridgeProxyContract: } fn finish_execute_gracefully(&self, tx_id: usize) { - self.refund_transaction(tx_id); + let tx = self.get_pending_transaction_by_id(tx_id); + self.refund_transactions(tx_id).set(&tx); self.cleanup_transaction(tx_id); } diff --git a/bridge-proxy/src/config.rs b/bridge-proxy/src/config.rs index c65aa314..d320a0f2 100644 --- a/bridge-proxy/src/config.rs +++ b/bridge-proxy/src/config.rs @@ -7,6 +7,10 @@ pub trait ConfigModule { #[storage_mapper("pendingTransactions")] fn pending_transactions(&self) -> MapMapper>; + #[view(refundTransactions)] + #[storage_mapper("refundTransactions")] + fn refund_transactions(&self, tx_id: usize) -> SingleValueMapper>; + #[storage_mapper("payments")] fn payments(&self, tx_id: usize) -> SingleValueMapper>; diff --git a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs index 8536cfff..99062aae 100644 --- a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs +++ b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs @@ -760,7 +760,7 @@ fn bridge_proxy_too_small_gas_sc_call_test() { .to(BRIDGE_PROXY_ADDRESS) .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) .get_pending_transaction_by_id(1u32) - .returns(ExpectValue(eth_tx)) + .returns(ExpectValue(eth_tx.clone())) .run(); test.world @@ -771,10 +771,12 @@ fn bridge_proxy_too_small_gas_sc_call_test() { .execute(1u32) .run(); - // Refund: Funds are transfered to EsdtSafe test.world - .check_account(ESDT_SAFE_ADDRESS) - .esdt_balance(BRIDGE_TOKEN_ID, amount.clone()); + .check_account(BRIDGE_PROXY_ADDRESS) + .check_storage("str:refundTransactions|u32:1", "0x30313032303330343035303630373038303931300000000000000000050063726f7766756e64696e675f5f5f5f5f5f5f5f5f5f5f0000000d4252494447452d3132333435360000000201f4000000000000000101000000150000000466756e6400000000000f42400100000000") + .check_storage("str:batchId|u32:1", "1") + .check_storage("str:highestTxId", "1") + .check_storage("str:payments|u32:1", "nested:str:BRIDGE-123456|u64:0|biguint:500"); } #[test] @@ -840,8 +842,10 @@ fn bridge_proxy_empty_endpoint_with_args_test() { .execute(1u32) .run(); - // Refund: Funds are transfered to EsdtSafe test.world - .check_account(ESDT_SAFE_ADDRESS) - .esdt_balance(BRIDGE_TOKEN_ID, amount.clone()); + .check_account(BRIDGE_PROXY_ADDRESS) + .check_storage("str:refundTransactions|u32:1", "0x30313032303330343035303630373038303931300000000000000000050063726f7766756e64696e675f5f5f5f5f5f5f5f5f5f5f0000000d4252494447452d3132333435360000000201f4000000000000000101000000110000000000000000009896800100000000") + .check_storage("str:batchId|u32:1", "1") + .check_storage("str:highestTxId", "1") + .check_storage("str:payments|u32:1", "nested:str:BRIDGE-123456|u64:0|biguint:500"); } diff --git a/bridge-proxy/wasm/src/lib.rs b/bridge-proxy/wasm/src/lib.rs index 97c28d7c..76e2b616 100644 --- a/bridge-proxy/wasm/src/lib.rs +++ b/bridge-proxy/wasm/src/lib.rs @@ -6,10 +6,10 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 8 +// Endpoints: 10 // Async Callback (empty): 1 // Promise callbacks: 1 -// Total number of exported functions: 12 +// Total number of exported functions: 14 #![no_std] @@ -23,8 +23,10 @@ multiversx_sc_wasm_adapter::endpoints! { upgrade => upgrade deposit => deposit execute => execute + refundTransaction => refund_transaction getPendingTransactionById => get_pending_transaction_by_id getPendingTransactions => get_pending_transactions + refundTransactions => refund_transactions highestTxId => highest_tx_id pause => pause_endpoint unpause => unpause_endpoint