Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Incorrect call_value in callback #1050

Open
janniksam opened this issue Apr 16, 2023 · 2 comments
Open

[BUG] Incorrect call_value in callback #1050

janniksam opened this issue Apr 16, 2023 · 2 comments

Comments

@janniksam
Copy link

janniksam commented Apr 16, 2023

When calling another SC from my SC, when accessing the call_value() inside the callback, the call_value does contain the tokens of the initial call instead of the sent tokens coming from the asynchronously called SC.

I created a minimal reproduction project you can find here (branch: bug/callvalue)
https://github.com/janniksam/mvx_sellnftbug/tree/bug/callvalue

Here are the basic steps, pretty straightforward:

  1. Transfer some EGLD to the endpoint reproduce on the first smart contract
  2. The endpoint reproduce calls the second smart contracts foo endpoint and forward the EGLD to it.
  3. The called second smart contract sends back any ESDT token and returns
  4. The first smart contracts callback foo_callback gets called. When trying to use call_value().single_esdt() inside that callback it will fail.

Is there ANY temporary workaround for this?
I'm currently stuck and cannot proceed, because I definitely need to know the amount I get back from the second SC (which in my real scenario is created by third party).

@andrei-marinica
Copy link
Contributor

The current version of the VM doesn't know how to extract data from transfer-execute calls to provide the call value in the callback. It can only do that if the called contract returns the tokens via another async call.

Using this code causes the tests to pass:

    #[endpoint(foo)]
    #[payable("EGLD")]
    fn foo(&self) {
        let payment = self.payment().get();
        self.send().transfer_esdt_via_async_call(
            self.blockchain().get_caller(),
            payment.token_identifier,
            payment.token_nonce,
            payment.amount,
        );
    }

This limitation will be lifted in the next version of the VM, we are working on it as we speak.

@janniksam
Copy link
Author

Should be fixed with backtransfers, right @andrei-marinica?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants