Skip to content

Commit

Permalink
Merge pull request #1646 from multiversx/deprecate-async-call
Browse files Browse the repository at this point in the history
deprecated legacy methods async_call and async_call_promise
  • Loading branch information
andrei-marinica authored May 24, 2024
2 parents bf7db0b + 4570ca2 commit 3752387
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 64 deletions.
6 changes: 2 additions & 4 deletions contracts/examples/nft-minter/src/nft_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ pub trait NftModule {
can_add_special_roles: true,
},
)
.async_call()
.with_callback(self.callbacks().issue_callback())
.call_and_exit()
.async_call_and_exit()
}

#[only_owner]
Expand All @@ -54,8 +53,7 @@ pub trait NftModule {
&self.nft_token_id().get(),
[EsdtLocalRole::NftCreate][..].iter().cloned(),
)
.async_call()
.call_and_exit()
.async_call_and_exit()
}

// endpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ pub trait Child {
can_add_special_roles: true,
},
)
.async_call()
.with_callback(self.callbacks().esdt_issue_callback())
.call_and_exit()
.async_call_and_exit()
}

// callbacks
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![no_std]
#![allow(clippy::type_complexity)]
#![allow(clippy::let_unit_value)]
#![allow(deprecated)]

pub mod fwd_call_async_legacy;
pub mod fwd_call_sync_legacy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ pub trait ForwarderRawAsync: super::forwarder_raw_common::ForwarderRawCommon {
) {
let (token, payment) = self.call_value().egld_or_single_fungible_esdt();
self.forward_contract_call(to, token, payment, endpoint_name, args)
.async_call()
.call_and_exit()
.async_call_and_exit()
}

#[endpoint]
Expand All @@ -81,8 +80,7 @@ pub trait ForwarderRawAsync: super::forwarder_raw_common::ForwarderRawCommon {
let (token, payment) = self.call_value().egld_or_single_fungible_esdt();
let half_payment = payment / 2u32;
self.forward_contract_call(to, token, half_payment, endpoint_name, args)
.async_call()
.call_and_exit()
.async_call_and_exit()
}

#[endpoint]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ pub trait ForwarderAsyncCallModule {
.typed(vault_proxy::VaultProxy)
.accept_funds()
.payment(payment)
.async_call()
.call_and_exit()
.async_call_and_exit()
}

#[endpoint]
Expand All @@ -80,8 +79,7 @@ pub trait ForwarderAsyncCallModule {
payment.token_nonce,
&half_payment,
)
.async_call()
.call_and_exit()
.async_call_and_exit()
}

#[payable("*")]
Expand Down Expand Up @@ -115,9 +113,8 @@ pub trait ForwarderAsyncCallModule {
.to(&to)
.typed(vault_proxy::VaultProxy)
.retrieve_funds(token, token_nonce, amount)
.async_call()
.callback(self.callbacks().retrieve_funds_callback())
.call_and_exit()
.async_call_and_exit()
}

#[callback]
Expand Down Expand Up @@ -196,8 +193,7 @@ pub trait ForwarderAsyncCallModule {
.typed(vault_proxy::VaultProxy)
.accept_funds()
.payment(all_token_payments)
.async_call()
.call_and_exit();
.async_call_and_exit();
}

#[view]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ pub trait ForwarderEsdtModule: fwd_storage::ForwarderStorageModule {
can_add_special_roles: true,
},
)
.async_call()
.with_callback(self.callbacks().esdt_issue_callback(&caller))
.call_and_exit()
.async_call_and_exit()
}

#[callback]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ pub trait ForwarderNftModule: fwd_storage::ForwarderStorageModule {
can_add_special_roles: true,
},
)
.async_call()
.with_callback(self.callbacks().nft_issue_callback(&caller))
.call_and_exit()
.async_call_and_exit()
}

#[callback]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ pub trait ForwarderRolesModule: fwd_storage::ForwarderStorageModule {
self.send()
.esdt_system_sc_proxy()
.set_special_roles(&address, &token_identifier, roles.into_iter())
.async_call()
.with_callback(self.callbacks().change_roles_callback())
.call_and_exit()
.async_call_and_exit()
}

#[endpoint(unsetLocalRoles)]
Expand All @@ -29,9 +28,8 @@ pub trait ForwarderRolesModule: fwd_storage::ForwarderStorageModule {
self.send()
.esdt_system_sc_proxy()
.unset_special_roles(&address, &token_identifier, roles.into_iter())
.async_call()
.with_callback(self.callbacks().change_roles_callback())
.call_and_exit()
.async_call_and_exit()
}

#[callback]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ pub trait ForwarderSftModule: fwd_storage::ForwarderStorageModule {
can_add_special_roles: true,
},
)
.async_call()
.with_callback(self.callbacks().sft_issue_callback(&caller))
.call_and_exit()
.async_call_and_exit()
}

#[callback]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ pub trait LocalEsdtAndEsdtNft {
can_add_special_roles: true,
},
)
.async_call()
.with_callback(self.callbacks().esdt_issue_callback(&caller))
.call_and_exit()
.async_call_and_exit()
}

#[endpoint(localMint)]
Expand Down Expand Up @@ -87,9 +86,8 @@ pub trait LocalEsdtAndEsdtNft {
can_add_special_roles: true,
},
)
.async_call()
.with_callback(self.callbacks().nft_issue_callback(&caller))
.call_and_exit()
.async_call_and_exit()
}

#[endpoint(nftCreate)]
Expand Down Expand Up @@ -194,9 +192,8 @@ pub trait LocalEsdtAndEsdtNft {
can_add_special_roles: true,
},
)
.async_call()
.with_callback(self.callbacks().nft_issue_callback(&caller))
.call_and_exit()
.async_call_and_exit()
}

// common
Expand All @@ -211,9 +208,8 @@ pub trait LocalEsdtAndEsdtNft {
self.send()
.esdt_system_sc_proxy()
.set_special_roles(&address, &token_identifier, roles.into_iter())
.async_call()
.with_callback(self.callbacks().change_roles_callback())
.call_and_exit()
.async_call_and_exit()
}

#[endpoint(unsetLocalRoles)]
Expand All @@ -226,9 +222,8 @@ pub trait LocalEsdtAndEsdtNft {
self.send()
.esdt_system_sc_proxy()
.unset_special_roles(&address, &token_identifier, roles.into_iter())
.async_call()
.with_callback(self.callbacks().change_roles_callback())
.call_and_exit()
.async_call_and_exit()
}

#[endpoint(controlChanges)]
Expand All @@ -242,8 +237,7 @@ pub trait LocalEsdtAndEsdtNft {
self.send()
.esdt_system_sc_proxy()
.control_changes(&token, &property_arguments)
.async_call()
.call_and_exit();
.async_call_and_exit();
}

// views
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub trait CallPromisesDirectModule {
.payment(payment)
.arguments_raw(args.to_arg_buffer())
.gas(gas_limit)
.async_call_promise()
.callback(self.callbacks().the_one_callback(1001, 1002u32.into()))
.gas_for_callback(extra_gas_for_callback)
.register_promise();
Expand All @@ -46,7 +45,6 @@ pub trait CallPromisesDirectModule {
.raw_call(endpoint_name)
.payment(EgldOrMultiEsdtPayment::MultiEsdt(token_payments_vec))
.gas(gas_limit)
.async_call_promise()
.callback(self.callbacks().the_one_callback(2001, 2002u32.into()))
.gas_for_callback(extra_gas_for_callback)
.register_promise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub trait CallPromisesBackTransfersModule: common::CommonModule {
.typed(vault_proxy::VaultProxy)
.retrieve_funds(token, token_nonce, amount)
.gas(gas_limit)
.async_call()
.callback(self.callbacks().retrieve_funds_back_transfers_callback())
.gas_for_callback(10_000_000)
.register_promise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ pub trait ProxyTestFirst {
.typed(pay_me_proxy::PayMeProxy)
.pay_me(0x56)
.egld(payment)
.async_call()
.call_and_exit();
.async_call_and_exit();
}

#[payable("EGLD")]
Expand Down Expand Up @@ -103,8 +102,7 @@ pub trait ProxyTestFirst {
[3u8; 3].to_vec(),
&ManagedAddress::from(&HARDCODED_ADDRESS),
)
.async_call()
.call_and_exit()
.async_call_and_exit()
}

#[endpoint(messageOtherContractWithCallback)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ pub trait RecursiveCaller {
.to(&self_address)
.typed(self_proxy::RecursiveCallerProxy)
.recursive_send_funds(to, token_identifier, amount, counter - 1)
.async_call()
.call_and_exit()
.async_call_and_exit()
}
}

Expand Down
6 changes: 2 additions & 4 deletions contracts/modules/src/bonding_curve/utils/owner_endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ pub trait OwnerEndpointsModule: storage::StorageModule + events::EventsModule {
self.send()
.esdt_system_sc_proxy()
.set_special_roles(&address, &token_identifier, roles.into_iter())
.async_call()
.call_and_exit()
.async_call_and_exit()
}

#[endpoint(unsetLocalRoles)]
Expand All @@ -39,8 +38,7 @@ pub trait OwnerEndpointsModule: storage::StorageModule + events::EventsModule {
self.send()
.esdt_system_sc_proxy()
.unset_special_roles(&address, &token_identifier, roles.into_iter())
.async_call()
.call_and_exit()
.async_call_and_exit()
}

fn set_bonding_curve<T>(
Expand Down
3 changes: 1 addition & 2 deletions contracts/modules/src/esdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ pub trait EsdtModule {
token_type,
num_decimals,
)
.async_call()
.with_callback(self.callbacks().issue_callback())
.call_and_exit()
.async_call_and_exit()
}

#[callback]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ where
};

storage_set(self.get_storage_key(), &TokenMapperState::<SA>::Pending);
contract_call
.async_call()
.with_callback(callback)
.call_and_exit();
contract_call.with_callback(callback).async_call_and_exit();
}

/// Important: If you use custom callback, remember to save the token ID in the callback and clear the mapper in case of error! Clear is unusable outside this specific case.
Expand Down Expand Up @@ -200,9 +197,8 @@ where
token_type,
num_decimals,
)
.async_call()
.callback(callback)
.call_and_exit()
.async_call_and_exit()
}

pub fn clear(&mut self) {
Expand Down
2 changes: 1 addition & 1 deletion framework/base/src/storage/mappers/token/token_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ where
.typed(ESDTSystemSCProxy)
.set_special_roles(address, token_id, roles[..].iter().cloned())
.callback(opt_callback)
.call_and_exit()
.async_call_and_exit()
}

fn get_sc_address() -> ManagedAddress<SA> {
Expand Down
4 changes: 4 additions & 0 deletions framework/base/src/types/interaction/tx_exec/tx_exec_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ where
RH: TxResultHandler<Env>,
{
/// Backwards compatibility only.
#[deprecated(
since = "0.50.2",
note = "Backwards compatibility only, does nothing. Just delete. Use `async_call_and_exit` to launch asynchronous calls."
)]
#[inline]
pub fn async_call(self) -> Tx<Env, From, To, Payment, Gas, Data, RH> {
Tx {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ where
///
/// This version of the method must never be called. It is only here to provide a more readable error.
pub unsafe fn register_promise(self) {
ErrorHelper::<Api>::signal_error_with_message("register_promise requires explicit gas and function call");
ErrorHelper::<Api>::signal_error_with_message(
"register_promise requires explicit gas and function call",
);
}
}

Expand Down Expand Up @@ -257,7 +259,11 @@ where
Payment: TxPayment<TxScEnv<Api>>,
Callback: TxPromisesCallback<Api>,
{
/// Backwards compatibility only.
/// Backwards compatibility only.
#[deprecated(
since = "0.50.2",
note = "Backwards compatibility only, does nothing. Just delete. Use `register_promise` to launch asynchronous calls."
)]
#[inline]
pub fn async_call_promise(self) -> Self {
self
Expand Down

0 comments on commit 3752387

Please sign in to comment.