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 2 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
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.clone(), token_nonce, payment_amount))
andrei-marinica marked this conversation as resolved.
Show resolved Hide resolved
.gas(distribution.gas_limit)
.transfer_execute();
}
}
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,20 @@ 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())
.egld_or_single_esdt((payment_token, 0, payment_amount))
}

#[endpoint]
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)
.egld_or_single_esdt(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
9 changes: 5 additions & 4 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())
.egld_or_single_esdt(return_payment.clone())
andrei-marinica marked this conversation as resolved.
Show resolved Hide resolved
.gas(self.blockchain().get_gas_left() / 2)
.transfer_execute()
}
}
Expand Down
16 changes: 6 additions & 10 deletions contracts/modules/src/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,12 @@ pub trait GovernanceModule:
self.clear_proposal(proposal_id);

for action in proposal.actions {
let mut contract_call = self
.send()
.contract_call::<()>(action.dest_address, action.function_name)
.with_gas_limit(action.gas_limit);

for arg in &action.arguments {
contract_call.push_raw_argument(arg);
}

contract_call.transfer_execute();
self.tx()
.to(&action.dest_address)
.raw_call(action.function_name)
.gas(action.gas_limit)
.arguments_raw(action.arguments.into())
.transfer_execute()
}

self.proposal_executed_event(proposal_id);
Expand Down
Loading