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 shrink 3 #1569

Draft
wants to merge 3 commits into
base: unified-shrink-2
Choose a base branch
from
Draft
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
8 changes: 4 additions & 4 deletions framework/base/src/types/interaction/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,19 +644,19 @@ where

fn into_normalized(self) -> ContractCallWithEgld<Api, OriginalResult> {
self.payment.with_normalized(
&self.env,
&self.from,
self.env,
self.from,
self.to,
self.data,
|norm_to, norm_egld, norm_fc| ContractCallWithEgld {
basic: ContractCallNoPayment {
_phantom: core::marker::PhantomData,
to: norm_to.clone(),
to: norm_to.clone_value(),
function_call: norm_fc.clone(),
explicit_gas_limit: UNSPECIFIED_GAS_LIMIT,
_return_type: core::marker::PhantomData,
},
egld_payment: norm_egld.clone(),
egld_payment: norm_egld.clone_value(),
},
)
}
Expand Down
8 changes: 4 additions & 4 deletions framework/base/src/types/interaction/tx_exec/tx_exec_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ where
pub fn async_call_and_exit(self) -> ! {
self.result_handler.save_callback_closure_to_storage();
self.payment.with_normalized(
&self.env,
&self.from,
self.env,
self.from,
self.to,
self.data.into(),
|norm_to, norm_egld, norm_fc| {
SendRawWrapper::<Api>::new().async_call_raw(
norm_to,
norm_egld,
&norm_to,
&norm_egld,
&norm_fc.function_name,
&norm_fc.arg_buffer,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ where
let gas = self.gas.gas_value(&self.env);

self.payment.with_normalized(
&self.env,
&self.from,
self.env,
self.from,
self.to,
self.data,
|norm_to, norm_egld, norm_fc| {
SendRawWrapper::<Api>::new().create_async_call_raw(
norm_to,
norm_egld,
&norm_to,
&norm_egld,
&norm_fc.function_name,
&norm_fc.arg_buffer,
callback_name,
Expand Down
8 changes: 4 additions & 4 deletions framework/base/src/types/interaction/tx_exec/tx_exec_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ where
let gas_limit = self.gas.gas_value(&self.env);

let raw_result = self.payment.with_normalized(
&self.env,
&self.from,
self.env,
self.from,
self.to,
self.data.into(),
|norm_to, norm_egld, norm_fc| {
SendRawWrapper::<Api>::new().execute_on_dest_context_raw(
gas_limit,
norm_to,
norm_egld,
&norm_to,
&norm_egld,
&norm_fc.function_name,
&norm_fc.arg_buffer,
)
Expand Down
12 changes: 8 additions & 4 deletions framework/base/src/types/interaction/tx_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use tx_payment_multi_esdt::TxPaymentMultiEsdt;

use crate::{
api::ManagedTypeApi,
types::{BigUint, ManagedAddress, ManagedBuffer, MultiEsdtPayment},
types::{BigUint, ManagedAddress, ManagedBuffer, ManagedRef, MultiEsdtPayment},
};

use super::{AnnotatedValue, FunctionCall, TxEnv, TxFrom, TxToSpecified};
Expand All @@ -42,16 +42,20 @@ where
/// Converts an ESDT call to a built-in function call, if necessary.
fn with_normalized<From, To, F, R>(
self,
env: &Env,
from: &From,
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;
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
FunctionCall<Env::Api>,
) -> R;

/// Payment data to be used by the testing framework. Will be refactored.
fn into_full_payment_data(self, env: &Env) -> FullPaymentData<Env::Api>;
Expand Down
17 changes: 11 additions & 6 deletions framework/base/src/types/interaction/tx_payment/tx_payment_egld.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{
contract_base::SendRawWrapper,
types::{
AnnotatedValue, BigUint, ManagedAddress, ManagedBuffer, ManagedVec, TxFrom, TxToSpecified,
AnnotatedValue, BigUint, ManagedAddress, ManagedBuffer, ManagedRef, ManagedVec, TxFrom,
TxToSpecified,
},
};

Expand Down Expand Up @@ -45,20 +46,24 @@ where
#[inline]
fn with_normalized<From, To, F, R>(
self,
env: &Env,
_from: &From,
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,
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
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, egld_value, &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, TxFrom, TxToSpecified};
use crate::types::{
BigUint, Egld, EgldOrEsdtTokenPayment, ManagedAddress, ManagedRef, TxFrom, TxToSpecified,
};

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

Expand Down Expand Up @@ -26,21 +28,25 @@ where

fn with_normalized<From, To, F, R>(
self,
env: &Env,
from: &From,
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,
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
FunctionCall<Env::Api>,
) -> R,
{
self.map_ref_egld_or_esdt(
(to, fc, f),
|(to, fc, f), amount| Egld(amount).with_normalized(env, from, to, fc, f),
|(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 @@ -75,21 +81,25 @@ where

fn with_normalized<From, To, F, R>(
self,
env: &Env,
from: &From,
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,
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
FunctionCall<Env::Api>,
) -> R,
{
self.map_egld_or_esdt(
(to, fc, f),
|(to, fc, f), amount| Egld(amount).with_normalized(env, from, to, fc, f),
|(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, TxFrom, TxToSpecified};
use crate::types::{
BigUint, EgldOrEsdtTokenPaymentRefs, ManagedAddress, ManagedRef, TxFrom, TxToSpecified,
};

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

Expand Down Expand Up @@ -26,21 +28,25 @@ where

fn with_normalized<From, To, F, R>(
self,
env: &Env,
from: &From,
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,
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
FunctionCall<Env::Api>,
) -> R,
{
self.map_egld_or_esdt(
(to, fc, f),
|(to, fc, f), amount| Egld(amount).with_normalized(env, from, to, fc, f),
|(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, EgldOrMultiEsdtPayment, ManagedAddress, TxFrom, TxToSpecified};
use crate::types::{
BigUint, EgldOrMultiEsdtPayment, ManagedAddress, ManagedRef, TxFrom, TxToSpecified,
};

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

Expand All @@ -25,16 +27,20 @@ where
#[inline]
fn with_normalized<From, To, F, R>(
self,
env: &Env,
from: &From,
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,
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
FunctionCall<Env::Api>,
) -> R,
{
self.as_refs().with_normalized(env, from, to, fc, f)
}
Expand Down Expand Up @@ -68,16 +74,20 @@ where
#[inline]
fn with_normalized<From, To, F, R>(
self,
env: &Env,
from: &From,
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,
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<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, TxFrom, TxToSpecified};
use crate::types::{
BigUint, EgldOrMultiEsdtPaymentRefs, ManagedAddress, ManagedRef, TxFrom, TxToSpecified,
};

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

Expand Down Expand Up @@ -29,16 +31,20 @@ where

fn with_normalized<From, To, F, R>(
self,
env: &Env,
from: &From,
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,
F: FnOnce(
ManagedRef<'_, Env::Api, ManagedAddress<Env::Api>>,
ManagedRef<'_, Env::Api, BigUint<Env::Api>>,
FunctionCall<Env::Api>,
) -> R,
{
match self {
EgldOrMultiEsdtPaymentRefs::Egld(egld_amount) => {
Expand Down
Loading
Loading