From b91c12c998bb8d7013f143f03b065b9d6e14a233 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Tue, 28 Jan 2025 19:28:09 +0100 Subject: [PATCH 1/2] get_back_transfers docs and disclaimer --- .../developer-reference/sc-api-functions.md | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/docs/developers/developer-reference/sc-api-functions.md b/docs/developers/developer-reference/sc-api-functions.md index c83cb7c3d..bb4461f1b 100644 --- a/docs/developers/developer-reference/sc-api-functions.md +++ b/docs/developers/developer-reference/sc-api-functions.md @@ -140,6 +140,67 @@ A smart contract call that runs out of gas will revert all operations, so this f [comment]: # (mx-context-auto) +### get_back_transfers + +```rust +get_back_transfers() - > BackTransfers +``` + +Retrieves back-transfers from the VM, after a contract call. This functionality is available for both synchoronous calls and asynchronous calls (in callbacks). + +All previous transfers are gathered in the `BackTransfers` struct: + +```rust +/// Holding back-transfer data, as retrieved from the VM. +pub struct BackTransfers +where + A: ManagedTypeApi, +{ + pub total_egld_amount: BigUint, + pub esdt_payments: MultiEsdtPayment, +} + +pub type MultiEsdtPayment = ManagedVec>; +``` + +:::important +The `back_transfers` function retrieves **all** previous transfers **without performing any prior shuffling**. To obtain the exact back transfers corresponding to a specific call when multiple calls are executed, you must explicitly invoke the function after each individual call. +::: + +#### Example +```rust + // SC A + #[endpoint] + fn calls_then_back_transfers( + &self, + to: ManagedAddress, + egld_values: MultiValueEncoded, + ) { + for egld_value in egld_values { + let _back_transfers_after_one_call = self + .tx() + .to(&to) + .typed(contract_proxy::ContractProxy) + .send_back_egld_value(egld_value.clone()) + .returns(ReturnsBackTransfers) + .sync_call(); + } + } + + // SC B + #[endpoint] + fn send_back_egld_value(&self, egld_value: BigUint) { + self.tx().to(ToCaller).egld(egld_value).transfer(); + } +``` + +In this case, the `ReturnsBackTransfers` result handler calls the `get_back_transfers` function from the blockchain API after each call. Otherwise, the same type of call can be executed as such: +```rust + let _back_transfers_after_one_call = self.blockchain().get_back_transfers(); +``` + +[comment]: # (mx-context-auto) + ### get_block_timestamp ```rust From 54a6a87207f4c199f94e773b5a32c776f90a8353 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Wed, 29 Jan 2025 09:14:07 +0100 Subject: [PATCH 2/2] typo --- docs/developers/developer-reference/sc-api-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/developers/developer-reference/sc-api-functions.md b/docs/developers/developer-reference/sc-api-functions.md index bb4461f1b..85e13ab7f 100644 --- a/docs/developers/developer-reference/sc-api-functions.md +++ b/docs/developers/developer-reference/sc-api-functions.md @@ -146,7 +146,7 @@ A smart contract call that runs out of gas will revert all operations, so this f get_back_transfers() - > BackTransfers ``` -Retrieves back-transfers from the VM, after a contract call. This functionality is available for both synchoronous calls and asynchronous calls (in callbacks). +Retrieves back-transfers from the VM, after a contract call. This functionality is available for both synchronous calls and asynchronous calls (in callbacks). All previous transfers are gathered in the `BackTransfers` struct: