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

Replacing direct transfers with unified syntax #1494

Merged
merged 6 commits into from
Mar 22, 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
12 changes: 8 additions & 4 deletions contracts/examples/crypto-kitties/kitty-auction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ pub trait KittyAuction {

// refund losing bid
if !auction.current_winner.is_zero() {
self.send()
.direct_egld(&auction.current_winner, &auction.current_bid);
self.tx()
.to(&auction.current_winner)
.egld(&auction.current_bid)
.transfer();
}

// update auction bid and winner
Expand Down Expand Up @@ -356,8 +358,10 @@ pub trait KittyAuction {
if auction.kitty_owner != self.blockchain().get_sc_address()
&& !auction.current_winner.is_zero()
{
self.send()
.direct_egld(&auction.kitty_owner, &auction.current_bid);
self.tx()
.to(&auction.kitty_owner)
.egld(&auction.current_bid)
.transfer();
}
},
ManagedAsyncCallResult::Err(_) => {
Expand Down
4 changes: 2 additions & 2 deletions contracts/examples/crypto-kitties/kitty-ownership/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub trait KittyOwnership {
.blockchain()
.get_sc_balance(&EgldOrEsdtTokenIdentifier::egld(), 0);

self.send().direct_egld(&caller, &egld_balance);
self.tx().to(&caller).egld(&egld_balance).transfer();
}

// views/endpoints - ERC721 required
Expand Down Expand Up @@ -569,7 +569,7 @@ pub trait KittyOwnership {

// send birth fee to caller
let fee = self.birth_fee().get();
self.send().direct_egld(&original_caller, &fee);
self.tx().to(&original_caller).egld(&fee).transfer();
},
ManagedAsyncCallResult::Err(_) => {
// this can only fail if the kitty_genes contract address is invalid
Expand Down
5 changes: 4 additions & 1 deletion contracts/examples/crypto-zombies/src/zombie_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ pub trait ZombieHelper: storage::Storage {
fn withdraw(&self) {
let caller_address = self.blockchain().get_caller();
let collected_fees = self.collected_fees().get();
self.send().direct_egld(&caller_address, &collected_fees);
self.tx()
.to(&caller_address)
.egld(&collected_fees)
.transfer();
self.collected_fees().clear();
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/examples/digital-cash/src/digital_cash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub trait DigitalCash:
continue;
}
if token == EgldOrEsdtTokenIdentifier::egld() {
self.send().direct_egld(&caller_address, &fee);
self.tx().to(&caller_address).egld(&fee).transfer();
} else {
let collected_fee = EsdtTokenPayment::new(token.unwrap_esdt(), 0, fee);
collected_esdt_fees.push(collected_fee);
Expand Down
2 changes: 1 addition & 1 deletion contracts/examples/digital-cash/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
pub trait HelpersModule: storage::StorageModule {
fn send_fee_to_address(&self, fee: &EgldOrEsdtTokenPayment, address: &ManagedAddress) {
if fee.token_identifier == EgldOrEsdtTokenIdentifier::egld() {
self.send().direct_egld(address, &fee.amount);
self.tx().to(address).egld(&fee.amount).transfer();
} else {
let esdt_fee = fee.clone().unwrap_esdt();
self.send()
Expand Down
12 changes: 8 additions & 4 deletions contracts/examples/digital-cash/src/signature_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ pub trait SignatureOperationsModule: storage::StorageModule + helpers::HelpersMo
}

if egld_funds > 0 {
self.send()
.direct_egld(&deposit.depositor_address, &egld_funds);
self.tx()
.to(&deposit.depositor_address)
.egld(&egld_funds)
.transfer();
}

if !esdt_funds.is_empty() {
Expand Down Expand Up @@ -71,8 +73,10 @@ pub trait SignatureOperationsModule: storage::StorageModule + helpers::HelpersMo
.update(|collected_fees| *collected_fees += fee_cost);

if deposit.egld_funds > 0 {
self.send()
.direct_egld(&caller_address, &deposit.egld_funds);
self.tx()
.to(&caller_address)
.egld(&deposit.egld_funds)
.transfer();
}
if !deposit.esdt_funds.is_empty() {
self.send()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub trait NftStoragePrepay {
self.total_reserved().clear();

let owner = self.blockchain().get_caller();
self.send().direct_egld(&owner, &total_reserved);
self.tx().to(&owner).egld(&total_reserved).transfer();
}

// endpoints
Expand Down Expand Up @@ -71,7 +71,7 @@ pub trait NftStoragePrepay {
user_deposit -= &amount;
self.deposit(&caller).set(&user_deposit);

self.send().direct_egld(&caller, &amount);
self.tx().to(&caller).egld(&amount).transfer();
}

// views
Expand Down
12 changes: 5 additions & 7 deletions contracts/feature-tests/composability/forwarder/src/esdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ pub trait ForwarderEsdtModule: storage::ForwarderStorageModule {
all_token_payments.push(payment);
}

let _ = self.send_raw().multi_esdt_transfer_execute(
&to,
&all_token_payments,
self.blockchain().get_gas_left(),
&ManagedBuffer::new(),
&ManagedArgBuffer::new(),
);
self.tx()
.with_gas_limit(self.blockchain().get_gas_left())
.to(&to)
.multi_esdt(all_token_payments)
.transfer_execute();
andrei-marinica marked this conversation as resolved.
Show resolved Hide resolved
}

#[payable("EGLD")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub trait OwnerEndpointsModule: storage::StorageModule + events::EventsModule {
self.owned_tokens(&caller).clear();
self.send().direct_multi(&caller, &tokens_to_claim);
if egld_to_claim > BigUint::zero() {
self.send().direct_egld(&caller, &egld_to_claim);
self.tx().to(&caller).egld(&egld_to_claim).transfer();
}
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/modules/src/default_issue_callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ pub trait DefaultIssueCallbacksModule {
}

fn return_failed_issue_funds(&self, initial_caller: ManagedAddress) {
let egld_returned = self.call_value().egld_value();
if *egld_returned > 0u32 {
self.send().direct_egld(&initial_caller, &egld_returned);
let egld_returned = self.call_value().egld_value().to_u64().unwrap();
if egld_returned > 0u64 {
self.tx().to(&initial_caller).egld(egld_returned).transfer();
}
}
}
6 changes: 3 additions & 3 deletions contracts/modules/src/esdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ pub trait EsdtModule {
ManagedAsyncCallResult::Err(_) => {
// return payment to initial caller
let initial_caller = self.blockchain().get_owner_address();
let egld_returned = self.call_value().egld_value();
if *egld_returned > 0u32 {
self.send().direct_egld(&initial_caller, &egld_returned);
let egld_returned = self.call_value().egld_value().to_u64().unwrap();
BiancaIalangi marked this conversation as resolved.
Show resolved Hide resolved
if egld_returned > 0u64 {
self.tx().to(&initial_caller).egld(egld_returned).transfer();
}
},
}
Expand Down
8 changes: 8 additions & 0 deletions framework/base/src/types/interaction/tx_call_te.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,12 @@ where
pub fn transfer(self) {
self.transfer_execute_with_gas(0)
}

pub fn transfer_non_zero(self) {
BiancaIalangi marked this conversation as resolved.
Show resolved Hide resolved
if self.payment.is_no_payment() {
return;
}

self.transfer_execute_with_gas(0)
}
}
Loading