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

unified syntax - more migrations #1567

Merged
merged 1 commit 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
11 changes: 8 additions & 3 deletions contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ pub trait Crowdfunding {
let token_identifier = self.cf_token_identifier().get();
let sc_balance = self.get_current_funds();

self.send()
.direct(&caller, &token_identifier, 0, &sc_balance);
self.tx()
.to(&caller)
.egld_or_single_esdt(&token_identifier, 0, &sc_balance)
.transfer();
},
Status::Failed => {
let caller = self.blockchain().get_caller();
Expand All @@ -86,7 +88,10 @@ pub trait Crowdfunding {
let token_identifier = self.cf_token_identifier().get();

self.deposit(&caller).clear();
self.send().direct(&caller, &token_identifier, 0, &deposit);
self.tx()
.to(&caller)
.egld_or_single_esdt(&token_identifier, 0, &deposit)
.transfer();
}
},
}
Expand Down
16 changes: 8 additions & 8 deletions contracts/examples/lottery-esdt/src/lottery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,19 @@ pub trait Lottery {
&BigUint::from(info.prize_distribution.get(i)),
);

self.send()
.direct(&winner_address, &info.token_identifier, 0, &prize);
self.tx()
.to(&winner_address)
.egld_or_single_esdt(&info.token_identifier, 0, &prize)
.transfer();
info.prize_pool -= prize;
}

// send leftover to first place
let first_place_winner = ticket_holders_mapper.get(winning_tickets[0]);
self.send().direct(
&first_place_winner,
&info.token_identifier,
0,
&info.prize_pool,
);
self.tx()
.to(&first_place_winner)
.egld_or_single_esdt(&info.token_identifier, 0, &info.prize_pool)
.transfer();
}

fn clear_storage(&self, lottery_name: &ManagedBuffer) {
Expand Down
11 changes: 2 additions & 9 deletions contracts/examples/nft-minter/src/nft_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@ pub trait NftModule {
.transfer();

let owner = self.blockchain().get_owner_address();
self.send().direct(
&owner,
&payment.token_identifier,
payment.token_nonce,
&payment.amount,
);
self.tx().to(owner).payment(payment).transfer();
}

// views
Expand Down Expand Up @@ -133,11 +128,9 @@ pub trait NftModule {
self.nft_token_id().set(&token_id.unwrap_esdt());
},
ManagedAsyncCallResult::Err(_) => {
let caller = self.blockchain().get_owner_address();
let returned = self.call_value().egld_or_single_esdt();
if returned.token_identifier.is_egld() && returned.amount > 0 {
self.send()
.direct(&caller, &returned.token_identifier, 0, &returned.amount);
self.tx().to(ToCaller).egld(returned.amount).transfer();
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ pub trait ForwarderRawAsync: super::forwarder_raw_common::ForwarderRawCommon {
#[payable("*")]
fn forward_payment(&self, to: ManagedAddress) {
let (token, payment) = self.call_value().egld_or_single_fungible_esdt();
self.send().direct(&to, &token, 0, &payment);
self.tx()
.to(to)
.egld_or_single_esdt(&token, 0, &payment)
.transfer();
}

#[endpoint]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ pub trait LocalEsdtAndEsdtNft {
nonce: u64,
amount: BigUint,
) {
self.send()
.transfer_esdt_via_async_call(to, token_identifier, nonce, amount);
self.tx()
.to(to)
.esdt((token_identifier, nonce, amount))
.async_call_and_exit();
}

#[endpoint]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ pub trait Erc1155Marketplace {

let claimable_funds_mapper = self.get_claimable_funds_mapper();
for (token_identifier, amount) in claimable_funds_mapper.iter() {
self.send().direct(&caller, &token_identifier, 0, &amount);
self.tx()
.to(&caller)
.egld_or_single_esdt(&token_identifier, 0, &amount)
.transfer();
self.clear_claimable_funds(&token_identifier);
}
}
Expand Down Expand Up @@ -178,12 +181,10 @@ pub trait Erc1155Marketplace {

// refund losing bid
if !auction.current_winner.is_zero() {
self.send().direct(
&auction.current_winner,
&auction.token_identifier,
0,
&auction.current_bid,
);
self.tx()
.to(&auction.current_winner)
.egld_or_single_esdt(&auction.token_identifier, 0, &auction.current_bid)
.transfer();
}

// update auction bid and winner
Expand Down Expand Up @@ -217,12 +218,10 @@ pub trait Erc1155Marketplace {
self.add_claimable_funds(&auction.token_identifier, &cut_amount);

// send part of the bid to the original owner
self.send().direct(
&auction.original_owner,
&auction.token_identifier,
0,
&amount_to_send,
);
self.tx()
.to(&auction.original_owner)
.egld_or_single_esdt(&auction.token_identifier, 0, &amount_to_send)
.transfer();

// send token to winner
self.async_transfer_token(type_id, nft_id, auction.current_winner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,8 @@ pub trait RustTestingFrameworkTester: dummy_module::DummyModule {
#[payable("EGLD")]
#[endpoint]
fn recieve_egld_half(&self) {
let caller = self.blockchain().get_caller();
let payment_amount = &*self.call_value().egld_value() / 2u32;
self.send().direct(
&caller,
&EgldOrEsdtTokenIdentifier::egld(),
0,
&payment_amount,
);
self.tx().to(ToCaller).egld(payment_amount).transfer();
}

#[payable("*")]
Expand Down
17 changes: 9 additions & 8 deletions contracts/modules/src/bonding_curve/utils/user_endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ pub trait UserEndpointsModule: storage::StorageModule + events::EventsModule {
self.nonce_amount(&offered_token, nonce)
.update(|val| *val += sell_amount);

self.send()
.direct(&caller, &payment_token, 0u64, &calculated_price);
self.tx()
.to(&caller)
.egld_or_single_esdt(&payment_token, 0u64, &calculated_price)
.transfer();

self.token_details(&offered_token)
.update(|details| details.add_nonce(nonce));

Expand Down Expand Up @@ -116,12 +119,10 @@ pub trait UserEndpointsModule: storage::StorageModule + events::EventsModule {
},
};

self.send().direct(
&caller,
&offered_token,
0u64,
&(&payment - &calculated_price),
);
self.tx()
.to(&caller)
.egld_or_single_esdt(&offered_token, 0u64, &(&payment - &calculated_price))
.transfer();

self.buy_token_event(&caller, &calculated_price);
}
Expand Down
6 changes: 4 additions & 2 deletions contracts/modules/src/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ pub trait StakingModule {
staked_amount_mapper.set(&leftover_amount);

let staking_token = self.staking_token().get();
self.send()
.direct(&caller, &staking_token, 0, &unstake_amount);
self.tx()
.to(caller)
.egld_or_single_esdt(&staking_token, 0, &unstake_amount)
.transfer();
}

#[endpoint(voteSlashMember)]
Expand Down
8 changes: 5 additions & 3 deletions contracts/modules/src/token_merge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ pub trait TokenMergeModule:

let merged_token_payment =
self.create_merged_token(merged_token_id, &all_merged_instances, attr_creator);
let caller = self.blockchain().get_caller();
self.send()
.direct_non_zero_esdt_payment(&caller, &merged_token_payment);

self.tx()
.to(ToCaller)
.payment(&merged_token_payment)
.transfer_if_not_empty();

merged_token_payment
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,49 @@ where
}
}
}

impl<Env> TxPayment<Env> for &EsdtTokenPayment<Env::Api>
where
Env: TxEnv,
{
#[inline]
fn is_no_payment(&self, _env: &Env) -> bool {
self.amount == 0u32
}

#[inline]
fn perform_transfer_execute(
self,
env: &Env,
to: &ManagedAddress<Env::Api>,
gas_limit: u64,
fc: FunctionCall<Env::Api>,
) {
self.as_refs()
.perform_transfer_execute(env, to, gas_limit, fc);
}

#[inline]
fn with_normalized<From, To, F, R>(
self,
env: &Env,
from: &From,
to: To,
fc: FunctionCall<Env::Api>,
f: F,
) -> R
where
From: TxFrom<Env>,
To: TxToSpecified<Env>,
F: FnOnce(&ManagedAddress<Env::Api>, &BigUint<Env::Api>, &FunctionCall<Env::Api>) -> R,
{
self.as_refs().with_normalized(env, from, to, fc, f)
}

fn into_full_payment_data(self, _env: &Env) -> FullPaymentData<Env::Api> {
FullPaymentData {
egld: None,
multi_esdt: MultiEsdtPayment::from_single_item(self.clone()),
}
}
}
Loading