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

migration process to unified syntax for various contracts #1542

Merged
merged 8 commits into from
Apr 22, 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
8 changes: 4 additions & 4 deletions contracts/examples/crypto-kitties/kitty-auction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub trait KittyAuction {
.to(&kitty_ownership_contract_address)
.typed(kitty_ownership_proxy::KittyOwnershipProxy)
.create_gen_zero_kitty()
.with_callback(self.callbacks().create_gen_zero_kitty_callback())
.callback(self.callbacks().create_gen_zero_kitty_callback())
.async_call_and_exit();
}

Expand Down Expand Up @@ -246,7 +246,7 @@ pub trait KittyAuction {
.to(&kitty_ownership_contract_address)
.typed(kitty_ownership_proxy::KittyOwnershipProxy)
.allow_auctioning(&caller, kitty_id)
.with_callback(self.callbacks().allow_auctioning_callback(
.callback(self.callbacks().allow_auctioning_callback(
auction_type,
kitty_id,
starting_price,
Expand Down Expand Up @@ -283,7 +283,7 @@ pub trait KittyAuction {
.to(&kitty_ownership_contract_address)
.typed(kitty_ownership_proxy::KittyOwnershipProxy)
.transfer(address, kitty_id)
.with_callback(self.callbacks().transfer_callback(kitty_id))
.callback(self.callbacks().transfer_callback(kitty_id))
.async_call_and_exit();
}
}
Expand All @@ -302,7 +302,7 @@ pub trait KittyAuction {
.typed(kitty_ownership_proxy::KittyOwnershipProxy)
.approve_siring_and_return_kitty(approved_address, kitty_owner, kitty_id)
// not a mistake, same callback for transfer and approveSiringAndReturnKitty
.with_callback(self.callbacks().transfer_callback(kitty_id))
.callback(self.callbacks().transfer_callback(kitty_id))
.async_call_and_exit();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ pub trait KittyOwnership {
.to(&gene_science_contract_address)
.typed(kitty_genetic_alg_proxy::KittyGeneticAlgProxy)
.generate_kitty_genes(matron, sire)
.with_callback(
.callback(
self.callbacks()
.generate_kitty_genes_callback(matron_id, caller),
)
Expand Down
2 changes: 1 addition & 1 deletion contracts/examples/crypto-zombies/src/zombie_feeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub trait ZombieFeeding:
.to(&crypto_kitties_sc_address)
.typed(kitty_ownership_proxy::KittyOwnershipProxy)
.get_kitty_by_id_endpoint(kitty_id)
.with_callback(self.callbacks().get_kitty_callback(zombie_id))
.callback(self.callbacks().get_kitty_callback(zombie_id))
.async_call_and_exit();
}
}
20 changes: 13 additions & 7 deletions contracts/examples/order-book/factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ pub trait Factory {
arguments.push_arg(&token_id_pair.first_token_id);
arguments.push_arg(&token_id_pair.second_token_id);

let (pair_address, _) = self.send_raw().deploy_from_source_contract(
self.blockchain().get_gas_left(),
&BigUint::zero(),
&self.pair_template_address().get(),
CodeMetadata::DEFAULT,
&arguments,
);
let gas_left = self.blockchain().get_gas_left();
let source = self.pair_template_address().get();

let pair_address = self
.tx()
.gas(gas_left)
.raw_deploy()
.arguments_raw(arguments)
.from_source(source)
.code_metadata(CodeMetadata::DEFAULT)
.returns(ReturnsNewManagedAddress)
.sync_call();

self.pairs().insert(token_id_pair, pair_address.clone());

pair_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

multiversx_sc::imports!();

const ESDT_TRANSFER_STRING: &[u8] = b"ESDTTransfer";
const SECOND_CONTRACT_ACCEPT_ESDT_PAYMENT: &[u8] = b"acceptEsdtPayment";
const SECOND_CONTRACT_REJECT_ESDT_PAYMENT: &[u8] = b"rejectEsdtPayment";
const ESDT_TRANSFER_STRING: &str = "ESDTTransfer";
const SECOND_CONTRACT_ACCEPT_ESDT_PAYMENT: &str = "acceptEsdtPayment";
const SECOND_CONTRACT_REJECT_ESDT_PAYMENT: &str = "rejectEsdtPayment";

#[multiversx_sc::contract]
pub trait FirstContract {
Expand Down Expand Up @@ -90,14 +90,13 @@ pub trait FirstContract {
"Wrong esdt token"
);

let _ = self.send_raw().transfer_esdt_execute(
&second_contract_address,
&expected_token_identifier,
&esdt_value,
self.blockchain().get_gas_left(),
&ManagedBuffer::from(SECOND_CONTRACT_REJECT_ESDT_PAYMENT),
&ManagedArgBuffer::new(),
);
let gas_left = self.blockchain().get_gas_left();
self.tx()
.to(&second_contract_address)
.gas(gas_left)
.raw_call(SECOND_CONTRACT_REJECT_ESDT_PAYMENT)
.single_esdt(&expected_token_identifier, 0u64, &esdt_value)
.transfer_execute();
}

#[payable("*")]
Expand All @@ -112,14 +111,13 @@ pub trait FirstContract {
"Wrong esdt token"
);

let _ = self.send_raw().transfer_esdt_execute(
&second_contract_address,
&expected_token_identifier,
&esdt_value,
self.blockchain().get_gas_left(),
&ManagedBuffer::from(SECOND_CONTRACT_ACCEPT_ESDT_PAYMENT),
&ManagedArgBuffer::new(),
);
let gas_left = self.blockchain().get_gas_left();
self.tx()
.to(&second_contract_address)
.gas(gas_left)
.raw_call(SECOND_CONTRACT_ACCEPT_ESDT_PAYMENT)
.single_esdt(&expected_token_identifier, 0u64, &esdt_value)
.transfer_execute();
}

fn call_esdt_second_contract(
Expand All @@ -138,12 +136,11 @@ pub trait FirstContract {
arg_buffer.push_arg_raw(arg);
}

self.send_raw().async_call_raw(
to,
&BigUint::zero(),
&ManagedBuffer::from(ESDT_TRANSFER_STRING),
&arg_buffer,
);
self.tx()
.to(to)
.raw_call(ESDT_TRANSFER_STRING)
.arguments_raw(arg_buffer)
.async_call_and_exit();
}

// storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub trait Parent {
.tx()
.raw_deploy()
.code(code)
.with_gas_limit(gas_left)
.gas(gas_left)
.returns(ReturnsNewManagedAddress)
.sync_call();

Expand All @@ -46,7 +46,7 @@ pub trait Parent {
.typed(child_proxy::ChildProxy)
.issue_wrapped_egld(token_display_name, token_ticker, initial_supply)
.egld(issue_cost)
.with_gas_limit(ISSUE_EXPECTED_GAS_COST)
.gas(ISSUE_EXPECTED_GAS_COST)
.sync_call();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ pub trait ForwarderRawAlterativeInit: super::forwarder_raw_common::ForwarderRawC
) {
let payment = self.call_value().egld_value();
let half_gas = self.blockchain().get_gas_left() / 2;
let result = self.send_raw().execute_on_dest_context_raw(
half_gas,
&to,
&payment,
&endpoint_name,
&args.to_arg_buffer(),
);

let result = self
.tx()
.to(&to)
.gas(half_gas)
.egld(payment)
.raw_call(endpoint_name)
.arguments_raw(args.to_arg_buffer())
.returns(ReturnsRawResult)
.sync_call();

self.execute_on_dest_context_result(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub trait ForwarderRawAsync: super::forwarder_raw_common::ForwarderRawCommon {
endpoint_name,
args,
)
.with_gas_limit(self.blockchain().get_gas_left() / 2)
.gas(self.blockchain().get_gas_left() / 2)
.transfer_execute();
}

Expand All @@ -118,7 +118,7 @@ pub trait ForwarderRawAsync: super::forwarder_raw_common::ForwarderRawCommon {
endpoint_name,
args,
)
.with_gas_limit(self.blockchain().get_gas_left() / 2)
.gas(self.blockchain().get_gas_left() / 2)
.transfer_execute();
}

Expand All @@ -132,7 +132,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)
.with_gas_limit(self.blockchain().get_gas_left() / 2)
.gas(self.blockchain().get_gas_left() / 2)
.transfer_execute();
}

Expand All @@ -153,10 +153,10 @@ pub trait ForwarderRawAsync: super::forwarder_raw_common::ForwarderRawCommon {
endpoint_name.clone(),
args.clone(),
)
.with_gas_limit(self.blockchain().get_gas_left() / 2)
.gas(self.blockchain().get_gas_left() / 2)
.transfer_execute();
self.forward_contract_call(to, token, half_payment, endpoint_name, args)
.with_gas_limit(self.blockchain().get_gas_left() / 2)
.gas(self.blockchain().get_gas_left() / 2)
.transfer_execute();
}

Expand All @@ -175,12 +175,11 @@ pub trait ForwarderRawAsync: super::forwarder_raw_common::ForwarderRawCommon {
arg_buffer.push_arg(amount);
}

self.send_raw().async_call_raw(
&to,
&BigUint::zero(),
&ManagedBuffer::from(&b"retrieve_multi_funds_async"[..]),
&arg_buffer,
);
self.tx()
.to(&to)
.raw_call("retrieve_multi_funds_async")
.arguments_raw(arg_buffer)
.async_call_and_exit();
}

#[endpoint]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub trait ForwarderRawDeployUpgrade {
.code(code)
.code_metadata(code_metadata)
.arguments_raw(args.to_arg_buffer())
.with_gas_limit(self.blockchain().get_gas_left())
.gas(self.blockchain().get_gas_left())
.returns(ReturnsNewManagedAddress)
.returns(ReturnsRawResult)
.sync_call()
Expand All @@ -33,7 +33,7 @@ pub trait ForwarderRawDeployUpgrade {
.from_source(source_contract_address)
.code_metadata(code_metadata)
.arguments_raw(args.to_arg_buffer())
.with_gas_limit(self.blockchain().get_gas_left())
.gas(self.blockchain().get_gas_left())
.returns(ReturnsNewManagedAddress)
.sync_call()
}
Expand Down Expand Up @@ -69,7 +69,7 @@ pub trait ForwarderRawDeployUpgrade {
.from_source(source_contract_address)
.code_metadata(code_metadata)
.arguments_raw(args.to_arg_buffer())
.with_gas_limit(self.blockchain().get_gas_left())
.gas(self.blockchain().get_gas_left())
.upgrade_async_call_and_exit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub trait ForwarderRawSync: super::forwarder_raw_common::ForwarderRawCommon {
.egld(payment)
.raw_call(endpoint_name)
.argument(&args)
.with_gas_limit(half_gas)
.gas(half_gas)
.returns(ReturnsRawResult)
.sync_call();

Expand All @@ -38,22 +38,28 @@ pub trait ForwarderRawSync: super::forwarder_raw_common::ForwarderRawCommon {
let half_payment = &*payment / 2u32;
let arg_buffer = args.to_arg_buffer();

let result = self.send_raw().execute_on_dest_context_raw(
one_third_gas,
&to,
&half_payment,
&endpoint_name,
&arg_buffer,
);
let result = self
.tx()
.to(&to)
.gas(one_third_gas)
.egld(&half_payment)
.raw_call(endpoint_name.clone())
.arguments_raw(arg_buffer.clone())
.returns(ReturnsRawResult)
.sync_call();

self.execute_on_dest_context_result(result);

let result = self.send_raw().execute_on_dest_context_raw(
one_third_gas,
&to,
&half_payment,
&endpoint_name,
&arg_buffer,
);
let result = self
.tx()
.to(&to)
.gas(one_third_gas)
.egld(&half_payment)
.raw_call(endpoint_name)
.arguments_raw(arg_buffer)
.returns(ReturnsRawResult)
.sync_call();

self.execute_on_dest_context_result(result);
}

Expand All @@ -67,13 +73,16 @@ pub trait ForwarderRawSync: super::forwarder_raw_common::ForwarderRawCommon {
) {
let payment = self.call_value().egld_value();
let half_gas = self.blockchain().get_gas_left() / 2;
let result = self.send_raw().execute_on_same_context_raw(
half_gas,
&to,
&payment,
&endpoint_name,
&args.to_arg_buffer(),
);

let result = self
.tx()
.to(&to)
.gas(half_gas)
.egld(payment)
.raw_call(endpoint_name)
.arguments_raw(args.to_arg_buffer())
.returns(ReturnsRawResult)
.sync_call_same_context();

self.execute_on_same_context_result(result);
}
Expand All @@ -86,12 +95,14 @@ pub trait ForwarderRawSync: super::forwarder_raw_common::ForwarderRawCommon {
args: MultiValueEncoded<ManagedBuffer>,
) {
let half_gas = self.blockchain().get_gas_left() / 2;
let result = self.send_raw().execute_on_dest_context_readonly_raw(
half_gas,
&to,
&endpoint_name,
&args.to_arg_buffer(),
);
let result = self
.tx()
.to(&to)
.gas(half_gas)
.raw_call(endpoint_name)
.arguments_raw(args.to_arg_buffer())
.returns(ReturnsRawResult)
.sync_call_readonly();

self.execute_on_dest_context_result(result);
}
Expand Down
Loading
Loading