Skip to content

Commit

Permalink
tx payment - with_normalized removed references
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Apr 17, 2024
1 parent 18510b0 commit c30b831
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 76 deletions.
2 changes: 1 addition & 1 deletion framework/base/src/types/interaction/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ where

fn into_normalized(self) -> ContractCallWithEgld<Api, OriginalResult> {
self.payment.with_normalized(
&self.env,
self.env,
self.from,
self.to,
self.data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ where
pub fn async_call_and_exit(self) -> ! {
self.result_handler.save_callback_closure_to_storage();
self.payment.with_normalized(
&self.env,
self.env,
self.from,
self.to,
self.data.into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ where
let gas = self.gas.gas_value(&self.env);

self.payment.with_normalized(
&self.env,
self.env,
self.from,
self.to,
self.data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ where
let gas_limit = self.gas.gas_value(&self.env);

let raw_result = self.payment.with_normalized(
&self.env,
self.env,
self.from,
self.to,
self.data.into(),
Expand Down
4 changes: 2 additions & 2 deletions framework/base/src/types/interaction/tx_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where
/// Converts an ESDT call to a built-in function call, if necessary.
fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -54,7 +54,7 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
FunctionCall<Env::Api>,
) -> R;

/// Payment data to be used by the testing framework. Will be refactored.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{
contract_base::SendRawWrapper,
types::{
AnnotatedValue, BigUint, ManagedAddress, ManagedBuffer, ManagedRef, ManagedVec, TxFrom, TxToSpecified
AnnotatedValue, BigUint, ManagedAddress, ManagedBuffer, ManagedRef, ManagedVec, TxFrom,
TxToSpecified,
},
};

Expand Down Expand Up @@ -45,7 +46,7 @@ where
#[inline]
fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
_from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -57,12 +58,12 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
) -> R
FunctionCall<Env::Api>,
) -> R,
{
to.with_value_ref(env, |to_addr| {
to.with_value_ref(&env, |to_addr| {
self.0
.with_value_ref(env, |egld_value| f(to_addr.into(), egld_value.into(), &fc))
.with_value_ref(&env, |egld_value| f(to_addr.into(), egld_value.into(), fc))
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::types::{BigUint, Egld, EgldOrEsdtTokenPayment, ManagedAddress, ManagedRef, TxFrom, TxToSpecified};
use crate::types::{
BigUint, Egld, EgldOrEsdtTokenPayment, ManagedAddress, ManagedRef, TxFrom, TxToSpecified,
};

use super::{FullPaymentData, FunctionCall, TxEnv, TxPayment};

Expand Down Expand Up @@ -26,7 +28,7 @@ where

fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -38,13 +40,13 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
) -> R
FunctionCall<Env::Api>,
) -> R,
{
self.map_ref_egld_or_esdt(
(from, to, fc, f),
|(from, to, fc, f), amount| Egld(amount).with_normalized(env, from, to, fc, f),
|(from, to, fc, f), esdt_payment| esdt_payment.with_normalized(env, from, to, fc, f),
(env, from, to, fc, f),
|(env, from, to, fc, f), amount| Egld(amount).with_normalized(env, from, to, fc, f),
|(env, from, to, fc, f), esdt_payment| esdt_payment.with_normalized(env, from, to, fc, f),
)
}

Expand Down Expand Up @@ -79,7 +81,7 @@ where

fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -91,13 +93,13 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
) -> R
FunctionCall<Env::Api>,
) -> R,
{
self.map_egld_or_esdt(
(from, to, fc, f),
|(from, to, fc, f), amount| Egld(amount).with_normalized(env, from, to, fc, f),
|(from, to, fc, f), esdt_payment| esdt_payment.with_normalized(env, from, to, fc, f),
(env, from, to, fc, f),
|(env, from, to, fc, f), amount| Egld(amount).with_normalized(env, from, to, fc, f),
|(env, from, to, fc, f), esdt_payment| esdt_payment.with_normalized(env, from, to, fc, f),
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::types::{BigUint, EgldOrEsdtTokenPaymentRefs, ManagedAddress, ManagedRef, TxFrom, TxToSpecified};
use crate::types::{
BigUint, EgldOrEsdtTokenPaymentRefs, ManagedAddress, ManagedRef, TxFrom, TxToSpecified,
};

use super::{Egld, FullPaymentData, FunctionCall, TxEnv, TxPayment};

Expand Down Expand Up @@ -26,7 +28,7 @@ where

fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -38,13 +40,13 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
) -> R
FunctionCall<Env::Api>,
) -> R,
{
self.map_egld_or_esdt(
(from, to, fc, f),
|(from, to, fc, f), amount| Egld(amount).with_normalized(env, from, to, fc, f),
|(from, to, fc, f), esdt_payment| esdt_payment.with_normalized(env, from, to, fc, f),
(env, from, to, fc, f),
|(env, from, to, fc, f), amount| Egld(amount).with_normalized(env, from, to, fc, f),
|(env, from, to, fc, f), esdt_payment| esdt_payment.with_normalized(env, from, to, fc, f),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ where
#[inline]
fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -39,8 +39,8 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
) -> R
FunctionCall<Env::Api>,
) -> R,
{
self.as_refs().with_normalized(env, from, to, fc, f)
}
Expand Down Expand Up @@ -74,7 +74,7 @@ where
#[inline]
fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -86,7 +86,7 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
FunctionCall<Env::Api>,
) -> R,
{
self.as_refs().with_normalized(env, from, to, fc, f)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::types::{BigUint, EgldOrMultiEsdtPaymentRefs, ManagedAddress, ManagedRef, TxFrom, TxToSpecified};
use crate::types::{
BigUint, EgldOrMultiEsdtPaymentRefs, ManagedAddress, ManagedRef, TxFrom, TxToSpecified,
};

use super::{Egld, FullPaymentData, FunctionCall, TxEnv, TxPayment};

Expand Down Expand Up @@ -29,7 +31,7 @@ where

fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -41,8 +43,8 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
) -> R
FunctionCall<Env::Api>,
) -> R,
{
match self {
EgldOrMultiEsdtPaymentRefs::Egld(egld_amount) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ where

fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -59,15 +59,19 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
) -> R
FunctionCall<Env::Api>,
) -> R,
{
match self.len() {
0 => ().with_normalized(env, from, to, fc, f),
1 => self.get(0).as_refs().with_normalized(env, from, to, fc, f),
_ => to.with_value_ref(env, |to_addr| {
_ => to.with_value_ref(&env, |to_addr| {
let fc_conv = fc.convert_to_multi_transfer_esdt_call(to_addr, self);
f((&from.resolve_address(env)).into(), BigUint::zero_ref(), &fc_conv)
f(
(&from.resolve_address(&env)).into(),
BigUint::zero_ref(),
fc_conv,
)
}),
}
}
Expand Down Expand Up @@ -104,7 +108,7 @@ where
#[inline]
fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -116,8 +120,8 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
) -> R
FunctionCall<Env::Api>,
) -> R,
{
self.deref().with_normalized(env, from, to, fc, f)
}
Expand Down Expand Up @@ -150,7 +154,7 @@ where
#[inline]
fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -162,8 +166,8 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
) -> R
FunctionCall<Env::Api>,
) -> R,
{
(&self).with_normalized(env, from, to, fc, f)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
#[inline]
fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
_from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -37,10 +37,10 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
) -> R
FunctionCall<Env::Api>,
) -> R,
{
to.with_value_ref(env, |to_addr| f(to_addr.into(), BigUint::zero_ref(), &fc))
to.with_value_ref(&env, |to_addr| f(to_addr.into(), BigUint::zero_ref(), fc))
}

fn into_full_payment_data(self, _env: &Env) -> FullPaymentData<Env::Api> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::types::{
BigUint, EsdtTokenPayment, ManagedAddress, ManagedRef, MultiEsdtPayment, TxFrom, TxToSpecified
BigUint, EsdtTokenPayment, ManagedAddress, ManagedRef, MultiEsdtPayment, TxFrom, TxToSpecified,
};

use super::{FullPaymentData, FunctionCall, TxEnv, TxPayment};
Expand Down Expand Up @@ -28,7 +28,7 @@ where
#[inline]
fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -40,8 +40,8 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
) -> R
FunctionCall<Env::Api>,
) -> R,
{
self.as_refs().with_normalized(env, from, to, fc, f)
}
Expand Down Expand Up @@ -78,7 +78,7 @@ where
#[inline]
fn with_normalized<From, To, F, R>(
self,
env: &Env,
env: Env,
from: From,
to: To,
fc: FunctionCall<Env::Api>,
Expand All @@ -90,8 +90,8 @@ where
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
&FunctionCall<Env::Api>,
) -> R
FunctionCall<Env::Api>,
) -> R,
{
self.as_refs().with_normalized(env, from, to, fc, f)
}
Expand Down
Loading

0 comments on commit c30b831

Please sign in to comment.