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

replace contract_call function and ContractCall* structs with unified syntax correspondents #1530

Merged
merged 5 commits into from
Apr 4, 2024
Merged
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
29 changes: 10 additions & 19 deletions contracts/examples/multisig/interact/src/multisig_interact_wegld.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
use std::time::Duration;

use multiversx_sc_scenario::{
multiversx_sc::types::{ContractCallBase, FunctionCall, ReturnsResult},
multiversx_sc::types::{FunctionCall, ManagedAddress, ReturnsResult},
NumExpr,
};
#[allow(unused_imports)]
use multiversx_sc_snippets::multiversx_sc::types::{
EsdtTokenPayment, MultiValueEncoded, TokenIdentifier,
};
use multiversx_sc_snippets::{
multiversx_sc::types::ContractCallNoPayment,
multiversx_sc_scenario::{
mandos_system::ScenarioRunner, scenario_format::interpret_trait::InterpretableFrom,
standalone::retrieve_account_as_scenario_set_state,
},
use multiversx_sc_snippets::multiversx_sc_scenario::{
mandos_system::ScenarioRunner, scenario_format::interpret_trait::InterpretableFrom,
standalone::retrieve_account_as_scenario_set_state,
};

use super::*;
Expand Down Expand Up @@ -85,16 +82,13 @@ impl MultisigInteract {
}

async fn propose_unwrap_egld(&mut self) -> usize {
let contract_call = ContractCallNoPayment::<StaticApi, ()>::new(
bech32::decode(WEGLD_SWAP_SC_BECH32).into(),
"unwrapEgld",
)
.with_esdt_transfer(EsdtTokenPayment::new(
let to = ManagedAddress::<StaticApi>::from(bech32::decode(WEGLD_SWAP_SC_BECH32));
let payment = EsdtTokenPayment::new(
TokenIdentifier::from(WEGLD_TOKEN_IDENTIFIER),
0u64,
UNWRAP_AMOUNT.into(),
))
.into_normalized();
);
let function_call = FunctionCall::new("unwrapEgld");

let action_id = self
.interactor
Expand All @@ -103,11 +97,8 @@ impl MultisigInteract {
.to(&self.state.multisig().to_address())
.gas(NumExpr("10,000,000"))
.typed(multisig_proxy::MultisigProxy)
.propose_async_call(
contract_call.basic.to,
0u64,
contract_call.basic.function_call,
)
.propose_async_call(to, 0u64, function_call)
.esdt(payment)
.returns(ReturnsResult)
.prepare_async()
.run()
Expand Down
15 changes: 8 additions & 7 deletions contracts/examples/multisig/src/multisig_perform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ pub trait MultisigPerformModule:
&call_data.endpoint_name,
call_data.arguments.as_multi(),
);
self.send()
.contract_call::<()>(call_data.to, call_data.endpoint_name)
.with_egld_transfer(call_data.egld_amount)
.with_raw_arguments(call_data.arguments.into())
.async_call()
.with_callback(self.callbacks().perform_async_call_callback())
.call_and_exit()

self.tx()
.to(&call_data.to)
.raw_call(call_data.endpoint_name)
.arguments_raw(call_data.arguments.into())
.egld(call_data.egld_amount)
.callback(self.callbacks().perform_async_call_callback())
.async_call_and_exit();
},
Action::SCDeployFromSource {
amount,
Expand Down
9 changes: 5 additions & 4 deletions contracts/examples/seed-nft-minter/src/distribution_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ pub trait DistributionModule {
if payment_amount == 0 {
continue;
}
self.send()
.contract_call::<IgnoreValue>(distribution.address, distribution.endpoint)
.with_egld_or_single_esdt_transfer((token_id.clone(), token_nonce, payment_amount))
.with_gas_limit(distribution.gas_limit)
self.tx()
.to(&distribution.address)
.raw_call(distribution.endpoint)
.egld_or_single_esdt(token_id, token_nonce, &payment_amount)
.gas(distribution.gas_limit)
.transfer_execute();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,30 +172,27 @@ pub trait ForwarderQueue {
},
};

let contract_call = ContractCallWithAnyPayment::<_, ()>::new(
call.to,
call.endpoint_name,
call.payments,
);
let contract_call = self
.tx()
.raw_call(call.endpoint_name)
.to(&call.to)
.payment(&call.payments);

match call.call_type {
QueuedCallType::Sync => {
contract_call.execute_on_dest_context::<()>();
contract_call.sync_call();
},
QueuedCallType::LegacyAsync => {
contract_call.async_call().call_and_exit();
contract_call.async_call_and_exit();
},
QueuedCallType::TransferExecute => {
contract_call
.with_gas_limit(call.gas_limit)
.transfer_execute();
contract_call.gas(call.gas_limit).transfer_execute();
},
QueuedCallType::Promise => {
contract_call
.with_gas_limit(call.gas_limit)
.with_raw_arguments(call.args)
.async_call_promise()
.with_callback(self.callbacks().promises_callback_method())
.gas(call.gas_limit)
.arguments_raw(call.args)
.callback(self.callbacks().promises_callback_method())
.register_promise();
},
}
Expand All @@ -208,10 +205,13 @@ pub trait ForwarderQueue {
self.callback_count().update(|c| *c += 1);
let payments = self.call_value().any_payment();

let payments_data_string =
ContractCallNoPayment::<_, ()>::new(ManagedAddress::default(), ManagedBuffer::new())
.with_any_payment(payments)
.into_call_data_string();
let payments_data_string = self
.tx()
.to(&ManagedAddress::default())
.payment(payments)
.function_call(FunctionCall::empty())
.to_call_data_string();

self.callback_payments().set(payments_data_string);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ pub trait ForwarderRawAlterativeInit: super::forwarder_raw_common::ForwarderRawC
endpoint_name: ManagedBuffer,
args: MultiValueEncoded<ManagedBuffer>,
) {
self.send()
.contract_call::<()>(to, endpoint_name)
.with_raw_arguments(args.to_arg_buffer())
.async_call()
.call_and_exit();
self.tx()
.to(&to)
.raw_call(endpoint_name)
.arguments_raw(args.to_arg_buffer())
.async_call_and_exit();
}

/// Will not work, only written for VM testing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,24 @@ pub trait ForwarderRawAsync: super::forwarder_raw_common::ForwarderRawCommon {
payment_amount: BigUint,
endpoint_name: ManagedBuffer,
args: MultiValueEncoded<ManagedBuffer>,
) -> ContractCallWithEgldOrSingleEsdt<Self::Api, ()> {
self.send()
.contract_call(to, endpoint_name)
.with_raw_arguments(args.to_arg_buffer())
.with_egld_or_single_esdt_transfer((payment_token, 0, payment_amount))
) -> Tx<
TxScEnv<Self::Api>,
(),
ManagedAddress,
EgldOrEsdtTokenPayment<Self::Api>,
(),
FunctionCall<Self::Api>,
(),
> {
self.tx()
.to(to)
.raw_call(endpoint_name)
.arguments_raw(args.to_arg_buffer())
.payment(EgldOrEsdtTokenPayment::new(
payment_token,
0,
payment_amount,
))
}

#[endpoint]
Expand Down Expand Up @@ -183,12 +196,10 @@ pub trait ForwarderRawAsync: super::forwarder_raw_common::ForwarderRawCommon {
all_payments.push(EsdtTokenPayment::new(token_identifier, token_nonce, amount));
}

ContractCallWithMultiEsdt::<Self::Api, ()>::new(
to,
"burn_and_create_retrive_async",
all_payments,
)
.async_call()
.call_and_exit_ignore_callback()
self.tx()
.raw_call("burn_and_create_retrieve_async")
.to(&to)
.payment(&all_payments)
.async_call_and_exit()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ where
.original_result()
}

pub fn burn_and_create_retrive_async(
pub fn burn_and_create_retrieve_async(
self,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call("burn_and_create_retrive_async")
.raw_call("burn_and_create_retrieve_async")
.original_result()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ pub trait CallPromisesDirectModule {
args: MultiValueEncoded<ManagedBuffer>,
) {
let payment = self.call_value().egld_or_single_esdt();
self.send()
.contract_call::<()>(to, endpoint_name)
.with_egld_or_single_esdt_transfer(payment)
.with_raw_arguments(args.to_arg_buffer())
.with_gas_limit(gas_limit)
self.tx()
.to(&to)
.raw_call(endpoint_name)
.payment(payment)
.arguments_raw(args.to_arg_buffer())
.gas(gas_limit)
.async_call_promise()
.with_extra_gas_for_callback(extra_gas_for_callback)
.with_callback(self.callbacks().the_one_callback(1001, 1002u32.into()))
.callback(self.callbacks().the_one_callback(1001, 1002u32.into()))
.gas_for_callback(extra_gas_for_callback)
.register_promise();
}

Expand All @@ -40,13 +41,14 @@ pub trait CallPromisesDirectModule {

let gas_limit = (self.blockchain().get_gas_left() - extra_gas_for_callback) * 9 / 10;

self.send()
.contract_call::<()>(to, endpoint_name)
.with_multi_token_transfer(token_payments_vec)
.with_gas_limit(gas_limit)
self.tx()
.to(&to)
.raw_call(endpoint_name)
.egld_or_multi_esdt(EgldOrMultiEsdtPayment::MultiEsdt(token_payments_vec))
andrei-marinica marked this conversation as resolved.
Show resolved Hide resolved
.gas(gas_limit)
.async_call_promise()
.with_extra_gas_for_callback(extra_gas_for_callback)
.with_callback(self.callbacks().the_one_callback(2001, 2002u32.into()))
.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 @@ -214,11 +214,11 @@ where
.original_result()
}

pub fn burn_and_create_retrive_async(
pub fn burn_and_create_retrieve_async(
self,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call("burn_and_create_retrive_async")
.raw_call("burn_and_create_retrieve_async")
.original_result()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub trait RecursiveCaller {
.to(to)
.typed(vault_proxy::VaultProxy)
.accept_funds()
.egld_or_single_esdt((token_identifier.clone(), 0, amount.clone()))
.egld_or_single_esdt(token_identifier, 0, amount)
.async_call()
.with_callback(self.callbacks().recursive_send_funds_callback(
to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ where
.original_result()
}

pub fn burn_and_create_retrive_async(
pub fn burn_and_create_retrieve_async(
self,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call("burn_and_create_retrive_async")
.raw_call("burn_and_create_retrieve_async")
.original_result()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub trait TransferRoleFeatures:
}

if !self.blockchain().is_smart_contract(&dest) {
self.transfer_to_user(original_caller, dest, payments.clone_value(), endpoint_name);
self.transfer_to_user(original_caller, dest, &payments, endpoint_name);
} else {
let mut args_buffer = ManagedArgBuffer::new();
for arg in args {
Expand All @@ -40,7 +40,7 @@ pub trait TransferRoleFeatures:
self.transfer_to_contract_raw(
original_caller,
dest,
payments.clone_value(),
&payments,
endpoint_name,
args_buffer,
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn test_transfer_role() {
sc.transfer_to_user(
managed_address!(&address_expr_to_address(USER_ADDRESS_EXPR)),
managed_address!(&address_expr_to_address(OWNER_ADDRESS_EXPR)),
payments,
&payments,
managed_buffer!(b"enjoy"),
);
},
Expand Down Expand Up @@ -135,7 +135,7 @@ fn test_transfer_role() {
sc.transfer_to_user(
managed_address!(&address_expr_to_address(USER_ADDRESS_EXPR)),
managed_address!(&Address::zero()),
payments,
&payments,
managed_buffer!(b"enjoy"),
);
},
Expand All @@ -159,7 +159,7 @@ fn test_transfer_role() {
sc.transfer_to_contract_raw(
managed_address!(&address_expr_to_address(USER_ADDRESS_EXPR)),
managed_address!(&address_expr_to_address(VAULT_ADDRESS_EXPR)),
payments,
&payments,
managed_buffer!(ACCEPT_FUNDS_FUNC_NAME),
ManagedArgBuffer::new(),
None,
Expand Down Expand Up @@ -191,7 +191,7 @@ fn test_transfer_role() {
sc.transfer_to_contract_raw(
managed_address!(&address_expr_to_address(USER_ADDRESS_EXPR)),
managed_address!(&address_expr_to_address(VAULT_ADDRESS_EXPR)),
payments,
&payments,
managed_buffer!(REJECT_FUNDS_FUNC_NAME),
ManagedArgBuffer::new(),
None,
Expand Down
11 changes: 6 additions & 5 deletions contracts/feature-tests/composability/vault/src/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ pub trait Vault {
for _ in 0..nr_callbacks {
self.num_async_calls_sent_from_child().update(|c| *c += 1);

self.send()
.contract_call::<()>(caller.clone(), endpoint_name.clone())
.with_egld_or_single_esdt_transfer(return_payment.clone())
.with_gas_limit(self.blockchain().get_gas_left() / 2)
self.tx()
.to(&caller)
.raw_call(endpoint_name.clone())
.payment(&return_payment)
.gas(self.blockchain().get_gas_left() / 2)
.transfer_execute()
}
}
Expand Down Expand Up @@ -192,7 +193,7 @@ pub trait Vault {

#[payable("*")]
#[endpoint]
fn burn_and_create_retrive_async(&self) {
fn burn_and_create_retrieve_async(&self) {
let payments = self.call_value().all_esdt_transfers();
let mut uris = ManagedVec::new();
uris.push(ManagedBuffer::new());
Expand Down
Loading
Loading