Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
multiversx_sc::imports!();
use multiversx_sc::imports::*;

use crate::{
common::{self, CallbackData},
Expand Down Expand Up @@ -85,6 +85,39 @@ pub trait CallPromisesModule: common::CommonModule {
.register_promise();
}

#[endpoint]
#[payable("*")]
fn forward_payment_gas_for_raw_async_callback(
&self,
to: ManagedAddress,
original_caller: ManagedAddress,
value: BigUint,
) {
self.promise_check().set(value);
let payment = self.call_value().any_payment();
let half_gas = self.blockchain().get_gas_left() / 3;

self.tx()
.to(&to)
.gas(half_gas)
.payment(payment)
.callback(self.callbacks().raw_async_callback(original_caller))
.gas_for_callback(half_gas)
.register_promise();
}

#[promises_callback]
fn raw_async_callback(
&self,
original_caller: ManagedAddress,
#[call_result] _result: ManagedAsyncCallResult<IgnoreValue>,
) {
let egld_amount = self.call_value().egld_direct_non_strict().clone_value();
self.error_check().set(BigUint::from(33u64));
self.send()
.direct_non_zero_egld(&original_caller, &egld_amount);
}

#[promises_callback]
fn transfer_callback(&self, #[call_result] result: MultiValueEncoded<ManagedBuffer>) {
self.callback_result(result);
Expand Down Expand Up @@ -116,4 +149,12 @@ pub trait CallPromisesModule: common::CommonModule {
},
}
}

#[view(errorCheck)]
#[storage_mapper("errorCheck")]
fn error_check(&self) -> SingleValueMapper<BigUint>;

#[view(promiseCheck)]
#[storage_mapper("promiseCheck")]
fn promise_check(&self) -> SingleValueMapper<BigUint>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 14
// Endpoints: 17
// Async Callback (empty): 1
// Promise callbacks: 5
// Total number of exported functions: 21
// Promise callbacks: 6
// Total number of exported functions: 25

#![no_std]

Expand All @@ -26,6 +26,9 @@ multiversx_sc_wasm_adapter::endpoints! {
forward_promise_retrieve_funds => forward_promise_retrieve_funds
forward_payment_callback => forward_payment_callback
forward_payment_gas_for_callback => forward_payment_gas_for_callback
forward_payment_gas_for_raw_async_callback => forward_payment_gas_for_raw_async_callback
errorCheck => error_check
promiseCheck => promise_check
promise_raw_single_token_to_user => promise_raw_single_token_to_user
promise_raw_single_token => promise_raw_single_token
promise_raw_multi_transfer => promise_raw_multi_transfer
Expand All @@ -34,6 +37,7 @@ multiversx_sc_wasm_adapter::endpoints! {
forward_sync_retrieve_funds_bt_twice => forward_sync_retrieve_funds_bt_twice
forward_promise_retrieve_funds_back_transfers => forward_promise_retrieve_funds_back_transfers
retrieve_funds_callback => retrieve_funds_callback
raw_async_callback => raw_async_callback
transfer_callback => transfer_callback
the_one_callback => the_one_callback
retrieve_esdt_callback => retrieve_esdt_callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,94 @@
"refund": "*"
}
},
{
"step": "checkState",
"accounts": {
"address:a_user": {
"nonce": "*",
"balance": "0",
"storage": {},
"code": ""
},
"sc:vault": {
"nonce": "0",
"balance": "100",
"esdt": {
"str:FWD-TOKEN": "800",
"str:NFT-123456": {
"instances": [
{
"nonce": "1",
"balance": "1"
}
]
},
"str:SFT-456789": {
"instances": [
{
"nonce": "3",
"balance": "6"
}
]
}
},
"storage": {
"str:call_counts|nested:str:accept_funds": "1"
},
"code": "mxsc:../vault/output/vault.mxsc.json"
},
"sc:forwarder": {
"nonce": "0",
"balance": "3900",
"esdt": {
"str:FWD-TOKEN": "200",
"str:SFT-456789": {
"instances": [
{
"nonce": "3",
"balance": "4"
}
]
}
},
"code": "mxsc:../forwarder/output/forwarder.mxsc.json"
}
}
},
{
"step": "scCall",
"id": "2",
"comment": "send all types",
"tx": {
"from": "address:a_user",
"to": "sc:forwarder",
"function": "send_async_accept_multi_transfer",
"arguments": [
"sc:vault",
"str:FWD-TOKEN",
"0",
"800",
"str:NFT-123456",
"1",
"1",
"str:EGLD-000000",
"0",
"4100",
"str:SFT-456789",
"3",
"6"
],
"gasLimit": "80,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "0",
"message": "",
"gas": "*",
"refund": "*"
}
},
{
"step": "checkState",
"accounts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"gasSchedule": "v3",
"steps": [
{
"step": "setState",
"accounts": {
"address:a_user": {
"nonce": "0",
"balance": "0"
},
"sc:forwarder": {
"nonce": "0",
"balance": "1000",
"esdt": {
"str:FWD-TOKEN": "100",
"str:NFT-123456": {
"instances": [
{
"nonce": "1",
"balance": "1"
}
]
},
"str:SFT-456789": {
"instances": [
{
"nonce": "3",
"balance": "10"
}
]
}
},
"code": "mxsc:../forwarder/output/forwarder.mxsc.json"
},
"sc:vault": {
"nonce": "0",
"balance": "0",
"code": "mxsc:../vault/output/vault.mxsc.json"
}
}
},
{
"step": "scCall",
"id": "1",
"comment": "failed sending EGLD+ESDT",
"tx": {
"from": "address:a_user",
"to": "sc:forwarder",
"function": "transf_exec_multi_accept_funds",
"arguments": [
"sc:vault",
"str:FWD-TOKEN",
"0",
"10",
"str:EGLD",
"0",
"1001"
],
"gasLimit": "1,400,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "10",
"message": "str:insufficient funds for token EGLD-000000",
"gas": "*",
"refund": "*"
}
},
{
"step": "checkState",
"accounts": {
"address:a_user": {
"nonce": "*",
"balance": "0",
"storage": {},
"code": ""
},
"sc:vault": {
"nonce": "0",
"balance": "0",
"esdt": {
"str:FWD-TOKEN": "0",
"str:NFT-123456": {
"instances": [
{
"nonce": "1",
"balance": "0"
}
]
},
"str:SFT-456789": {
"instances": [
{
"nonce": "3",
"balance": "0"
}
]
}
},
"storage": {
"str:call_counts|nested:str:accept_funds": "0"
},
"code": "mxsc:../vault/output/vault.mxsc.json"
},
"sc:forwarder": {
"nonce": "0",
"balance": "1000",
"esdt": {
"str:FWD-TOKEN": "100",
"str:SFT-456789": {
"instances": [
{
"nonce": "3",
"balance": "10"
}
]
},
"str:NFT-123456": {
"instances": [
{
"nonce": "1",
"balance": "1"
}
]
}
},
"storage": {
"str:call_counts|nested:str:accept_funds": "0"
},
"code": "mxsc:../forwarder/output/forwarder.mxsc.json"
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"steps": [
{
"step": "setState",
"accounts": {
"address:a_user": {
"nonce": "0",
"balance": "100"
},
"address:b_user": {
"nonce": "0",
"balance": "0"
},
"sc:vault": {
"nonce": "0",
"balance": "0",
"code": "mxsc:../vault/output/vault.mxsc.json"
},
"sc:forwarder": {
"nonce": "0",
"balance": "100",
"code": "mxsc:../promises-features/output/promises-features.mxsc.json"
}
}
},
{
"step": "scCall",
"id": "1",
"tx": {
"from": "address:a_user",
"to": "sc:forwarder",
"egldValue": "75",
"function": "forward_payment_gas_for_raw_async_callback",
"arguments": [
"sc:vault",
"address:b_user",
"11"
],
"gasLimit": "60,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "10",
"message": "*",
"gas": "*",
"refund": "*"
}
},
{
"step": "scQuery",
"id": "2",
"tx": {
"to": "sc:forwarder",
"function": "promiseCheck",
"arguments": []
},
"expect": {
"out": [
"11"
],
"status": "",
"logs": []
}
}
]
}
Loading
Loading