From 18a6ad3cf8cdcf30e9ab86e13356174105ab04a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Wed, 20 Nov 2024 13:56:25 +0200 Subject: [PATCH 1/2] paymaster: fix transfer_callback --- contracts/paymaster/src/forward_call.rs | 35 +++++++++++-------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/contracts/paymaster/src/forward_call.rs b/contracts/paymaster/src/forward_call.rs index 1f1dbea7..6e5ea9e4 100644 --- a/contracts/paymaster/src/forward_call.rs +++ b/contracts/paymaster/src/forward_call.rs @@ -36,32 +36,29 @@ pub trait ForwardCall { payments: PaymentsVec, #[call_result] result: ManagedAsyncCallResult>, ) -> MultiValueEncoded { - let back_transfers = self.blockchain().get_back_transfers(); - - // Send the original input tokens back to the original caller - if !back_transfers.esdt_payments.is_empty() { - self.tx() - .to(&original_caller) - .payment(&back_transfers.esdt_payments) - .transfer(); - } - if back_transfers.total_egld_amount > 0 { - self.tx() - .to(&original_caller) - .egld(back_transfers.total_egld_amount) - .transfer(); - } - match result { ManagedAsyncCallResult::Ok(return_values) => { + let back_transfers = self.blockchain().get_back_transfers(); + + // Send the original input tokens back to the original caller + if !back_transfers.esdt_payments.is_empty() { + self.tx() + .to(&original_caller) + .payment(&back_transfers.esdt_payments) + .transfer(); + } + if back_transfers.total_egld_amount > 0 { + self.tx() + .to(&original_caller) + .egld(back_transfers.total_egld_amount) + .transfer(); + } // Send the resulted tokens to the original caller return_values } ManagedAsyncCallResult::Err(err) => { - let egld_value = self.call_value().egld_value(); // Send the resulted tokens to the original caller - self.tx().to(&original_caller).payment(&payments).transfer(); - self.tx().to(&original_caller).egld(egld_value).transfer(); + self.tx().to(&original_caller).payment(payments).transfer(); let mut err_result = MultiValueEncoded::new(); err_result.push(ManagedBuffer::new_from_bytes(ERR_CALLBACK_MSG)); From d857fedafa2a18ad59eca85ac3ba7cfb9d77dee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Fri, 22 Nov 2024 13:57:14 +0200 Subject: [PATCH 2/2] paymaster: removed unused variable --- contracts/paymaster/src/forward_call.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/paymaster/src/forward_call.rs b/contracts/paymaster/src/forward_call.rs index 6e5ea9e4..8971d563 100644 --- a/contracts/paymaster/src/forward_call.rs +++ b/contracts/paymaster/src/forward_call.rs @@ -3,7 +3,7 @@ use multiversx_sc::imports::*; pub type PaymentsVec = ManagedVec>; static ERR_CALLBACK_MSG: &[u8] = b"Error received in callback:"; -pub const ESDT_TRANSFER_FUNC_NAME: &str = "ESDTTransfer"; + #[multiversx_sc::module] pub trait ForwardCall { fn forward_call(