Skip to content

Commit

Permalink
Merge branch 'feat/unified' into uegld-replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
BiancaIalangi authored Mar 22, 2024
2 parents c374bfc + 52b4653 commit 778fe22
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
19 changes: 6 additions & 13 deletions framework/base/src/contract_base/wrappers/send_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,15 @@ where
/// Used especially for sending EGLD to regular accounts.
#[inline]
pub fn direct_egld(&self, to: &ManagedAddress<A>, amount: &BigUint<A>) {
self.send_raw_wrapper().direct_egld(to, amount, Empty)
Tx::new_tx_from_sc().to(to).egld(amount).transfer();
}

/// Sends EGLD to a given address, directly.
/// Used especially for sending EGLD to regular accounts.
///
/// If the amount is 0, it returns without error.
pub fn direct_non_zero_egld(&self, to: &ManagedAddress<A>, amount: &BigUint<A>) {
if amount == &0 {
return;
}

self.direct_egld(to, amount)
Tx::new_tx_from_sc().to(to).egld(amount).transfer_non_zero();
}

/// Sends either EGLD, ESDT or NFT to the target address,
Expand Down Expand Up @@ -291,13 +287,10 @@ where
to: &ManagedAddress<A>,
payments: &ManagedVec<A, EsdtTokenPayment<A>>,
) {
let _ = self.send_raw_wrapper().multi_esdt_transfer_execute(
to,
payments,
0,
&ManagedBuffer::new(),
&ManagedArgBuffer::new(),
);
Tx::new_tx_from_sc()
.to(to)
.multi_esdt_ref(payments)
.transfer();
}

/// Performs a simple ESDT/NFT transfer, but via async call.
Expand Down
16 changes: 16 additions & 0 deletions framework/base/src/types/interaction/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,22 @@ where
}
}

/// Sets a reference to multiple ESDT payments.
pub fn multi_esdt_ref(
self,
payments: &MultiEsdtPayment<Env::Api>,
) -> Tx<Env, From, To, &MultiEsdtPayment<Env::Api>, Gas, Data, RH> {
Tx {
env: self.env,
from: self.from,
to: self.to,
payment: payments,
gas: self.gas,
data: self.data,
result_handler: self.result_handler,
}
}

/// Backwards compatibility.
pub fn with_multi_token_transfer(
self,
Expand Down
5 changes: 4 additions & 1 deletion framework/base/src/types/interaction/tx_call_te.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ where
self.transfer_execute_with_gas(0)
}

/// Transfers funds, amount is greater than zero. Does nothing otherwise.
///
/// Can only used for simple transfers.
pub fn transfer_non_zero(self) {
if self.payment.is_no_payment() {
return;
}

self.transfer_execute_with_gas(0)
self.transfer();
}
}
30 changes: 28 additions & 2 deletions framework/base/src/types/interaction/tx_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ where
}
}

impl<Env> TxPayment<Env> for MultiEsdtPayment<Env::Api>
impl<Env> TxPayment<Env> for &MultiEsdtPayment<Env::Api>
where
Env: TxEnv,
{
Expand All @@ -135,13 +135,39 @@ where
) {
let _ = SendRawWrapper::<Env::Api>::new().multi_esdt_transfer_execute(
to,
&self,
self,
gas_limit,
&fc.function_name,
&fc.arg_buffer,
);
}

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

impl<Env> TxPayment<Env> for MultiEsdtPayment<Env::Api>
where
Env: TxEnv,
{
fn is_no_payment(&self) -> bool {
self.is_empty()
}

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

fn into_full_payment_data(self, env: &Env) -> FullPaymentData<Env::Api> {
FullPaymentData {
egld: None,
Expand Down

0 comments on commit 778fe22

Please sign in to comment.