Skip to content

Commit

Permalink
send_raw migration and other small impls and modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaicalinluca committed Apr 8, 2024
1 parent 0957bbe commit dee6e08
Show file tree
Hide file tree
Showing 29 changed files with 331 additions and 227 deletions.
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();
}
}
55 changes: 30 additions & 25 deletions contracts/examples/multisig/src/multisig_perform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
},
}
Expand Down
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 @@ -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("*")]
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(ManagedBuffer::from(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(ManagedBuffer::from(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();
}
}
Loading

0 comments on commit dee6e08

Please sign in to comment.