From 6b29b30a3766e5d17552c0386f2ac5ccb99842ae Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Mon, 15 Apr 2024 18:58:12 +0300 Subject: [PATCH 1/4] unified syntas - added inlines --- .../interaction/annotated/annotated_impl_big_uint.rs | 5 +++++ .../annotated/annotated_impl_managed_buffer.rs | 3 +++ framework/base/src/types/interaction/markers/to_self.rs | 1 + .../interaction/system_proxy/esdt_system_sc_proxy.rs | 2 +- framework/base/src/types/interaction/tx_payment.rs | 1 + .../src/types/interaction/tx_payment/tx_payment_egld.rs | 4 ++++ .../types/interaction/tx_payment/tx_payment_multi_esdt.rs | 8 +++++++- .../src/types/interaction/tx_payment/tx_payment_none.rs | 7 +++++-- .../interaction/tx_payment/tx_payment_single_esdt_ref.rs | 4 ++-- framework/base/src/types/interaction/tx_to.rs | 1 + framework/base/src/types/managed/basic/big_uint.rs | 7 +++++++ .../types/managed/wrapped/egld_or_esdt_token_payment.rs | 2 +- 12 files changed, 38 insertions(+), 7 deletions(-) diff --git a/framework/base/src/types/interaction/annotated/annotated_impl_big_uint.rs b/framework/base/src/types/interaction/annotated/annotated_impl_big_uint.rs index ea2250399d..92802fba00 100644 --- a/framework/base/src/types/interaction/annotated/annotated_impl_big_uint.rs +++ b/framework/base/src/types/interaction/annotated/annotated_impl_big_uint.rs @@ -18,6 +18,7 @@ where self } + #[inline] fn with_value_ref(&self, _env: &Env, f: F) -> R where F: FnOnce(&BigUint) -> R, @@ -38,10 +39,12 @@ where (*self).clone() } + #[inline] fn into_value(self, _env: &Env) -> BigUint { self.clone() } + #[inline] fn with_value_ref(&self, _env: &Env, f: F) -> R where F: FnOnce(&BigUint) -> R, @@ -58,6 +61,7 @@ where self.to_display() } + #[inline] fn to_value(&self, _env: &Env) -> BigUint { (*self).clone_value() } @@ -66,6 +70,7 @@ where self.clone_value() } + #[inline] fn with_value_ref(&self, _env: &Env, f: F) -> R where F: FnOnce(&BigUint) -> R, diff --git a/framework/base/src/types/interaction/annotated/annotated_impl_managed_buffer.rs b/framework/base/src/types/interaction/annotated/annotated_impl_managed_buffer.rs index b8d4fc8fd7..61cf142dfb 100644 --- a/framework/base/src/types/interaction/annotated/annotated_impl_managed_buffer.rs +++ b/framework/base/src/types/interaction/annotated/annotated_impl_managed_buffer.rs @@ -10,14 +10,17 @@ where self.hex_expr() } + #[inline] fn to_value(&self, _env: &Env) -> ManagedBuffer { self.clone() } + #[inline] fn into_value(self, _env: &Env) -> ManagedBuffer { self } + #[inline] fn with_value_ref(&self, _env: &Env, f: F) -> R where F: FnOnce(&ManagedBuffer) -> R, diff --git a/framework/base/src/types/interaction/markers/to_self.rs b/framework/base/src/types/interaction/markers/to_self.rs index dee4d5ed3a..f339a448e2 100644 --- a/framework/base/src/types/interaction/markers/to_self.rs +++ b/framework/base/src/types/interaction/markers/to_self.rs @@ -17,6 +17,7 @@ where self.with_address_ref(env, |addr_ref| addr_ref.hex_expr()) } + #[inline] fn to_value(&self, _env: &TxScEnv) -> ManagedAddress { BlockchainWrapper::::new().get_sc_address() } diff --git a/framework/base/src/types/interaction/system_proxy/esdt_system_sc_proxy.rs b/framework/base/src/types/interaction/system_proxy/esdt_system_sc_proxy.rs index 3589f4ce28..4463c9ec64 100644 --- a/framework/base/src/types/interaction/system_proxy/esdt_system_sc_proxy.rs +++ b/framework/base/src/types/interaction/system_proxy/esdt_system_sc_proxy.rs @@ -101,7 +101,7 @@ where token_ticker: &ManagedBuffer, properties: NonFungibleTokenProperties, ) -> IssueCall { - let zero = BigUint::zero(); + let zero = BigUint::zero_ref(); self.issue( issue_cost, EsdtTokenType::NonFungible, diff --git a/framework/base/src/types/interaction/tx_payment.rs b/framework/base/src/types/interaction/tx_payment.rs index e72a5b9fa6..b8979bf50c 100644 --- a/framework/base/src/types/interaction/tx_payment.rs +++ b/framework/base/src/types/interaction/tx_payment.rs @@ -62,6 +62,7 @@ pub trait TxPaymentEgldOnly: TxPayment + AnnotatedValue(&self, env: &Env, f: F) -> R where F: FnOnce(&BigUint) -> R, diff --git a/framework/base/src/types/interaction/tx_payment/tx_payment_egld.rs b/framework/base/src/types/interaction/tx_payment/tx_payment_egld.rs index ad0969aca1..6bda81cd29 100644 --- a/framework/base/src/types/interaction/tx_payment/tx_payment_egld.rs +++ b/framework/base/src/types/interaction/tx_payment/tx_payment_egld.rs @@ -42,6 +42,7 @@ where }) } + #[inline] fn with_normalized( self, env: &Env, @@ -78,14 +79,17 @@ where self.0.annotation(env) } + #[inline] fn to_value(&self, env: &Env) -> BigUint { self.0.to_value(env) } + #[inline] fn into_value(self, env: &Env) -> BigUint { self.0.into_value(env) } + #[inline] fn with_value_ref(&self, env: &Env, f: F) -> R where F: FnOnce(&BigUint) -> R, diff --git a/framework/base/src/types/interaction/tx_payment/tx_payment_multi_esdt.rs b/framework/base/src/types/interaction/tx_payment/tx_payment_multi_esdt.rs index 892fd2c114..7cb062c50b 100644 --- a/framework/base/src/types/interaction/tx_payment/tx_payment_multi_esdt.rs +++ b/framework/base/src/types/interaction/tx_payment/tx_payment_multi_esdt.rs @@ -63,7 +63,7 @@ where 1 => self.get(0).as_refs().with_normalized(env, from, to, fc, f), _ => to.with_address_ref(env, |to_addr| { let fc_conv = fc.convert_to_multi_transfer_esdt_call(to_addr, self); - f(&from.resolve_address(env), &BigUint::zero(), &fc_conv) + f(&from.resolve_address(env), &*BigUint::zero_ref(), &fc_conv) }), } } @@ -80,10 +80,12 @@ impl<'a, Env> TxPayment for ManagedRef<'a, Env::Api, MultiEsdtPayment bool { self.deref().is_empty() } + #[inline] fn perform_transfer_execute( self, env: &Env, @@ -95,6 +97,7 @@ where .perform_transfer_execute(env, to, gas_limit, fc) } + #[inline] fn with_normalized( self, env: &Env, @@ -120,10 +123,12 @@ impl TxPayment for MultiEsdtPayment where Env: TxEnv, { + #[inline] fn is_no_payment(&self, _env: &Env) -> bool { self.is_empty() } + #[inline] fn perform_transfer_execute( self, env: &Env, @@ -134,6 +139,7 @@ where (&self).perform_transfer_execute(env, to, gas_limit, fc); } + #[inline] fn with_normalized( self, env: &Env, diff --git a/framework/base/src/types/interaction/tx_payment/tx_payment_none.rs b/framework/base/src/types/interaction/tx_payment/tx_payment_none.rs index fe6016e43b..8725163f67 100644 --- a/framework/base/src/types/interaction/tx_payment/tx_payment_none.rs +++ b/framework/base/src/types/interaction/tx_payment/tx_payment_none.rs @@ -6,10 +6,12 @@ impl TxPayment for () where Env: TxEnv, { + #[inline] fn is_no_payment(&self, _env: &Env) -> bool { true } + #[inline] fn perform_transfer_execute( self, env: &Env, @@ -17,9 +19,10 @@ where gas_limit: u64, fc: FunctionCall, ) { - Egld(BigUint::zero()).perform_transfer_execute(env, to, gas_limit, fc); + Egld(BigUint::zero_ref()).perform_transfer_execute(env, to, gas_limit, fc); } + #[inline] fn with_normalized( self, env: &Env, @@ -33,7 +36,7 @@ where To: TxToSpecified, F: FnOnce(&ManagedAddress, &BigUint, &FunctionCall) -> R, { - to.with_address_ref(env, |to_addr| f(to_addr, &BigUint::zero(), &fc)) + to.with_address_ref(env, |to_addr| f(to_addr, &*BigUint::zero_ref(), &fc)) } fn into_full_payment_data(self, _env: &Env) -> FullPaymentData { diff --git a/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_ref.rs b/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_ref.rs index bc5e2532a8..e19a35123d 100644 --- a/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_ref.rs +++ b/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_ref.rs @@ -62,10 +62,10 @@ where to.with_address_ref(env, |to_addr| { if self.token_nonce == 0 { let fc_conv = fc.convert_to_single_transfer_fungible_call(self); - f(to_addr, &BigUint::zero(), &fc_conv) + f(to_addr, &*BigUint::zero_ref(), &fc_conv) } else { let fc_conv = fc.convert_to_single_transfer_nft_call(to_addr, self); - f(&from.resolve_address(env), &BigUint::zero(), &fc_conv) + f(&from.resolve_address(env), &*BigUint::zero_ref(), &fc_conv) } }) } diff --git a/framework/base/src/types/interaction/tx_to.rs b/framework/base/src/types/interaction/tx_to.rs index 6ba0f6eec8..c365809f05 100644 --- a/framework/base/src/types/interaction/tx_to.rs +++ b/framework/base/src/types/interaction/tx_to.rs @@ -17,6 +17,7 @@ where /// Avoids a clone when performing transfer-execute. /// /// Other than that, does thesame as `AnnotatedValue::into_value`. + #[inline] fn with_address_ref(&self, env: &Env, f: F) -> R where F: FnOnce(&ManagedAddress) -> R, diff --git a/framework/base/src/types/managed/basic/big_uint.rs b/framework/base/src/types/managed/basic/big_uint.rs index 5f32388093..eb34d765cf 100644 --- a/framework/base/src/types/managed/basic/big_uint.rs +++ b/framework/base/src/types/managed/basic/big_uint.rs @@ -12,6 +12,7 @@ use crate::{ TopEncodeOutput, TryStaticCast, }, formatter::{hex_util::encode_bytes_as_hex, FormatBuffer, FormatByteReceiver, SCDisplay}, + proxy_imports::ManagedRef, types::{heap::BoxedBytes, ManagedBuffer, ManagedBufferCachedBuilder, ManagedType}, }; @@ -146,6 +147,12 @@ impl BigUint { BigUint::from_handle(handle) } + pub fn zero_ref() -> ManagedRef<'static, M, BigUint> { + let handle: M::BigIntHandle = use_raw_handle(const_handles::BIG_INT_CONST_ZERO); + M::managed_type_impl().bi_set_int64(handle.clone(), 0); + unsafe { ManagedRef::wrap_handle(handle) } + } + #[inline] pub fn to_u64(&self) -> Option { let api = M::managed_type_impl(); diff --git a/framework/base/src/types/managed/wrapped/egld_or_esdt_token_payment.rs b/framework/base/src/types/managed/wrapped/egld_or_esdt_token_payment.rs index ffce0c44e7..12670295cf 100644 --- a/framework/base/src/types/managed/wrapped/egld_or_esdt_token_payment.rs +++ b/framework/base/src/types/managed/wrapped/egld_or_esdt_token_payment.rs @@ -165,7 +165,7 @@ impl<'a, M: ManagedTypeApi> EgldOrEsdtTokenPaymentRefs<'a, M> { } pub fn is_empty(&self) -> bool { - self.amount == &BigUint::zero() + self.amount == &0u32 } pub fn map_egld_or_esdt(self, context: Context, for_egld: D, for_esdt: F) -> U From 958aeeb01e919290c190590744ebaf5e1275cfc1 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Tue, 16 Apr 2024 16:56:31 +0300 Subject: [PATCH 2/4] unified syntax - inlines & code deduplication --- .../tx_payment/tx_payment_egld_or_esdt.rs | 2 + .../tx_payment_egld_or_multi_esdt.rs | 64 +++++-------------- .../tx_payment/tx_payment_single_esdt.rs | 3 + .../tx_payment/tx_payment_single_esdt_ref.rs | 1 + .../tx_payment_single_esdt_triple.rs | 3 + .../managed/wrapped/esdt_token_payment.rs | 1 + 6 files changed, 25 insertions(+), 49 deletions(-) diff --git a/framework/base/src/types/interaction/tx_payment/tx_payment_egld_or_esdt.rs b/framework/base/src/types/interaction/tx_payment/tx_payment_egld_or_esdt.rs index a4ac0577ff..8c5d62e49a 100644 --- a/framework/base/src/types/interaction/tx_payment/tx_payment_egld_or_esdt.rs +++ b/framework/base/src/types/interaction/tx_payment/tx_payment_egld_or_esdt.rs @@ -57,10 +57,12 @@ impl TxPayment for EgldOrEsdtTokenPayment where Env: TxEnv, { + #[inline] fn is_no_payment(&self, env: &Env) -> bool { (&self).is_no_payment(env) } + #[inline] fn perform_transfer_execute( self, env: &Env, diff --git a/framework/base/src/types/interaction/tx_payment/tx_payment_egld_or_multi_esdt.rs b/framework/base/src/types/interaction/tx_payment/tx_payment_egld_or_multi_esdt.rs index 2538383494..bde3528eb3 100644 --- a/framework/base/src/types/interaction/tx_payment/tx_payment_egld_or_multi_esdt.rs +++ b/framework/base/src/types/interaction/tx_payment/tx_payment_egld_or_multi_esdt.rs @@ -1,6 +1,6 @@ use crate::types::{BigUint, EgldOrMultiEsdtPayment, ManagedAddress, TxFrom, TxToSpecified}; -use super::{Egld, FullPaymentData, FunctionCall, TxEnv, TxPayment}; +use super::{FullPaymentData, FunctionCall, TxEnv, TxPayment}; impl TxPayment for EgldOrMultiEsdtPayment where @@ -10,6 +10,7 @@ where self.is_empty() } + #[inline] fn perform_transfer_execute( self, env: &Env, @@ -17,16 +18,11 @@ where gas_limit: u64, fc: FunctionCall, ) { - match self { - EgldOrMultiEsdtPayment::Egld(egld_amount) => { - Egld(egld_amount).perform_transfer_execute(env, to, gas_limit, fc) - }, - EgldOrMultiEsdtPayment::MultiEsdt(multi_esdt_payment) => { - multi_esdt_payment.perform_transfer_execute(env, to, gas_limit, fc) - }, - } + self.as_refs() + .perform_transfer_execute(env, to, gas_limit, fc) } + #[inline] fn with_normalized( self, env: &Env, @@ -40,25 +36,12 @@ where To: TxToSpecified, F: FnOnce(&ManagedAddress, &BigUint, &FunctionCall) -> R, { - match self { - EgldOrMultiEsdtPayment::Egld(egld_amount) => { - Egld(egld_amount).with_normalized(env, from, to, fc, f) - }, - EgldOrMultiEsdtPayment::MultiEsdt(multi_esdt_payment) => { - multi_esdt_payment.with_normalized(env, from, to, fc, f) - }, - } + self.as_refs().with_normalized(env, from, to, fc, f) } + #[inline] fn into_full_payment_data(self, env: &Env) -> FullPaymentData { - match self { - EgldOrMultiEsdtPayment::Egld(egld_amount) => { - TxPayment::::into_full_payment_data(Egld(egld_amount), env) - }, - EgldOrMultiEsdtPayment::MultiEsdt(multi_esdt_payment) => { - TxPayment::::into_full_payment_data(multi_esdt_payment, env) - }, - } + self.as_refs().into_full_payment_data(env) } } @@ -70,6 +53,7 @@ where self.is_empty() } + #[inline] fn perform_transfer_execute( self, env: &Env, @@ -77,16 +61,11 @@ where gas_limit: u64, fc: FunctionCall, ) { - match self { - EgldOrMultiEsdtPayment::Egld(egld_amount) => { - Egld(egld_amount).perform_transfer_execute(env, to, gas_limit, fc) - }, - EgldOrMultiEsdtPayment::MultiEsdt(multi_esdt_payment) => { - multi_esdt_payment.perform_transfer_execute(env, to, gas_limit, fc) - }, - } + self.as_refs() + .perform_transfer_execute(env, to, gas_limit, fc) } + #[inline] fn with_normalized( self, env: &Env, @@ -100,24 +79,11 @@ where To: TxToSpecified, F: FnOnce(&ManagedAddress, &BigUint, &FunctionCall) -> R, { - match self { - EgldOrMultiEsdtPayment::Egld(egld_amount) => { - Egld(egld_amount).with_normalized(env, from, to, fc, f) - }, - EgldOrMultiEsdtPayment::MultiEsdt(multi_esdt_payment) => { - multi_esdt_payment.with_normalized(env, from, to, fc, f) - }, - } + self.as_refs().with_normalized(env, from, to, fc, f) } + #[inline] fn into_full_payment_data(self, env: &Env) -> FullPaymentData { - match self { - EgldOrMultiEsdtPayment::Egld(egld_amount) => { - TxPayment::::into_full_payment_data(Egld(egld_amount), env) - }, - EgldOrMultiEsdtPayment::MultiEsdt(multi_esdt_payment) => { - TxPayment::::into_full_payment_data(multi_esdt_payment, env) - }, - } + self.as_refs().into_full_payment_data(env) } } diff --git a/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt.rs b/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt.rs index 975a5d0d78..d5a87c4bde 100644 --- a/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt.rs +++ b/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt.rs @@ -8,10 +8,12 @@ impl TxPayment for EsdtTokenPayment where Env: TxEnv, { + #[inline] fn is_no_payment(&self, _env: &Env) -> bool { self.amount == 0u32 } + #[inline] fn perform_transfer_execute( self, env: &Env, @@ -23,6 +25,7 @@ where .perform_transfer_execute(env, to, gas_limit, fc); } + #[inline] fn with_normalized( self, env: &Env, diff --git a/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_ref.rs b/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_ref.rs index e19a35123d..c17ec71c8e 100644 --- a/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_ref.rs +++ b/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_ref.rs @@ -11,6 +11,7 @@ impl<'a, Env> TxPayment for EsdtTokenPaymentRefs<'a, Env::Api> where Env: TxEnv, { + #[inline] fn is_no_payment(&self, _env: &Env) -> bool { self.amount == &0u32 } diff --git a/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_triple.rs b/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_triple.rs index c49062eb27..458e631a30 100644 --- a/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_triple.rs +++ b/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_triple.rs @@ -12,6 +12,7 @@ where self.2 == 0u32 } + #[inline] fn perform_transfer_execute( self, env: &Env, @@ -22,6 +23,7 @@ where EsdtTokenPayment::from(self).perform_transfer_execute(env, to, gas_limit, fc) } + #[inline] fn with_normalized( self, env: &Env, @@ -38,6 +40,7 @@ where EsdtTokenPayment::from(self).with_normalized(env, from, to, fc, f) } + #[inline] fn into_full_payment_data(self, env: &Env) -> FullPaymentData { EsdtTokenPayment::from(self).into_full_payment_data(env) } diff --git a/framework/base/src/types/managed/wrapped/esdt_token_payment.rs b/framework/base/src/types/managed/wrapped/esdt_token_payment.rs index ac7a54c442..5dcfeceaab 100644 --- a/framework/base/src/types/managed/wrapped/esdt_token_payment.rs +++ b/framework/base/src/types/managed/wrapped/esdt_token_payment.rs @@ -237,6 +237,7 @@ impl EsdtTokenPayment { } impl<'a, M: ManagedTypeApi> EsdtTokenPaymentRefs<'a, M> { + #[inline] pub fn new( token_identifier: &'a TokenIdentifier, token_nonce: u64, From ba4b49d9fe4891fe4c617003f44e58a57bdfaa88 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Tue, 16 Apr 2024 19:44:53 +0300 Subject: [PATCH 3/4] unified syntax - removed with_address_ref --- .../base/src/types/interaction/markers/to_caller.rs | 2 +- .../base/src/types/interaction/markers/to_self.rs | 2 +- .../base/src/types/interaction/tx_exec/tx_exec_te.rs | 2 +- framework/base/src/types/interaction/tx_from.rs | 1 + .../types/interaction/tx_payment/tx_payment_egld.rs | 2 +- .../interaction/tx_payment/tx_payment_multi_esdt.rs | 2 +- .../types/interaction/tx_payment/tx_payment_none.rs | 2 +- .../tx_payment/tx_payment_single_esdt_ref.rs | 2 +- framework/base/src/types/interaction/tx_to.rs | 10 ---------- 9 files changed, 8 insertions(+), 17 deletions(-) diff --git a/framework/base/src/types/interaction/markers/to_caller.rs b/framework/base/src/types/interaction/markers/to_caller.rs index f24191ce9f..5c9a1ad500 100644 --- a/framework/base/src/types/interaction/markers/to_caller.rs +++ b/framework/base/src/types/interaction/markers/to_caller.rs @@ -14,7 +14,7 @@ where Api: CallTypeApi + BlockchainApi, { fn annotation(&self, env: &TxScEnv) -> ManagedBuffer { - self.with_address_ref(env, |addr_ref| addr_ref.hex_expr()) + self.with_value_ref(env, |addr_ref| addr_ref.hex_expr()) } fn to_value(&self, _env: &TxScEnv) -> ManagedAddress { diff --git a/framework/base/src/types/interaction/markers/to_self.rs b/framework/base/src/types/interaction/markers/to_self.rs index f339a448e2..3295beb0ec 100644 --- a/framework/base/src/types/interaction/markers/to_self.rs +++ b/framework/base/src/types/interaction/markers/to_self.rs @@ -14,7 +14,7 @@ where Api: CallTypeApi + BlockchainApi, { fn annotation(&self, env: &TxScEnv) -> ManagedBuffer { - self.with_address_ref(env, |addr_ref| addr_ref.hex_expr()) + self.with_value_ref(env, |addr_ref| addr_ref.hex_expr()) } #[inline] diff --git a/framework/base/src/types/interaction/tx_exec/tx_exec_te.rs b/framework/base/src/types/interaction/tx_exec/tx_exec_te.rs index a484dd2fdb..95768e4074 100644 --- a/framework/base/src/types/interaction/tx_exec/tx_exec_te.rs +++ b/framework/base/src/types/interaction/tx_exec/tx_exec_te.rs @@ -16,7 +16,7 @@ where RH: TxEmptyResultHandler>, { fn transfer_execute_with_gas(self, gas_limit: u64) { - self.to.with_address_ref(&self.env, |to| { + self.to.with_value_ref(&self.env, |to| { self.payment .perform_transfer_execute(&self.env, to, gas_limit, self.data.into()); }); diff --git a/framework/base/src/types/interaction/tx_from.rs b/framework/base/src/types/interaction/tx_from.rs index 039cb2c34c..b6c5b93859 100644 --- a/framework/base/src/types/interaction/tx_from.rs +++ b/framework/base/src/types/interaction/tx_from.rs @@ -20,6 +20,7 @@ impl TxFrom for () where Env: TxEnv, { + #[inline] fn resolve_address(&self, env: &Env) -> ManagedAddress { env.resolve_sender_address() } diff --git a/framework/base/src/types/interaction/tx_payment/tx_payment_egld.rs b/framework/base/src/types/interaction/tx_payment/tx_payment_egld.rs index 6bda81cd29..161fdfea1e 100644 --- a/framework/base/src/types/interaction/tx_payment/tx_payment_egld.rs +++ b/framework/base/src/types/interaction/tx_payment/tx_payment_egld.rs @@ -56,7 +56,7 @@ where To: TxToSpecified, F: FnOnce(&ManagedAddress, &BigUint, &FunctionCall) -> R, { - to.with_address_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)) }) diff --git a/framework/base/src/types/interaction/tx_payment/tx_payment_multi_esdt.rs b/framework/base/src/types/interaction/tx_payment/tx_payment_multi_esdt.rs index 7cb062c50b..9541280dc6 100644 --- a/framework/base/src/types/interaction/tx_payment/tx_payment_multi_esdt.rs +++ b/framework/base/src/types/interaction/tx_payment/tx_payment_multi_esdt.rs @@ -61,7 +61,7 @@ where 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_address_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), &*BigUint::zero_ref(), &fc_conv) }), diff --git a/framework/base/src/types/interaction/tx_payment/tx_payment_none.rs b/framework/base/src/types/interaction/tx_payment/tx_payment_none.rs index 8725163f67..781f9a431a 100644 --- a/framework/base/src/types/interaction/tx_payment/tx_payment_none.rs +++ b/framework/base/src/types/interaction/tx_payment/tx_payment_none.rs @@ -36,7 +36,7 @@ where To: TxToSpecified, F: FnOnce(&ManagedAddress, &BigUint, &FunctionCall) -> R, { - to.with_address_ref(env, |to_addr| f(to_addr, &*BigUint::zero_ref(), &fc)) + to.with_value_ref(env, |to_addr| f(to_addr, &*BigUint::zero_ref(), &fc)) } fn into_full_payment_data(self, _env: &Env) -> FullPaymentData { diff --git a/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_ref.rs b/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_ref.rs index c17ec71c8e..151f9c3598 100644 --- a/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_ref.rs +++ b/framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_ref.rs @@ -60,7 +60,7 @@ where To: TxToSpecified, F: FnOnce(&ManagedAddress, &BigUint, &FunctionCall) -> R, { - to.with_address_ref(env, |to_addr| { + to.with_value_ref(env, |to_addr| { if self.token_nonce == 0 { let fc_conv = fc.convert_to_single_transfer_fungible_call(self); f(to_addr, &*BigUint::zero_ref(), &fc_conv) diff --git a/framework/base/src/types/interaction/tx_to.rs b/framework/base/src/types/interaction/tx_to.rs index c365809f05..4190059ace 100644 --- a/framework/base/src/types/interaction/tx_to.rs +++ b/framework/base/src/types/interaction/tx_to.rs @@ -14,16 +14,6 @@ pub trait TxToSpecified: TxTo + AnnotatedValue(&self, env: &Env, f: F) -> R - where - F: FnOnce(&ManagedAddress) -> R, - { - self.with_value_ref(env, f) - } } impl TxTo for ManagedAddress where Env: TxEnv {} From ed4a4a8d520777867559b74123fa5b8dc829614e Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Tue, 16 Apr 2024 19:50:14 +0300 Subject: [PATCH 4/4] unified syntax - removed with_egld_value --- framework/base/src/types/interaction/tx.rs | 2 +- .../src/types/interaction/tx_exec/tx_exec_deploy.rs | 8 ++++---- .../src/types/interaction/tx_exec/tx_exec_upgrade.rs | 8 ++++---- framework/base/src/types/interaction/tx_payment.rs | 11 ----------- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/framework/base/src/types/interaction/tx.rs b/framework/base/src/types/interaction/tx.rs index 98d88e499a..8a1f7899c5 100644 --- a/framework/base/src/types/interaction/tx.rs +++ b/framework/base/src/types/interaction/tx.rs @@ -888,7 +888,7 @@ where ContractDeploy { _phantom: core::marker::PhantomData, to: ManagedOption::none(), - egld_payment: value.payment.into_egld_payment(&value.env), + egld_payment: value.payment.into_value(&value.env), explicit_gas_limit: UNSPECIFIED_GAS_LIMIT, arg_buffer: value.data.arg_buffer, _return_type: core::marker::PhantomData, diff --git a/framework/base/src/types/interaction/tx_exec/tx_exec_deploy.rs b/framework/base/src/types/interaction/tx_exec/tx_exec_deploy.rs index 9ccb4bdd2a..63b9e6dc32 100644 --- a/framework/base/src/types/interaction/tx_exec/tx_exec_deploy.rs +++ b/framework/base/src/types/interaction/tx_exec/tx_exec_deploy.rs @@ -31,7 +31,7 @@ where fn execute_deploy_raw(self) -> (ManagedAddress, ManagedVec>, RH) { let gas_limit = self.gas.gas_value(&self.env); - let (new_address, raw_results) = self.payment.with_egld_value(&self.env, |egld_value| { + let (new_address, raw_results) = self.payment.with_value_ref(&self.env, |egld_value| { SendRawWrapper::::new().deploy_contract( gas_limit, egld_value, @@ -69,7 +69,7 @@ where ) -> (ManagedAddress, ManagedVec>, RH) { let gas_limit = self.gas.gas_value(&self.env); - let (new_address, raw_results) = self.payment.with_egld_value(&self.env, |egld_value| { + let (new_address, raw_results) = self.payment.with_value_ref(&self.env, |egld_value| { SendRawWrapper::::new().deploy_from_source_contract( gas_limit, egld_value, @@ -235,7 +235,7 @@ where )] pub fn upgrade_contract(self, code: &ManagedBuffer, code_metadata: CodeMetadata) { let gas = self.gas.explicit_or_gas_left(&self.env); - self.payment.with_egld_value(&self.env, |egld_value| { + self.payment.with_value_ref(&self.env, |egld_value| { SendRawWrapper::::new().upgrade_contract( &self.to, gas, @@ -268,7 +268,7 @@ where code_metadata: CodeMetadata, ) { let gas = self.gas.explicit_or_gas_left(&self.env); - self.payment.with_egld_value(&self.env, |egld_value| { + self.payment.with_value_ref(&self.env, |egld_value| { SendRawWrapper::::new().upgrade_from_source_contract( &self.to, gas, diff --git a/framework/base/src/types/interaction/tx_exec/tx_exec_upgrade.rs b/framework/base/src/types/interaction/tx_exec/tx_exec_upgrade.rs index b97591ab12..4897e7f574 100644 --- a/framework/base/src/types/interaction/tx_exec/tx_exec_upgrade.rs +++ b/framework/base/src/types/interaction/tx_exec/tx_exec_upgrade.rs @@ -29,7 +29,7 @@ where /// TODO: change return type to `!`. pub fn upgrade_async_call_and_exit(self) { let gas = self.gas.explicit_or_gas_left(&self.env); - self.payment.with_egld_value(&self.env, |egld_value| { + self.payment.with_value_ref(&self.env, |egld_value| { SendRawWrapper::::new().upgrade_contract( &self.to, gas, @@ -64,7 +64,7 @@ where /// TODO: change return type to `!`. pub fn upgrade_async_call_and_exit(self) { let gas = self.gas.explicit_or_gas_left(&self.env); - self.payment.with_egld_value(&self.env, |egld_value| { + self.payment.with_value_ref(&self.env, |egld_value| { SendRawWrapper::::new().upgrade_from_source_contract( &self.to, gas, @@ -98,7 +98,7 @@ where )] pub fn upgrade_contract(self, code: &ManagedBuffer, code_metadata: CodeMetadata) { let gas = self.gas.explicit_or_gas_left(&self.env); - self.payment.with_egld_value(&self.env, |egld_value| { + self.payment.with_value_ref(&self.env, |egld_value| { SendRawWrapper::::new().upgrade_contract( &self.to, gas, @@ -127,7 +127,7 @@ where code_metadata: CodeMetadata, ) { let gas = self.gas.explicit_or_gas_left(&self.env); - self.payment.with_egld_value(&self.env, |egld_value| { + self.payment.with_value_ref(&self.env, |egld_value| { SendRawWrapper::::new().upgrade_from_source_contract( &self.to, gas, diff --git a/framework/base/src/types/interaction/tx_payment.rs b/framework/base/src/types/interaction/tx_payment.rs index b8979bf50c..ffbd552a4e 100644 --- a/framework/base/src/types/interaction/tx_payment.rs +++ b/framework/base/src/types/interaction/tx_payment.rs @@ -62,17 +62,6 @@ pub trait TxPaymentEgldOnly: TxPayment + AnnotatedValue(&self, env: &Env, f: F) -> R - where - F: FnOnce(&BigUint) -> R, - { - self.with_value_ref(env, f) - } - - fn into_egld_payment(self, env: &Env) -> BigUint { - self.into_value(env) - } } #[derive(Clone)]