Skip to content

Commit

Permalink
paymaster: transfer_callback: handle payments in case of fail
Browse files Browse the repository at this point in the history
  • Loading branch information
CostinCarabas committed Oct 30, 2024
1 parent 2fc0540 commit 8df26a4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions contracts/paymaster/src/forward_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ pub trait ForwardCall {
.to(&dest)
.raw_call(endpoint_name)
.arguments_raw(endpoint_args.to_arg_buffer())
.payment(payments)
.callback(self.callbacks().transfer_callback(original_caller))
.payment(payments.clone())
.callback(
self.callbacks()
.transfer_callback(original_caller, payments),
)
.async_call_and_exit();
}

#[callback]
fn transfer_callback(
&self,
original_caller: ManagedAddress,
payments: PaymentsVec<Self::Api>,
#[call_result] result: ManagedAsyncCallResult<MultiValueEncoded<ManagedBuffer>>,
) -> MultiValueEncoded<ManagedBuffer> {
let back_transfers = self.blockchain().get_back_transfers();
Expand All @@ -54,6 +58,11 @@ pub trait ForwardCall {
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();

let mut err_result = MultiValueEncoded::new();
err_result.push(ManagedBuffer::new_from_bytes(ERR_CALLBACK_MSG));
err_result.push(err.err_msg);
Expand Down

0 comments on commit 8df26a4

Please sign in to comment.