From dee6e081c083f69e6574e1ca19d68059f699ed8e Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Mon, 8 Apr 2024 16:21:23 +0200 Subject: [PATCH] send_raw migration and other small impls and modifications --- .../crypto-kitties/kitty-auction/src/lib.rs | 8 +- .../crypto-kitties/kitty-ownership/src/lib.rs | 2 +- .../crypto-zombies/src/zombie_feeding.rs | 2 +- .../examples/multisig/src/multisig_perform.rs | 55 ++++++------ .../examples/order-book/factory/src/lib.rs | 20 +++-- .../first-contract/src/lib.rs | 41 ++++----- .../parent/src/lib.rs | 4 +- .../src/forwarder_raw_alt_init.rs | 17 ++-- .../forwarder-raw/src/forwarder_raw_async.rs | 21 +++-- .../src/forwarder_raw_deploy_upgrade.rs | 6 +- .../forwarder-raw/src/forwarder_raw_sync.rs | 67 ++++++++------ .../composability/forwarder/src/call_async.rs | 42 ++++----- .../composability/forwarder/src/call_sync.rs | 18 ++-- .../forwarder/src/call_transf_exec.rs | 20 ++--- .../composability/forwarder/src/nft.rs | 17 ++-- .../local-esdt-and-nft/src/lib.rs | 18 ++-- .../promises-features/src/call_promises.rs | 10 +-- .../promises-features/src/call_promises_bt.rs | 6 +- .../proxy-test-first/src/proxy-test-first.rs | 10 +-- .../recursive-caller/src/recursive_caller.rs | 5 +- .../composability/vault/src/vault.rs | 16 ++-- .../src/crowdfunding_erc20.rs | 2 +- .../erc1155/src/erc1155.rs | 4 +- .../lottery-erc20/src/lottery.rs | 4 +- .../rust-testing-framework-tester/src/lib.rs | 40 ++++----- .../mappers/token/fungible_token_mapper.rs | 2 +- .../token/non_fungible_token_mapper.rs | 2 +- .../interaction/tx_exec/tx_exec_upgrade.rs | 90 +++++++++++++++++++ .../src/types/interaction/upgrade_call.rs | 9 +- 29 files changed, 331 insertions(+), 227 deletions(-) diff --git a/contracts/examples/crypto-kitties/kitty-auction/src/lib.rs b/contracts/examples/crypto-kitties/kitty-auction/src/lib.rs index 557673bb3d..60a30c382e 100644 --- a/contracts/examples/crypto-kitties/kitty-auction/src/lib.rs +++ b/contracts/examples/crypto-kitties/kitty-auction/src/lib.rs @@ -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(); } @@ -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, @@ -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(); } } @@ -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(); } } diff --git a/contracts/examples/crypto-kitties/kitty-ownership/src/lib.rs b/contracts/examples/crypto-kitties/kitty-ownership/src/lib.rs index d6e0771fa4..dbde8aed52 100644 --- a/contracts/examples/crypto-kitties/kitty-ownership/src/lib.rs +++ b/contracts/examples/crypto-kitties/kitty-ownership/src/lib.rs @@ -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), ) diff --git a/contracts/examples/crypto-zombies/src/zombie_feeding.rs b/contracts/examples/crypto-zombies/src/zombie_feeding.rs index 7afd7a7be8..56ef89cb7c 100644 --- a/contracts/examples/crypto-zombies/src/zombie_feeding.rs +++ b/contracts/examples/crypto-zombies/src/zombie_feeding.rs @@ -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(); } } diff --git a/contracts/examples/multisig/src/multisig_perform.rs b/contracts/examples/multisig/src/multisig_perform.rs index dfa7016340..ef7a3ec257 100644 --- a/contracts/examples/multisig/src/multisig_perform.rs +++ b/contracts/examples/multisig/src/multisig_perform.rs @@ -167,16 +167,15 @@ pub trait MultisigPerformModule: &call_data.endpoint_name, call_data.arguments.as_multi(), ); - let result = self.send_raw().direct_egld_execute( - &call_data.to, - &call_data.egld_amount, - gas, - &call_data.endpoint_name, - &call_data.arguments.into(), - ); - if let Result::Err(e) = result { - sc_panic!(e); - } + + self.tx() + .to(&call_data.to) + .raw_call(call_data.endpoint_name) + .arguments_raw(call_data.arguments.into()) + .gas(gas) + .egld(&call_data.egld_amount) + .transfer_execute(); + OptionalValue::None }, Action::SendAsyncCall(call_data) => { @@ -213,13 +212,17 @@ pub trait MultisigPerformModule: gas_left, arguments.as_multi(), ); - let (new_address, _) = self.send_raw().deploy_from_source_contract( - gas_left, - &amount, - &source, - code_metadata, - &arguments.into(), - ); + let new_address = self + .tx() + .gas(gas_left) + .egld(&amount) + .raw_deploy() + .arguments_raw(arguments.into()) + .from_source(source) + .code_metadata(code_metadata) + .returns(ReturnsNewManagedAddress) + .sync_call(); + OptionalValue::Some(new_address) }, Action::SCUpgradeFromSource { @@ -239,14 +242,16 @@ pub trait MultisigPerformModule: gas_left, arguments.as_multi(), ); - self.send_raw().upgrade_from_source_contract( - &sc_address, - gas_left, - &amount, - &source, - code_metadata, - &arguments.into(), - ); + + self.tx() + .to(&sc_address) + .raw_upgrade() + .arguments_raw(arguments.into()) + .egld(&amount) + .from_source(source) + .code_metadata(code_metadata) + .upgrade_async_call_and_exit(); + OptionalValue::None }, } diff --git a/contracts/examples/order-book/factory/src/lib.rs b/contracts/examples/order-book/factory/src/lib.rs index cac1192361..fb83863ae3 100644 --- a/contracts/examples/order-book/factory/src/lib.rs +++ b/contracts/examples/order-book/factory/src/lib.rs @@ -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 diff --git a/contracts/feature-tests/composability/esdt-contract-pair/first-contract/src/lib.rs b/contracts/feature-tests/composability/esdt-contract-pair/first-contract/src/lib.rs index dfa6ff75e5..ad089ef4ce 100644 --- a/contracts/feature-tests/composability/esdt-contract-pair/first-contract/src/lib.rs +++ b/contracts/feature-tests/composability/esdt-contract-pair/first-contract/src/lib.rs @@ -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(ManagedBuffer::from(SECOND_CONTRACT_REJECT_ESDT_PAYMENT)) + .single_esdt(&expected_token_identifier, 0u64, &esdt_value) + .transfer_execute(); } #[payable("*")] @@ -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(ManagedBuffer::from(SECOND_CONTRACT_ACCEPT_ESDT_PAYMENT)) + .single_esdt(&expected_token_identifier, 0u64, &esdt_value) + .transfer_execute(); } fn call_esdt_second_contract( @@ -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(ManagedBuffer::from(ESDT_TRANSFER_STRING)) + .arguments_raw(arg_buffer) + .async_call_and_exit(); } // storage diff --git a/contracts/feature-tests/composability/execute-on-dest-esdt-issue-callback/parent/src/lib.rs b/contracts/feature-tests/composability/execute-on-dest-esdt-issue-callback/parent/src/lib.rs index d9dfe79d0e..5c4bff50d0 100644 --- a/contracts/feature-tests/composability/execute-on-dest-esdt-issue-callback/parent/src/lib.rs +++ b/contracts/feature-tests/composability/execute-on-dest-esdt-issue-callback/parent/src/lib.rs @@ -23,7 +23,7 @@ pub trait Parent { .tx() .raw_deploy() .code(code) - .with_gas_limit(gas_left) + .gas(gas_left) .returns(ReturnsNewManagedAddress) .sync_call(); @@ -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(); } diff --git a/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_alt_init.rs b/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_alt_init.rs index 0ded59b36d..f00a10d434 100644 --- a/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_alt_init.rs +++ b/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_alt_init.rs @@ -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); } diff --git a/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_async.rs b/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_async.rs index fbd0eec1a4..39638bbe6f 100644 --- a/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_async.rs +++ b/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_async.rs @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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] diff --git a/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_deploy_upgrade.rs b/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_deploy_upgrade.rs index b57ac773e2..803119c140 100644 --- a/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_deploy_upgrade.rs +++ b/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_deploy_upgrade.rs @@ -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() @@ -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() } @@ -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(); } } diff --git a/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_sync.rs b/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_sync.rs index 662518d093..a4e98f36a7 100644 --- a/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_sync.rs +++ b/contracts/feature-tests/composability/forwarder-raw/src/forwarder_raw_sync.rs @@ -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(); @@ -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); } @@ -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(); self.execute_on_same_context_result(result); } @@ -86,12 +95,14 @@ pub trait ForwarderRawSync: super::forwarder_raw_common::ForwarderRawCommon { args: MultiValueEncoded, ) { 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(); self.execute_on_dest_context_result(result); } diff --git a/contracts/feature-tests/composability/forwarder/src/call_async.rs b/contracts/feature-tests/composability/forwarder/src/call_async.rs index 04ba78faab..2de43a6752 100644 --- a/contracts/feature-tests/composability/forwarder/src/call_async.rs +++ b/contracts/feature-tests/composability/forwarder/src/call_async.rs @@ -22,9 +22,8 @@ pub trait ForwarderAsyncCallModule { .to(&to) .typed(vault_proxy::VaultProxy) .echo_arguments(args) - .async_call() - .with_callback(self.callbacks().echo_args_callback()) - .call_and_exit(); + .callback(self.callbacks().echo_args_callback()) + .async_call_and_exit(); } #[callback] @@ -61,7 +60,7 @@ pub trait ForwarderAsyncCallModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_egld_or_single_esdt_transfer(payment) + .payment(payment) .async_call() .call_and_exit() } @@ -75,11 +74,11 @@ pub trait ForwarderAsyncCallModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_egld_or_single_esdt_transfer(( - payment.token_identifier, + .egld_or_single_esdt( + &payment.token_identifier, payment.token_nonce, - half_payment, - )) + &half_payment, + ) .async_call() .call_and_exit() } @@ -95,13 +94,12 @@ pub trait ForwarderAsyncCallModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_egld_or_single_esdt_transfer(( - payment.token_identifier, + .egld_or_single_esdt( + &payment.token_identifier, payment.token_nonce, - amount_to_send, - )) - .async_call() - .call_and_exit() + &amount_to_send, + ) + .async_call_and_exit(); } #[endpoint] @@ -117,7 +115,7 @@ pub trait ForwarderAsyncCallModule { .typed(vault_proxy::VaultProxy) .retrieve_funds(token, token_nonce, amount) .async_call() - .with_callback(self.callbacks().retrieve_funds_callback()) + .callback(self.callbacks().retrieve_funds_callback()) .call_and_exit() } @@ -154,13 +152,12 @@ pub trait ForwarderAsyncCallModule { .to(to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_egld_or_single_esdt_transfer((token_identifier.clone(), 0u64, amount.clone())) - .async_call() - .with_callback( + .egld_or_single_esdt(token_identifier, 0u64, amount) + .callback( self.callbacks() .send_funds_twice_callback(to, token_identifier, amount), ) - .call_and_exit(); + .async_call_and_exit(); } #[callback] @@ -174,9 +171,8 @@ pub trait ForwarderAsyncCallModule { .to(to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_egld_or_single_esdt_transfer((token_identifier.clone(), 0u64, cb_amount.clone())) - .async_call() - .call_and_exit(); + .egld_or_single_esdt(token_identifier, 0u64, cb_amount) + .async_call_and_exit(); } #[endpoint] @@ -198,7 +194,7 @@ pub trait ForwarderAsyncCallModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_multi_token_transfer(all_token_payments) + .payment(all_token_payments) .async_call() .call_and_exit(); } diff --git a/contracts/feature-tests/composability/forwarder/src/call_sync.rs b/contracts/feature-tests/composability/forwarder/src/call_sync.rs index 8366f0ae29..13fbcd40db 100644 --- a/contracts/feature-tests/composability/forwarder/src/call_sync.rs +++ b/contracts/feature-tests/composability/forwarder/src/call_sync.rs @@ -14,7 +14,7 @@ pub trait ForwarderSyncCallModule { let result = self .tx() .to(&to) - .with_gas_limit(half_gas) + .gas(half_gas) .typed(vault_proxy::VaultProxy) .echo_arguments(args) .returns(ReturnsResult) @@ -35,7 +35,7 @@ pub trait ForwarderSyncCallModule { let result = self .tx() .to(&to) - .with_gas_limit(one_third_gas) + .gas(one_third_gas) .typed(vault_proxy::VaultProxy) .echo_arguments(args.clone()) .returns(ReturnsResult) @@ -46,7 +46,7 @@ pub trait ForwarderSyncCallModule { let result = self .tx() .to(&to) - .with_gas_limit(one_third_gas) + .gas(one_third_gas) .typed(vault_proxy::VaultProxy) .echo_arguments(args) .returns(ReturnsResult) @@ -67,10 +67,10 @@ pub trait ForwarderSyncCallModule { let result = self .tx() .to(&to) - .with_gas_limit(half_gas) + .gas(half_gas) .typed(vault_proxy::VaultProxy) .accept_funds_echo_payment() - .with_egld_or_single_esdt_transfer(payment) + .payment(payment) .returns(ReturnsResult) .sync_call(); @@ -90,7 +90,7 @@ pub trait ForwarderSyncCallModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_egld_or_single_esdt_transfer((token_id, 0u64, amount_to_send)) + .egld_or_single_esdt(&token_id, 0u64, &amount_to_send) .returns(ReturnsResult) .sync_call(); } @@ -110,7 +110,7 @@ pub trait ForwarderSyncCallModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_egld_or_single_esdt_transfer(payment) + .payment(payment) .sync_call(); self.tx() @@ -154,7 +154,7 @@ pub trait ForwarderSyncCallModule { amount, OptionalValue::::Some(b"accept_funds_func".into()), ) - .with_multi_token_transfer(payments.clone_value()) + .payment(payments) .sync_call(); } @@ -180,7 +180,7 @@ pub trait ForwarderSyncCallModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_multi_token_transfer(all_token_payments) + .payment(all_token_payments) .sync_call(); } } diff --git a/contracts/feature-tests/composability/forwarder/src/call_transf_exec.rs b/contracts/feature-tests/composability/forwarder/src/call_transf_exec.rs index 3573987867..952f50275c 100644 --- a/contracts/feature-tests/composability/forwarder/src/call_transf_exec.rs +++ b/contracts/feature-tests/composability/forwarder/src/call_transf_exec.rs @@ -14,7 +14,7 @@ pub trait ForwarderTransferExecuteModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_egld_or_single_esdt_transfer(payment) + .payment(payment) .transfer_execute(); } @@ -33,7 +33,7 @@ pub trait ForwarderTransferExecuteModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_egld_or_single_esdt_transfer((token_id, 0u64, amount_to_send)) + .egld_or_single_esdt(&token_id, 0u64, &amount_to_send) .transfer_execute(); } @@ -48,16 +48,16 @@ pub trait ForwarderTransferExecuteModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_egld_or_single_esdt_transfer((token.clone(), token_nonce, half_payment.clone())) - .with_gas_limit(half_gas) + .egld_or_single_esdt(&token, token_nonce, &half_payment) + .gas(half_gas) .transfer_execute(); self.tx() .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_egld_or_single_esdt_transfer((token, token_nonce, half_payment)) - .with_gas_limit(half_gas) + .egld_or_single_esdt(&token, token_nonce, &half_payment) + .gas(half_gas) .transfer_execute(); } @@ -77,7 +77,7 @@ pub trait ForwarderTransferExecuteModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_egld_or_single_esdt_transfer(payment) + .payment(payment) .transfer_execute(); let gas_left_after = self.blockchain().get_gas_left(); @@ -110,7 +110,7 @@ pub trait ForwarderTransferExecuteModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_multi_token_transfer(all_token_payments) + .payment(all_token_payments) .transfer_execute() } @@ -133,7 +133,7 @@ pub trait ForwarderTransferExecuteModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_multi_token_transfer(all_token_payments) + .payment(all_token_payments) .transfer_execute() } @@ -156,7 +156,7 @@ pub trait ForwarderTransferExecuteModule { .to(&to) .typed(vault_proxy::VaultProxy) .reject_funds() - .with_multi_token_transfer(all_token_payments) + .payment(all_token_payments) .transfer_execute() } } diff --git a/contracts/feature-tests/composability/forwarder/src/nft.rs b/contracts/feature-tests/composability/forwarder/src/nft.rs index 65e5eb7de1..8eae1e83c5 100644 --- a/contracts/feature-tests/composability/forwarder/src/nft.rs +++ b/contracts/feature-tests/composability/forwarder/src/nft.rs @@ -238,15 +238,14 @@ pub trait ForwarderNftModule: storage::ForwarderStorageModule { function: ManagedBuffer, arguments: MultiValueEncoded, ) { - let _ = self.send_raw().transfer_esdt_nft_execute( - &to, - &token_identifier, - nonce, - &amount, - self.blockchain().get_gas_left(), - &function, - &arguments.to_arg_buffer(), - ); + let gas_left = self.blockchain().get_gas_left(); + self.tx() + .to(&to) + .gas(gas_left) + .raw_call(function) + .arguments_raw(arguments.to_arg_buffer()) + .single_esdt(&token_identifier, nonce, &amount) + .transfer_execute(); } #[endpoint] diff --git a/contracts/feature-tests/composability/local-esdt-and-nft/src/lib.rs b/contracts/feature-tests/composability/local-esdt-and-nft/src/lib.rs index e65fd789b4..2f0bf64dc2 100644 --- a/contracts/feature-tests/composability/local-esdt-and-nft/src/lib.rs +++ b/contracts/feature-tests/composability/local-esdt-and-nft/src/lib.rs @@ -157,15 +157,15 @@ pub trait LocalEsdtAndEsdtNft { arg_buffer.push_arg_raw(arg); } - let _ = self.send_raw().transfer_esdt_nft_execute( - &to, - &token_identifier, - nonce, - &amount, - self.blockchain().get_gas_left(), - &function, - &arg_buffer, - ); + let gas_left = self.blockchain().get_gas_left(); + + self.tx() + .to(&to) + .gas(gas_left) + .raw_call(function) + .arguments_raw(arg_buffer) + .single_esdt(&token_identifier, nonce, &amount) + .transfer_execute(); } // Semi-Fungible diff --git a/contracts/feature-tests/composability/promises-features/src/call_promises.rs b/contracts/feature-tests/composability/promises-features/src/call_promises.rs index 2b116215cc..92a2c8e0e1 100644 --- a/contracts/feature-tests/composability/promises-features/src/call_promises.rs +++ b/contracts/feature-tests/composability/promises-features/src/call_promises.rs @@ -17,8 +17,8 @@ pub trait CallPromisesModule: common::CommonModule { .to(&to) .typed(vault_proxy::VaultProxy) .accept_funds() - .with_gas_limit(gas_limit) - .with_egld_or_single_esdt_transfer(payment) + .gas(gas_limit) + .payment(payment) .register_promise(); } @@ -36,9 +36,9 @@ pub trait CallPromisesModule: common::CommonModule { .to(&to) .typed(vault_proxy::VaultProxy) .retrieve_funds(token, token_nonce, amount) - .with_gas_limit(gas_limit) - .with_callback(self.callbacks().retrieve_funds_callback()) - .with_extra_gas_for_callback(10_000_000) + .gas(gas_limit) + .callback(self.callbacks().retrieve_funds_callback()) + .gas_for_callback(10_000_000) .register_promise(); } diff --git a/contracts/feature-tests/composability/promises-features/src/call_promises_bt.rs b/contracts/feature-tests/composability/promises-features/src/call_promises_bt.rs index 6f5d85179e..f6cbbfa188 100644 --- a/contracts/feature-tests/composability/promises-features/src/call_promises_bt.rs +++ b/contracts/feature-tests/composability/promises-features/src/call_promises_bt.rs @@ -20,10 +20,10 @@ pub trait CallPromisesBackTransfersModule: common::CommonModule { .to(&to) .typed(vault_proxy::VaultProxy) .retrieve_funds(token, token_nonce, amount) - .with_gas_limit(gas_limit) + .gas(gas_limit) .async_call() - .with_callback(self.callbacks().retrieve_funds_back_transfers_callback()) - .with_extra_gas_for_callback(10_000_000) + .callback(self.callbacks().retrieve_funds_back_transfers_callback()) + .gas_for_callback(10_000_000) .register_promise(); } diff --git a/contracts/feature-tests/composability/proxy-test-first/src/proxy-test-first.rs b/contracts/feature-tests/composability/proxy-test-first/src/proxy-test-first.rs index bc3d648b56..ccc9c45406 100644 --- a/contracts/feature-tests/composability/proxy-test-first/src/proxy-test-first.rs +++ b/contracts/feature-tests/composability/proxy-test-first/src/proxy-test-first.rs @@ -84,9 +84,8 @@ pub trait ProxyTestFirst { .typed(pay_me_proxy::PayMeProxy) .pay_me_with_result(0x56) .egld(payment) - .async_call() - .with_callback(self.callbacks().pay_callback()) - .call_and_exit(); + .callback(self.callbacks().pay_callback()) + .async_call_and_exit(); } #[endpoint(messageOtherContract)] @@ -117,9 +116,8 @@ pub trait ProxyTestFirst { [3u8; 3].to_vec(), &ManagedAddress::from(&HARDCODED_ADDRESS), ) - .async_call() - .with_callback(self.callbacks().message_callback()) - .call_and_exit() + .callback(self.callbacks().message_callback()) + .async_call_and_exit() } #[callback(payCallback)] // although uncommon, custom callback names are possible diff --git a/contracts/feature-tests/composability/recursive-caller/src/recursive_caller.rs b/contracts/feature-tests/composability/recursive-caller/src/recursive_caller.rs index 94f26e7e8d..339a9c7304 100644 --- a/contracts/feature-tests/composability/recursive-caller/src/recursive_caller.rs +++ b/contracts/feature-tests/composability/recursive-caller/src/recursive_caller.rs @@ -26,14 +26,13 @@ pub trait RecursiveCaller { .typed(vault_proxy::VaultProxy) .accept_funds() .egld_or_single_esdt(token_identifier, 0, amount) - .async_call() - .with_callback(self.callbacks().recursive_send_funds_callback( + .callback(self.callbacks().recursive_send_funds_callback( to, token_identifier, amount, counter, )) - .call_and_exit(); + .async_call_and_exit(); } #[callback] diff --git a/contracts/feature-tests/composability/vault/src/vault.rs b/contracts/feature-tests/composability/vault/src/vault.rs index d23123ca01..6984291b06 100644 --- a/contracts/feature-tests/composability/vault/src/vault.rs +++ b/contracts/feature-tests/composability/vault/src/vault.rs @@ -107,16 +107,12 @@ pub trait Vault { let caller = self.blockchain().get_caller(); let func_name = opt_receive_func.into_option().unwrap_or_default(); - self.send_raw() - .transfer_esdt_execute( - &caller, - &token, - &amount, - 50_000_000, - &func_name, - &ManagedArgBuffer::new(), - ) - .unwrap_or_else(|_| sc_panic!("ESDT transfer failed")); + self.tx() + .to(&caller) + .gas(50_000_000u64) + .raw_call(func_name) + .single_esdt(&token, 0u64, &amount) + .transfer_execute(); } #[allow_multiple_var_args] diff --git a/contracts/feature-tests/erc-style-contracts/crowdfunding-erc20/src/crowdfunding_erc20.rs b/contracts/feature-tests/erc-style-contracts/crowdfunding-erc20/src/crowdfunding_erc20.rs index 72b1cf8708..019ec560a5 100644 --- a/contracts/feature-tests/erc-style-contracts/crowdfunding-erc20/src/crowdfunding_erc20.rs +++ b/contracts/feature-tests/erc-style-contracts/crowdfunding-erc20/src/crowdfunding_erc20.rs @@ -36,7 +36,7 @@ pub trait Crowdfunding { .to(&erc20_address) .typed(erc20_proxy::SimpleErc20TokenProxy) .transfer_from(caller.clone(), cf_contract_address, token_amount.clone()) - .with_callback( + .callback( self.callbacks() .transfer_from_callback(caller, token_amount), ) diff --git a/contracts/feature-tests/erc-style-contracts/erc1155/src/erc1155.rs b/contracts/feature-tests/erc-style-contracts/erc1155/src/erc1155.rs index c6e9c5ce9a..725cff90de 100644 --- a/contracts/feature-tests/erc-style-contracts/erc1155/src/erc1155.rs +++ b/contracts/feature-tests/erc-style-contracts/erc1155/src/erc1155.rs @@ -354,7 +354,7 @@ pub trait Erc1155 { .to(to.clone()) .typed(erc1155_user_proxy::Erc1155UserProxy) .on_erc1155_received(caller, from.clone(), type_id.clone(), value.clone(), data) - .with_callback(self.callbacks().transfer_callback( + .callback(self.callbacks().transfer_callback( from, to, [type_id].to_vec(), @@ -383,7 +383,7 @@ pub trait Erc1155 { values.to_vec(), data, ) - .with_callback(self.callbacks().transfer_callback( + .callback(self.callbacks().transfer_callback( from, to, type_ids.to_vec(), diff --git a/contracts/feature-tests/erc-style-contracts/lottery-erc20/src/lottery.rs b/contracts/feature-tests/erc-style-contracts/lottery-erc20/src/lottery.rs index 105b19b166..1bbd1f7370 100644 --- a/contracts/feature-tests/erc-style-contracts/lottery-erc20/src/lottery.rs +++ b/contracts/feature-tests/erc-style-contracts/lottery-erc20/src/lottery.rs @@ -214,7 +214,7 @@ pub trait Lottery { .to(&erc20_address) .typed(erc20_proxy::SimpleErc20TokenProxy) .transfer_from(caller.clone(), lottery_contract_address, token_amount) - .with_callback( + .callback( self.callbacks() .transfer_from_callback(lottery_name, &caller), ) @@ -285,7 +285,7 @@ pub trait Lottery { .to(&erc20_address) .typed(erc20_proxy::SimpleErc20TokenProxy) .transfer(winner_address, prize) - .with_callback(self.callbacks().distribute_prizes_callback(lottery_name)) + .callback(self.callbacks().distribute_prizes_callback(lottery_name)) .async_call_and_exit(); } diff --git a/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs b/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs index dae11542e4..7a5b181028 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs +++ b/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs @@ -176,13 +176,14 @@ pub trait RustTestingFrameworkTester: dummy_module::DummyModule { #[endpoint] fn call_other_contract_execute_on_dest(&self, other_sc_address: ManagedAddress) -> BigUint { - let call_result = self.send_raw().execute_on_dest_context_raw( - self.blockchain().get_gas_left(), - &other_sc_address, - &BigUint::zero(), - &ManagedBuffer::new_from_bytes(b"getTotalValue"), - &ManagedArgBuffer::new(), - ); + let gas_left = self.blockchain().get_gas_left(); + let call_result = self + .tx() + .to(&other_sc_address) + .gas(gas_left) + .raw_call("getTotalValue") + .returns(ReturnsRawResult) + .sync_call(); if let Some(raw_value) = call_result.try_get(0) { BigUint::from_bytes_be_buffer(&raw_value) } else { @@ -195,12 +196,11 @@ pub trait RustTestingFrameworkTester: dummy_module::DummyModule { let mut args = ManagedArgBuffer::new(); args.push_arg(&value); - self.send_raw().async_call_raw( - &other_sc_address, - &BigUint::zero(), - &ManagedBuffer::new_from_bytes(b"add"), - &args, - ); + self.tx() + .to(&other_sc_address) + .raw_call("call") + .arguments_raw(args) + .async_call_and_exit(); } #[callback_raw] @@ -218,13 +218,13 @@ pub trait RustTestingFrameworkTester: dummy_module::DummyModule { let mut args = ManagedArgBuffer::new(); args.push_arg(value); - let _ = self.send_raw().execute_on_dest_context_raw( - self.blockchain().get_gas_left(), - &other_sc_address, - &BigUint::zero(), - &ManagedBuffer::new_from_bytes(b"addValue"), - &args, - ); + let gas_left = self.blockchain().get_gas_left(); + self.tx() + .to(&other_sc_address) + .gas(gas_left) + .raw_call("addValue") + .arguments_raw(args) + .sync_call(); } #[endpoint(addValue)] diff --git a/framework/base/src/storage/mappers/token/fungible_token_mapper.rs b/framework/base/src/storage/mappers/token/fungible_token_mapper.rs index f24e6139bf..efc322c2eb 100644 --- a/framework/base/src/storage/mappers/token/fungible_token_mapper.rs +++ b/framework/base/src/storage/mappers/token/fungible_token_mapper.rs @@ -184,7 +184,7 @@ where EsdtTokenType::Fungible, num_decimals, ) - .with_callback(callback) + .callback(callback) .async_call_and_exit(); } diff --git a/framework/base/src/storage/mappers/token/non_fungible_token_mapper.rs b/framework/base/src/storage/mappers/token/non_fungible_token_mapper.rs index 666776e88b..3e886f21de 100644 --- a/framework/base/src/storage/mappers/token/non_fungible_token_mapper.rs +++ b/framework/base/src/storage/mappers/token/non_fungible_token_mapper.rs @@ -202,7 +202,7 @@ where num_decimals, ) .async_call() - .with_callback(callback) + .callback(callback) .call_and_exit() } diff --git a/framework/base/src/types/interaction/tx_exec/tx_exec_upgrade.rs b/framework/base/src/types/interaction/tx_exec/tx_exec_upgrade.rs index 5a08481640..01a0107d68 100644 --- a/framework/base/src/types/interaction/tx_exec/tx_exec_upgrade.rs +++ b/framework/base/src/types/interaction/tx_exec/tx_exec_upgrade.rs @@ -79,6 +79,41 @@ where } } +impl + Tx< + TxScEnv, + (), + &ManagedAddress, + Payment, + Gas, + UpgradeCall, FromSource>, + RH, + > +where + Api: CallTypeApi, + Payment: TxPaymentEgldOnly>, + Gas: TxGas>, + FromSourceValue: TxFromSourceValue>, + RH: TxEmptyResultHandler>, +{ + /// Launches the upgrade from source async call. + /// + /// TODO: change return type to `!`. + pub fn upgrade_async_call_and_exit(self) { + let gas = self.gas.explicit_or_gas_left(&self.env); + self.payment.with_egld_value(&self.env, |egld_value| { + SendRawWrapper::::new().upgrade_from_source_contract( + self.to, + gas, + egld_value, + &self.data.code_source.0.into_value(&self.env), + self.data.code_metadata, + &self.data.arg_buffer, + ); + }); + } +} + impl Tx, (), ManagedAddress, Payment, Gas, UpgradeCall, ()>, RH> where @@ -133,3 +168,58 @@ where }); } } + +impl + Tx, (), &ManagedAddress, Payment, Gas, UpgradeCall, ()>, RH> +where + Api: CallTypeApi, + Payment: TxPaymentEgldOnly>, + Gas: TxGas>, + RH: TxEmptyResultHandler>, +{ + /// Backwards compatibility, immitates the old API. + /// + /// Note that the data type (the `UpgradeCall`) doesn't have the code set. + /// This is because the old API was passing it as paramter, so we use it from the `code` argument. + /// + /// Also note that the code metadata is taken from the `code_metadata` argument. + /// If another one was previously set in the `Tx` object, that one will be ignored. + pub fn upgrade_contract(self, code: &ManagedBuffer, code_metadata: CodeMetadata) { + let gas = self.gas.explicit_or_gas_left(&self.env); + self.payment.with_egld_value(&self.env, |egld_value| { + SendRawWrapper::::new().upgrade_contract( + self.to, + gas, + egld_value, + code, + code_metadata, + &self.data.arg_buffer, + ); + }); + } + + /// Backwards compatibility, immitates the old API. + /// + /// Note that the data type (the `UpgradeCall`) doesn't have the code set. + /// This is because the old API was passing it as paramter, so we use it from the `code` argument. + /// + /// Also note that the code metadata is taken from the `code_metadata` argument. + /// If another one was previously set in the `Tx` object, that one will be ignored. + pub fn upgrade_from_source( + self, + source_address: &ManagedAddress, + code_metadata: CodeMetadata, + ) { + let gas = self.gas.explicit_or_gas_left(&self.env); + self.payment.with_egld_value(&self.env, |egld_value| { + SendRawWrapper::::new().upgrade_from_source_contract( + self.to, + gas, + egld_value, + source_address, + code_metadata, + &self.data.arg_buffer, + ); + }); + } +} diff --git a/framework/base/src/types/interaction/upgrade_call.rs b/framework/base/src/types/interaction/upgrade_call.rs index d69895f029..c33290e82b 100644 --- a/framework/base/src/types/interaction/upgrade_call.rs +++ b/framework/base/src/types/interaction/upgrade_call.rs @@ -1,8 +1,13 @@ use multiversx_sc_codec::TopEncodeMulti; -use crate::types::{CodeMetadata, ManagedBuffer, ManagedBufferCachedBuilder}; +use crate::{ + proxy_imports::ManagedTypeApi, + types::{CodeMetadata, ManagedBuffer, ManagedBufferCachedBuilder}, +}; -use super::{ManagedArgBuffer, TxCodeSource, TxData, TxEnv}; +use super::{ + FunctionCall, ManagedArgBuffer, TxCodeSource, TxData, TxDataFunctionCall, TxEnv, TxScEnv, +}; /// Holds deploy data: code, code metadata, and arguments. pub struct UpgradeCall